1、伺服器要有載入TUN子產品才行
2、加載子產品: modprobe tun
3、負載均衡:/etc/init.d/ipvsnat
#!/bin/bash
VIP=172.16.54.245
RIP1=172.16.54.231
RIP2=172.16.54.232
./etc/rc.d/init.d/functions
case "$1" in
start)
echo "start LVS TUN"
/sbin/ifconfig tun0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev tun0
echo "1" > /proc/sys/net/ipv4/ip_forward
/sbin/ipvsadm -C
/sbin/ipvsadm -A -t $VIP:80 -s rr
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -i
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -i
/sbin/ipvsadm
;;
stop)
echo "stop LVS TUN"
echo "0" > /proc/sys/net/ipv4/ip_forward
/sbin/ifconfig eno16777984:0 down
*)
echo :Usage:$0{start|stop}
exit 1
esac
4、rip1、rip2:
. /etc/rc.d/init.d/functions
echo "start LVS TUNL"
/sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev tunl0
echo "1" > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/tunl0/arp_announce
echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/tunl0/rp_filter
sysctl -p
/sbin/ifconfig tunl0 down
echo "0" > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo "0" > /proc/sys/net/ipv4/conf/tunl0/arp_announce
echo "0" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" > /proc/sys/net/ipv4/conf/all/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/tunl0/rp_filter
5、rip1\rip2:yum install -y httpd && service httpd start
echo "YourIp">/var/www/html/index.html
6、for i in `seq 1 10`;do curl ....;done