Piranha-LVS配置全攻略
1.LVS配置
serial_no = 106primary = 10.109.195.11service = lvsbackup_active = 1backup = 10.109.195.12heartbeat = 1heartbeat_port = 539keepalive = 6deadtime = 18network = directdebug_level = NONEmonitor_links = 1syncdaemon = 1virtual CBD-SkypApp-SVC { active = 1 address = 10.109.192.10 eth2:1 vip_nmask = 255.255.255.255 port = 7788 expect = "OK" use_regex = 0 send_program = "/etc/sysconfig/ha/weblogic_7788_lvs.sh %h" load_monitor = none scheduler = rr protocol = tcp timeout = 6 reentry = 15 quiesce_server = 0 server node1 { address = 10.109.192.6 active = 1 weight = 1 } server node2 { address = 10.109.192.7 active = 1 weight = 1 }}virtual CBD-SkypApp-WS { active = 1 address = 10.109.192.10 eth2:1 vip_nmask = 255.255.255.255 port = 5566 expect = "OK" use_regex = 0 send_program = "/etc/sysconfig/ha/jboss_5566_lvs.sh %h" load_monitor = none scheduler = rr protocol = tcp timeout = 6 reentry = 15 quiesce_server = 0 server node1 { address = 10.109.192.6 active = 1 weight = 1 } server node2 { address = 10.109.192.7 active = 1 weight = 1 }}virtual private-ejb { active = 1 address = 10.109.195.10 eth1:1 vip_nmask = 255.255.255.255 port = 7788 expect = "OK" use_regex = 0 send_program = "/etc/sysconfig/ha/jboss_lvs.sh %h" load_monitor = none scheduler = wlc protocol = tcp timeout = 6 reentry = 15 quiesce_server = 0 server node1 { address = 10.109.195.6 active = 0 weight = 1 } server node2 { address = 10.109.195.8 active = 1 weight = 1 } server node3 { address = 10.109.195.9 active = 1 weight = 1 }}virtual CBD-App-All { active = 1 address = 10.109.195.10 eth1:1 vip_nmask = 255.255.255.255 port = 80 expect = "OK" use_regex = 0 send_program = "/etc/sysconfig/ha/jboss_lvs.sh %h" load_monitor = none scheduler = rr protocol = tcp timeout = 6 reentry = 15 quiesce_server = 0 server node1 { address = 10.109.195.8 active = 1 weight = 1 } server node2 { address = 10.109.195.9 active = 1 weight = 1 } server node3 { address = 10.109.195.6 active = 0 weight = 1 }}
#!/bin/sh# We use $1 as the argument in the TEST which will be the various IP's# of the real servers in the cluster.# Check for hack/defacementsTEST=`links -dump http://$1:80/console/ | grep JBoss | wc -l`if [ $TEST -ge "1" ]; then echo "OK"else echo "FAIL"fi
# Broadcom Corporation NetXtreme II BCM5716 Gigabit EthernetDEVICE=eth1BOOTPROTO=noneHWADDR=00:24:e8:7b:42:f0ONBOOT=yesDHCP_HOSTNAME=CBD-Lvs1IPADDR=10.109.195.11NETMASK=255.255.255.0GATEWAY=10.109.195.1TYPE=EthernetUSERCTL=noIPV6INIT=noPEERDNS=yes
# Generated by iptables-save v1.3.5 on Thu Apr 15 19:17:18 2010*nat:PREROUTING ACCEPT [681320:44756889]:POSTROUTING ACCEPT [764304:51209039]:OUTPUT ACCEPT [764277:51207419]-A PREROUTING -d 10.109.192.10 -p tcp -m tcp --dport 7788 -j REDIRECT -A PREROUTING -d 10.109.192.10 -p tcp -m tcp --dport 5566 -j REDIRECT -A OUTPUT -d 10.109.192.10 -p tcp -m tcp --dport 7788 -j DNAT --to-destination 10.109.192.6:7788 -A OUTPUT -d 10.109.192.10 -p tcp -m tcp --dport 5566 -j DNAT --to-destination 10.109.192.6:5566COMMIT# Completed on Thu Apr 15 19:17:18 2010
在控制台中输入命令:1)开启防火墙:【service iptables start】,【chkconfig iptables on】2)清空路由规则:【iptables -F】3)在控制台中输入命令:【iptables -A OUTPUT -d {VIP} -p tcp -m tcp --dport {VPORT} -j DNAT --to-destination {RIP:RPORT}】,其中{VIP}、{VPORT}为虚拟IP和端口, {RIP:RPORT}为真实服务的IP和端口4)保存路由配置:【service iptables save】
1)从“控制面板”中选择“添加硬件”,选中“是,硬件已连接好”,如果是Window7或Window2008则需要打开设备管理器,然后“添加过时硬件”。2)下一步,选中“添加新的硬件设备”3)下一步,选中“安装我手动从列表选择的硬件”4)下一步,选中“网络适配器”5)下一步,从microsoft中选择loopback适配器6)下一步,直至完成最后在网络邻居的网络连接中对刚建立的loopback适配器进行配置7)在real server上为虚拟网卡设置IP为LVS的VIP,子网掩码为:255.255.255.0(或255.255.255.255)。其他不需要设置。8)禁用网卡后重新启用即可。
把下面命令保存到一个BAT脚本中,按右键以管理员权限执行。其中“本地连接 3”是物理网卡的名称,“loopback”是虚拟网卡的名称。【netsh interface ipv4 set interface "loopback" weakhostreceive=enablednetsh interface ipv4 set interface "loopback" weakhostsend=enablednetsh interface ipv4 set interface "本地连接 3" weakhostreceive=enabledpause】