关注于系统高可用、网站架构
分类:
2010-09-05 19:17:09
[root@LVS-S src]# vi /etc/sysconfig/ha/lvs.cf service = lvs primary = 192.168.1.190 primary_private = 172.16.0.190 //lvs 主服务器心跳地址 backup_active = 1 backup = 192.168.1.1.191 //lvs 备服务器心跳地址 backup_private = 172.16.0.191 heartbeat = 1 heartbeat_port = 539 keepalive = 4 deadtime = 12 debug_level = NONE rsh_command = ssh network = direct #Tcp port 80 for portal virtual portal1v1 { active = 1 address = 192.168.1.100 eth0:1 vip_nmask = 255.255.255.0 port = 80 persistent = 1800 pmask = 255.255.255.255 send = "GET /iwl/.lvs.html\n" expect = "OK" load_monitor = none scheduler = wlc protocol = tcp timeout = 5 reentry = 10 quiesce_server = 0 server potral1 { address = 192.168.1.10 active = 1 weight = 100 } server potral2 { address = 192.168.1.11 active = 1 weight = 100 } server potral3 { address = 192.168.1.12 active = 1 weight = 100 } } virtual portal1v2 { active = 1 address = 192.168.2.100 eth1:1 vip_nmask = 255.255.255.0 port = 80 persistent = 1800 pmask = 255.255.255.255 send = "GET /iwl/.lvs.html\n" expect = "OK" load_monitor = none scheduler = wlc protocol = tcp timeout = 5 reentry = 10 quiesce_server = 0 server potral1 { address = 192.168.2.10 active = 1 weight = 100 } server potral2 { address = 192.168.2.11 active = 1 weight = 100 } server potral3 { address = 192.168.2.12 active = 1 weight = 100 } } virtual portal1v3 { active = 1 address = 192.168.3.100 eth2:1 vip_nmask = 255.255.255.0 port = 80 persistent = 1800 pmask = 255.255.255.255 send = "GET /iwl/.lvs.html\n" expect = "OK" load_monitor = none scheduler = wlc protocol = tcp timeout = 5 reentry = 10 quiesce_server = 0 server potral1 { address = 192.168.3.10 active = 1 weight = 100 } server potral2 { address = 192.168.3.11 active = 1 weight = 100 } server potral3 { address = 192.168.3.12 active = 1 weight = 100 } } :wq! //按”Esc”键输入”:wq!”保存退出 |
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
最后保存sysctl –p
root@portal1 ~]# vi /etc/rc.local
#!/bin/sh
……
………..
ifconfig lo:0 192.168.1.100 broadcast 192.168.1.100 netmask 255.255.255.255 up //增加此行
ifconfig lo:1 192.168.2.100 broadcast 192.168.2.100 netmask 255.255.255.255 up //增加此行
ifconfig lo:2 192.168.3.100 broadcast 192.168.3.100 netmask 255.255.255.255 up //增加此行
:wq! //按”Esc”键输入”:wq!”保存退出
[root@portal1 ~]# sh ./etc/rc.d/rc.local //执行rc.local脚本,使回环地址生效,注意如果重启网络回环地址会消失,因此需要重新执行此脚本,切记.
root@portal1 iwl.war]# vi /infowarelab/apache2/conf/uriworkermap.properties
# uriworkermap.properties
….
……..
/iwl/.lvs.html=jboss //添加此行
cp -r /infowarelab/jboss/server/default/deploy/jboss-web.deployer/ROOT.war /infowarelab/jboss/server/default/deploy/iwl.war
[root@portal1 ~]#cd /infowarelab/jboss/server/default/deploy/iwl.war/
[root@portal1 iwl.war]#cat > .lvs.html <
OK
EOF //回车,重启apache和jboss进程
[root@portal1 ~]# GET
OK //返回”OK”值说明配置成功
经验分享
1、机房无法实时刷新MAC,LVS+Heartbeat方案无法正常随机切换IP
假如两台VS之间使用的互备关系,那么当一台VS接管LVS服务时,可能会网络不通,这时因为路由器的MAC缓存表里无法及时刷新MAC.关于vip这个地址的MAC地址还是替换的VS的MAC,有两种解决方法,一种是修改新VS的MAC地址,另一种是使用send_arp /arping命令.
【注】最好让机房调整路由MAC缓存表的刷新频率;
以arping命令为例.
/sbin/arping -I eth0 -c 3 -s ${vip}${gateway_ip} > /dev/null 2>&1
Eg:
/sbin/arping -I eth0 -c 3 -s 192.168.1.6192.168.1.1