LVS-NAT: address translation
three servers test
192.168.139.161
192.168.139.193
192.168 .139.194
reference http://www.cnblogs.com/MacoLee/p/5856858.html
yum install ipvsadm -y cat /proc/sys/net/ipv4/ip_forward echo 1 > /proc/sys/net/ipv4/ip_forward ipvsadm -A -t 192.168.139.161:80 -s rr [root@LVS ~]# ipvsadm -A -t 192.168.139.161:80 -s rr #Define a cluster service [root@LVS ~]# ipvsadm -a -t 192.168.139.161:80 -r 192.168.139.193 -m #Add RealServer and assign the scheduling algorithm to NAT [root@LVS ~]# ipvsadm -a -t 192.168.139.161:80 -r 192.168.139.194 -m #Add RealServer and assign the scheduling algorithm to NAT [root@LVS ~]# ipvsadm -L -n #View the list of rules defined by ipvs
Wrong test several times, found that the average switch between 193 and 194
curl http://192.168.139.161/index.html
to modify the weight
ipvsadm -E -t 192.168.139.161:80 -s wrr ipvsadm -e -t 192.168.139.161:80 -r 192.168.139.193 -m -w 3 ipvsadm -e -t 192.168.139.161:80 -r 192.168.139.194 -m -w 1
I tested it several times and found that the ratio of switching 193 and 194 is 3:1
curl http://192.168.139.161/index.html
to save it permanently #The
first method:
# service ipvsadm save
ipvsadm: Saving IPVS table to /etc/sysconfig /ipvsadm: [OK] #Second
method:
ipvsadm -S > /etc/sysconfig/ipvsadm.s1
Empty:
ipvsadm -C
restore
ipvsadm -R < /etc/sysconfig/ipvsadm.s1
######## #########LVS-DR: Direct Routing
http://blog.csdn.net/gzh0222/article/details/8566516
################# ###On realserver
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 #The above commands need to be added to the /etc/rc.local file to make it take effect automatically # vim /etc/sysconfig/network-scripts/ifcfg-lo:0 The content is as follows DEVICE=lo:0 IPADDR=10.3.3.100 NETMASK=255.255.255.255 BROADCAST=10.3.3.100 ONBOOT=yes NAME=loopback ifdown lo:0 ifup lo:0 route add -host 10.3.3.100 dev lo:0 echo "route add -host 10.3.3.100 dev lo:0" >> /etc/rc.local
###################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
_
_ #######
# vim /etc/sysconfig/network-scripts/ifcfg-eth2:0 The content is as follows
DEVICE=eth2:0 IPADDR=10.3.3.100 NETMASK=255.255.255.255 BROADCAST=10.3.3.100 ONBOOT=yes #Order ifdown eth2:0 ifup eth2:0 route add -host 10.3.3.100 dev eth2:0 echo "route add -host 10.3.3.100 dev eth2:0" >> /etc/rc.local echo "1" > /proc/sys/net/ipv4/ip_forward echo "echo 1 > /proc/sys/net/ipv4/ip_forward" >> /etc/rc.local ipvsadm -A -t 10.3.3.100:80 -s wlc ipvsadm -a -t 10.3.3.100:80 -r 10.3.3.3 -g -w 2 ipvsadm -a -t 10.3.3.100:80 -r 10.3.3.4 -g -w 1
###################
Access curl from outside http://10.3.3.100 Test
tcpdump -i eth2 -e -l -s 0 -w 194.pcp
and then use wireshark Look at the network card traffic on each machine
############tun mode
health check
##check-lvs-health.sh
#!/bin/bash # VIP=172.16.100.100 CPORT=80 FAIL_BACK=127.0.0.1 RS=("10.3.3.3" "10.3.3.4") declare -a RSSTATUS RW=("2" "1") RPORT=80 TYPE=g CHCLOOP=3 LOG = / var / log / ipvsmonitor.log addrs() { ipvsadm -a -t $VIP:$CPORT -r $1:$RPORT -$TYPE -w $2 [ $? -eq 0 ] && return 0 || return 1 } delrs() { ipvsadm -d -t $ VIP: $ CPORT -r $ 1: $ RPORT [ $? -eq 0 ] && return 0 || return 1 } checkrs() { local I=1 while [ $I -le $CHKLOOP ]; do if curl --connect-timeout 1 http://$1 &> /dev/null; then return 0 be let I++ done return 1 } fixed() { local I local COUNT=0; for I in ${RS[*]}; do if ipvsadm -L -n | grep "$I:$RPORT" && > /dev/null ; then RSSTATUS[$COUNT]=1 else RSSTATUS[$COUNT]=0 A++ Dir [0] = $ A be let COUNT++ done } initstatus while :; do let COUNT=0 for I in ${RS[*]}; do if checkrs $I; then if [ ${RSSTATUS[$COUNT]} -eq 0 ]; then addrs $I ${RW[$COUNT]} [ $? -eq 0 ] && RSSTATUS[$COUNT]=1 && echo "`date +'%F %H:%M:%S'`, $I is back." >> $LOG be else if [ ${RSSTATUS[$COUNT]} -eq 1 ]; then delrs $I [ $? -eq 0 ] && RSSTATUS[$COUNT]=0 && echo "`date +'%F %H:%M:%S'`, $I is gone." >> $LOG be be let COUNT++ done sleep 5 done
######