三、Realserver服务器上的配置 (RHEL5)
提供服务的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:AB:B0:02
ONBOOT=yes
IPADDR=192.168.1.191
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
2)编写lvs-dr脚本
[root@localhost ~]# vim /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 //添加脚本lvs-dr的执行权限
[root@localhost ~]# echo "/opt/lvs-dr" >> /etc/rc.local //让脚本lvs-dr随机开机启动
[root@localhost ~]# /opt/lvs-dr //执行lvs-dr脚本
3)挂载光盘,YUM安装apache服务
[root@localhost ~]# mount /dev/cdrom /media/
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*
[root@localhost opt]# echo "1111" > /var/www/html/index.html //在RealServer1添加测试页
[root@localhost opt]# service httpd restart
停止 httpd: [确定]
启动 httpd: [确定]
1)在RealServer2上的设置
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:0C:29:AB:B0:02
ONBOOT=yes
IPADDR=192.168.1.192
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
2)编写lvs-dr脚本,将RealServer1节点上的lvs-dr拷贝到/opt下
[root@localhost ~]# cd /opt/ //节点一上
[root@localhost opt]# scp lvs-dr root@192.168.1.192:/opt/在节点一做,将节点一上/opt/lvs-dr文件拷贝到192的/opt目录下即可,省去下面的在节点二上编辑/opt/lvs-dr //
[root@localhost ~]# vim /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 //添加脚本lvs-dr的执行权限
[root@localhost ~]# echo "/opt/lvs-dr" >> /etc/rc.local //让脚本lvs-dr随机开机启动
[root@localhost ~]# /opt/lvs-dr //执行lvs-dr脚本
3)挂载光盘,YUM安装apache服务
[root@localhost ~]# mount /dev/cdrom /media/
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*
[root@localhost opt]# echo "1111" > /var/www/html/index.html //在RealServer1添加测试页
[root@localhost opt]# service httpd restart
停止 httpd: [确定]
启动 httpd: [确定]
四、测试
1)启动keepalived服务
分别在主、副均衡服务器上启动keepalived服务,启动命令为:
[root@localhost ~]# service keepalived start
启动 keepalived: [确定]