LVS+Heartbeat+ldirectord构建高可用负载均衡群集(D(3)

三、Realserver服务器上的配置

提供服务的RealServer1和RealServer2不需要安装任何IPVS软件,只需要设置在开机后自动执行以下脚本:

1)在RealServer1上的设置

 [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

DEVICE=eth0

BOOTPROTO=static

HWADDR=00:0C:29:26:16:64

ONBOOT=yes

IPADDR=192.168.1.191

NETMASK=255.255.255.0

GATEWAY=192.168.1.1

编写lvs-dr脚本

[root@localhost ~]# vi /opt/lvs-dr

#!/bin/bash

vip="192.168.1.198"

/sbin/ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up

/sbin/route add -host $vip dev lo:0

echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore

echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce

echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore

echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce

[root@localhost ~]# chmod +x /opt/lvs-dr //给予执行权限

[root@localhost ~]# echo "/opt/lvs-dr" >>/etc/rc.local //让脚本lvs-dr随机开机启动

[root@localhost ~]# /opt/lvs-dr //执行lvs-dr脚本

[root@localhost ~]# mount /dev/cdrom /media/ //挂载光盘,安装YUM

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@localhost ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo

[rhel-debuginfo]

name=Red Hat Enterprise Linux $releasever - $basearch - Debug

baseurl=file:///media/Server

enabled=1

gpgcheck=0

[root@localhost ~]# yum -y install http* //安装apache

[root@localhost ~]# echo "111" > /var/www/html/index.html //在RealServer1添加测试页

[root@localhost ~]# service httpd restart //重启web服务器

2)在RealServer1上的设置

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

DEVICE=eth0

BOOTPROTO=static

HWADDR=00:0C:29:E8:EE:83

ONBOOT=yes

IPADDR=192.168.1.192

NETMASK=255.255.255.0

GATEWAY=192.168.1.1

编写lvs-dr脚本

[root@localhost ~]# vi /opt/lvs-dr

#!/bin/bash

vip="192.168.1.198"

/sbin/ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up

/sbin/route add -host $vip dev lo:0

echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore

echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce

echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore

echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce

[root@localhost ~]# chmod +x /opt/lvs-dr //给予执行权限

[root@localhost ~]# echo "/opt/lvs-dr" >>/etc/rc.local //让脚本lvs-dr随机开机启动

[root@localhost ~]# /opt/lvs-dr //执行lvs-dr脚本

[root@localhost ~]# mount /dev/cdrom /media/ //挂载光盘,安装YUM

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@localhost ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo

[rhel-debuginfo]

name=Red Hat Enterprise Linux $releasever - $basearch - Debug

baseurl=file:///media/Server

enabled=1

gpgcheck=0

[root@localhost ~]# yum -y install http* //安装apache

[root@localhost ~]# echo "111" > /var/www/html/index.html //在RealServer1添加测试页

[root@localhost ~]# service httpd restart //重启web服务器

四、测试

1)启动heartbeat服务

分别在主、副均衡服务器上启动heartbeat服务,启动命令为:

[root@LVS-Slave ~]# service heartbeat start

2)确定realserver1和realserver2服务器的httpd服务启动,页面能正常访问

3)在两台客户机上分别打开浏览器,输入,将分别看到不同的页面

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/b6aef09f8b84a4f609027492d2123aed.html