LVS TUN模式搭建

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/ipvsadm -C

/sbin/ifconfig eno16777984:0 down

;;

*)

echo :Usage:$0{start|stop}

exit 1

esac

4、rip1、rip2:

#!/bin/bash

VIP=172.16.54.245

. /etc/rc.d/init.d/functions

case "$1" in

start)

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

;;

stop)

echo "stop LVS TUN"

/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

;;

*)

echo :Usage:$0{start|stop}

exit 1

esac

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

你可能感兴趣的:(LVS TUN模式搭建)