标签:lvs dr
# director端脚本 # cat /etc/init.d/ipvs #!/bin/bash # # LVS service script # chkconfig: - 90 10 . /etc/rc.d/init.d/functions # VIP=172.16.100.100 DIP=172.16.100.10 RIP1=172.16.100.11 RIP2=172.16.100.12 PORT=80 RSWEIGHT1=1 RSWEIGHT2=2 LOCKFILE=/var/lock/subsys/ipvsadm case $1 in start) /sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up /sbin/route add -host $VIP dev eth0:1 echo 1 > /proc/sys/net/ipv4/ip_forward /sbin/iptables -F /sbin/iptables -Z /sbin/ipvsadm -C /sbin/ipvsadm -A -t $VIP:$PORT -s wrr /sbin/ipvsadm -a -t $VIP:$PORT -r $RIP1 -g -w $RSWEIGHT1 /sbin/ipvsadm -a -t $VIP:$PORT -r $RIP2 -g -w $RSWEIGHT2 /bin/touch $LOCKFILE &> /dev/null echo "ipvs is startd ..." ;; stop) if [ ! -e $LOCKFILE ]; then echo " ipvs service is not started." else echo 0 > /proc/sys/net/ipv4/ip_forward /sbin/ipvsadm -C /sbin/ifconfig eth0:0 down /sbin/route del $VIP /bin/rm -f $LOCKFILE echo " ipvs is stopped." fi ;; status) [ -e $LOCKFILE ] && echo " ipvs is running ..." || echo "ipvs is stopped ..." ;; esac # realserver端脚本 [root@node1 ~]# cat /etc/init.d/realserver #!/bin/bash # lvs dr mode realserver script # chkconfig: - 90 10 VIP=172.16.100.100 case $1 in start) /sbin/ifconfig lo down /sbin/ifconfig lo up 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 /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up /sbin/route add -host $VIP dev lo:0 ;; stop) /sbin/ifconfig lo:0 down echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce ;; status) ALIASVIP=`ifconfig lo:0 | grep $VIP` HOSTROUTE=`route -n | grep $VIP` if [ "$ALIASVIP" -o "$HOSTROUTE" ]; then echo " realserver is started .." else echo " realserver is stopped .." fi ;; *) echo "$0: Usage: $0 {start|stop|status}" esac
本文出自 “不懂中医的IT不是好中医” 博客,请务必保留此出处http://zhishen.blog.51cto.com/1612050/1665153
标签:lvs dr
原文地址:http://zhishen.blog.51cto.com/1612050/1665153