heartbeat与lvs和realserver的结合
拓扑图:
主要依赖heartbeat-ldirectord-2.1.4-9.el5.i386.rpm这个软件包,注意:安装这个软件包就不需要开启ipvsadm服务,当启动heartbeat服务后自动启用ipvsadm服务。 当然ipvsadm服务也要安装。 需要下载的rpm包有: heartbeat-2.1.4-9.el5.i386.rpm heartbeat-ldirectord-2.1.4-9.el5.i386.rpm heartbeat-pils-2.1.4-10.el5.i386.rpm heartbeat-stonith-2.1.4-10.el5.i386.rpm libnet-1.1.4-3.el5.i386.rpm perl-MailTools-1.77-1.el5.noarch.rpm 附件内有 下边是配置情况:
流量分发服务器DIRECTOR1的配置 接口配置 eth0 192.168.2.10 eth1 192.168.10.1
使用yum时,别忘了挂在光盘...
执行脚本heart.sh #!/bin/bash cd heartbeat/ yum localinstall -y heartbeat* lib* perl* --nogpgcheck echo "192.168.2.10 node1.abc.com node1" >>/etc/hosts echo "192.168.2.15 node2.abc.com node2" >>/etc/hosts echo "192.168.10.1 node1.abc.com node1" >>/etc/hosts echo "192.168.10.2 node2.abc.com node2" >>/etc/hosts sed -i "s/^HOSTNAME.*$/HOSTNAME=node1.abc.com/" /etc/sysconfig/network hostname node1.abc.com cp /usr/share/doc/heartbeat-2.1.4/ha.cf /etc/ha.d/ cp /usr/share/doc/heartbeat-2.1.4/authkeys /etc/ha.d/ cp /usr/share/doc/heartbeat-2.1.4/haresources /etc/ha.d/ cp /usr/share/doc/heartbeat-ldirectord-2.1.4/ldirectord.cf /etc/ha.d/ cd /etc/ha.d/ echo "bcast eth1" >> ha.cf echo "node node1.abc.com" >> ha.cf echo "node node2.abc.com" >> ha.cf echo "node1.abc.com 192.168.2.100 ldirectord::ldirectord.cf">>haresources echo "auth 1">>authkeys echo "1 md5 d41d8cd98f00b204e9800998ecf8427e" >>authkeys chmod 600 authkeys 脚本到此结束
md5的产生方法 [root@node1 ~]# dd=/dev/urandom bs=512 count=1 |openssl md5 d41d8cd98f00b204e9800998ecf8427e 然后编辑vim ldirectord.cf virtual=192.168.2.100:80 real=192.168.2.20:80 gate real=192.168.2.30:80 gate #fallback=127.0.0.1:80 gate service=http request=".test.html" receive="ok" # virtualhost=some.domain.com.au scheduler=rr #persistent=600 #netmask=255.255.255.255 protocol=tcp checktype=negotiate checkport=80 request="index.html" receive="Test Page" virtualhost=www.x.y.z
安装完ipvsadm服务后不要启动该服务. service heartbeat restart
DIRECTOR2流量分发服务器的配置 接口配置 eth0 192.168.2.15 eth1 192.168.10.2
执行脚本heart.sh #!/bin/bash cd heartbeat/ yum localinstall -y heartbeat* lib* perl* --nogpgcheck echo "192.168.2.10 node1.abc.com node1" >>/etc/hosts echo "192.168.2.15 node2.abc.com node2" >>/etc/hosts echo "192.168.10.1 node1.abc.com node1" >>/etc/hosts echo "192.168.10.2 node2.abc.com node2" >>/etc/hosts sed -i "s/^HOSTNAME.*$/HOSTNAME=node1.abc.com/" /etc/sysconfig/network hostname node2.abc.com cp /usr/share/doc/heartbeat-2.1.4/ha.cf /etc/ha.d/ cp /usr/share/doc/heartbeat-2.1.4/authkeys /etc/ha.d/ cp /usr/share/doc/heartbeat-2.1.4/haresources /etc/ha.d/ cp /usr/share/doc/heartbeat-ldirectord-2.1.4/ldirectord.cf /etc/ha.d/ cd /etc/ha.d/ echo "bcast eth1" >> ha.cf echo "node node1.abc.com" >> ha.cf echo "node node2.abc.com" >> ha.cf echo "node1.abc.com 192.168.2.100 ldirectord::ldirectord.cf">>haresources //指定node1.abc.com作为主流量分发器。 echo "auth 1">>authkeys echo "1 md5 d41d8cd98f00b204e9800998ecf8427e" >>authkeys chmod 600 authkeys 然后编辑vim ldirectord.cf virtual=192.168.2.100:80 real=192.168.2.20:80 gate real=192.168.2.30:80 gate #fallback=127.0.0.1:80 gate service=http request=".test.html" receive="ok" # virtualhost=some.domain.com.au scheduler=rr #persistent=600 #netmask=255.255.255.255 protocol=tcp checktype=negotiate checkport=80 request="index.html" receive="Test Page" virtualhost=www.x.y.z
安装完ipvsadm软件包后不要启动该服务. service heartbeat restart
做完这些后我们可以查看node1上的ip地址 可以看到虚拟地址已经出现在eth0:0子接口上为2.100 还可以查看ipvsadm –L,有调度算法 但是node2上什么也没有,只是作为一个备份设备。 cd /usr/lib/heartbeat/ ./hb_standby //模拟心跳线down掉 hb_takeover //模拟心跳线恢复
执行脚本./hb_standby 当主流量分发器node1通过模拟standby时,通过察看日志可以发现 tail -f /var/log/message 可以很清楚的看到node1已经处于standby状态,node2处于开放状态 通过查看node2的接口地址,出现了虚地址所在的eth0:0上的地址 通过ipvsadm –L可以看出node2上开启了ipvsadm服务
在所有的real server上边配置: Ifconfig lo:0 192.168.2.100 netmask 255.255.255.255 route add -host 192.168.2.100 dev lo:0 //配置一条路由强制返回时通过lo:0 vim /etc/sysctl.conf 添加下边的两行,其实只需要all就可以了。all包含所有接口 net.ipv4.conf.all.arp_announce = 2 net.ipv4.conf.lo.arp_announce = 2 net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.lo.arp_ignore = 1
web1 eth0 192.168.2.20 在/var/www/html/下创建一个.test.htm的页面,随便写点。 Touch .test.htm //内容只写一个ok就可以了。 service httpd restart
web2 eth0 192.168.2.30 在/var/www/html/下创建一个.test.htm的页面,随便写点。 Touch .test.htm //内容只写一个ok就可以了。
service httpd restart