主機 | 用途 | 安裝軟件 |
10.10.10.100,192.168.1.100 | master+res1,10.10.10.100兼作VIP | ipvsadm+lvs腳本 |
10.10.10.101,192.168.1.101 | res2 | res腳本 |
10.10.10.102,192.168.1.102 | res3 | res腳本 |
sysctl -p /etc/sysctl.confweb
#!/bin/bash #description: sh lvs-dr.sh #set lvs #Written by bg VIP=10.10.10.100 /sbin/ipvsadm -C /sbin/ipvsadm -A -t $VIP:80 -s rr /sbin/ipvsadm -a -t $VIP:80 -r 192.168.1.100:80 -g -w 1 /sbin/ipvsadm -a -t $VIP:80 -r 192.168.1.101:80 -g -w 1 /sbin/ipvsadm -a -t $VIP:80 -r 192.168.1.102:80 -g -w 1 /etc/init.d/ipvsadm save
res腳本: lvs-web.shbash
#!/bin/bash #Description : sh lvs-web.sh #Write by bg VIP=10.10.10.100 /sbin/ifconfig lo:0 $VIP broadcast 10.10.10.255 netmask 255.255.255.255 up /sbin/route add -host $VIP dev lo:0 echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce sysctl -p