测试环境:
OS:rhel6
Director1:192.168.1.121 heartbeat heartbeat-ldirectord ipvsadm VIP hb_gui
Director2:192.168.1.122 heartbeat heartbeat-ldirectord ipvsadm VIP
RS1:192.168.1.111 httpd VIP
RS2:192.168.1.112 httpd VIP
VIP:192.168.1.160
LVS实现DR模型
PS:注意这里的测试过程是在上两篇博文的基础上操作的。。。go on !!
一,首先在Director1上停止自己和Director2的heartbeat服务和安装ipvsadm
#service heartbeat stop
#ssh Director2.luochen.com 'service heartbeat stop'
#yum -y install ipvsadm
#ssh Director2.luochen.com 'yum -y install ipvsadm'
二,在RS1上设定内核参数
#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
#echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
#echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce
#echo 1 > /proc/sys/net/ipv4/conf/all/arp_announce
配置VIP
#ifconfig lo:0 192.168.1.160 netmask 255.255.255.255 broadcast 192.168.1.160 up
#route add -host 192.168.1.160 dev lo:0
查看VIP是否添加成功
#ifconfig
#route -n
提供httpd服务的测试页面
#vim /var/www/html/index.html
<h1>RS1</h1>
#service httpd start
在本地测试看httpd是否启动正常
#curl http://192.168.1.111
#curl http://192.168.1.160
三,在RS2上设定内核参数
#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
#echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
#echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce
#echo 1 > /proc/sys/net/ipv4/conf/all/arp_announce
配置VIP
#ifconfig lo:0 192.168.1.160 netmask 255.255.255.255 broadcast 192.168.1.160 up
#route add -host 192.168.1.160 dev lo:0
查看VIP是否添加成功
#ifconfig
#route -n
提供httpd服务的测试页面
#vim /var/www/html/index.html
<h1>RS2</h1>
#service httpd start
在本地测试看httpd是否启动正常
#curl http://192.168.1.112
#curl http://192.168.1.160
四,在前端任意一台Director主机ping Rip 和 Vip
#ping 192.168.1.111 响应 Rip1
#ping 192.168.1.112 响应 Rip2
#ping 192.168.1.160 不响应Vip
五,在D1上定义ipvs集群测试
#chkconfig ipvsadm off
#ifconfig eth0:0 192.168.1.160/24 up
#route add -host 192.168.1.160 dev eth0:0
定义ipvs规则
#ipvsadm -A -t 192.168.1.160:80 -s rr
#ipvsadm -a -t 192.168.1.160:80 -r 192.168.1.111 -g
#ipvsadm -a -t 192.168.1.160:80 -r 192.168.1.112 -g
#ipvsadm -L -n
#service ipvsadm save
#service ipvsadm stop
#ifconfig eth0:0 down
#scp /etc/sysconfig/ipvsadm Director2.luochen.com:/etc/sysconfig/
六,在宿主机上访问vip测试
七,在D2上定义ipvs集群测试
#chkconfig ipvsadm off
#ifconfig eth0:0 192.168.1.160/24 up
#route add -host 192.168.1.160 dev eth0:0
#ipvsadm -R < /etc/sysconfig/ipvsadm
#ipvsadm -L -n
#service ipvsadm restart
八,在宿主机上访问vip测试
九,在安装配置heartbeat-ldirector之前需要停止ipvsadm服务,关闭eth0:0,删除路由条目,删除ipvs规则
#service ipvsadm stop
#ipvsadm -L -n (停止ipvsadm服务会清空所有的ipvs规则)
#ifconfig eth0:0 down
#ifconfig
#route del -host 172.16.100.36
#route -n
#rm -rf /etc/sysconfig/ipvsadm
十,在Director1上关闭自己和Director的heartbeat服务
#service heartbeat stop
#ssh Director2.luochen.com 'service heartbeat stop'
十一,在Director1和Director2上安装heartbeat-ldirectord
#yum install heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm
#rpm -ql heartbeat-lidirectord
#chkconfig ldirectord off
十二,在Director1上提供ldirectord的配置文件
#cp /usr/share/doc/heartbeat-ldirectord-2.1.4/ldirectord.cf /etc/ha.d/
#vim /etc/ha.d/ldirectord.cf (ldirectord会自动配置ipvs规则,ipvsadm服务不会启动)
virtual=192.168.1.160:80 (定义一个虚拟服务的 vip:80)
real=192.168.1.111:80 gate
real=192.168.1.112:80 gate (前面tab缩进是必须的)
failback=127.0.0.1:80 gate (备用本地web服务器,后端所有RS down了,启用)
service=hhtp (基于那种协议做健康状态检测的)
request=".health.html" (健康状态检测的页面)
receive="OK" (搜索关键字)
scheduler=rr (调度算法)
#scp ldirectord.cf Director2.luochen.com:/etc/ha.d/
#service ldirectord stop
#ssh Director2.luochen.com 'service ldirectord stop'
#service heartbeat start
#ssh Director2.luochen.com 'service heartbeat start'
十三,在RS1和RS2上提供健康状态检测文件
#vim /var/www/html/.health.html
ok
十四,在Director1上执行hb_gui 配置Director的高可用服务
#hb_gui &
定义资源组
添加VIP
添加ldirectord服务
资源组添加完毕
最后就是测试了,在运行服务的Director节点上查看VIP是否配置成功和ipvs规则是否添加成功
#ip addr show
#ipvsadm -L -n