Piranha-LVS配置全攻略

1.LVS配置
serial_no = 106
primary = 10.109.195.11
service = lvs
backup_active = 1
backup = 10.109.195.12
heartbeat = 1
heartbeat_port = 539
keepalive = 6
deadtime = 18
network = direct
debug_level = NONE
monitor_links = 1
syncdaemon = 1
virtual 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
     }
}

2.LVS脚本
#!/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/defacements
TEST=`links -dump http://$1:80/console/ | grep JBoss | wc -l`

if [ $TEST -ge "1" ]; then
        echo "OK"
else
        echo "FAIL"
fi

3.LVS的IP配置
# Broadcom Corporation NetXtreme II BCM5716 Gigabit Ethernet
DEVICE=eth1
BOOTPROTO=none
HWADDR=00:24:e8:7b:42:f0
ONBOOT=yes
DHCP_HOSTNAME=CBD-Lvs1
IPADDR=10.109.195.11
NETMASK=255.255.255.0
GATEWAY=10.109.195.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes

4.LVS的Iptables配置
# 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:5566
COMMIT
# Completed on Thu Apr 15 19:17:18 2010

5.Real Server配置(Linux)
在控制台中输入命令:
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】

6.Real Server配置(Windows)
应用服务器安装loopback网卡
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)禁用网卡后重新启用即可。

应用服务器为windows 2008时需要该配置
把下面命令保存到一个BAT脚本中,按右键以管理员权限执行。其中“本地连接 3”是物理网卡的名称,“loopback”是虚拟网卡的名称。
【netsh interface ipv4 set interface "loopback" weakhostreceive=enabled
netsh interface ipv4 set interface "loopback" weakhostsend=enabled
netsh interface ipv4 set interface "本地连接 3" weakhostreceive=enabled
pause】
http://www.linuxso.com/architecture/13814.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值