码迷,mamicode.com
首页 > 其他好文 > 详细

LVS setup + keepalived

时间:2018-05-04 15:22:26      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:enc   ipvs   top   ali   sync   pvs   rect   group   rip   

Server

#!/bin/bash

VIP=10.132.2.254
RIP1=10.132.2.17
RIP2=10.132.2.18

#./etc/rc.d/init.d/functions
case "$1" in
start )
echo "start LVS of Director Server"
/sbin/ifconfig bond4:0 $VIP broadcast $VIP netmask 255.255.255.255 up
echo 1 > /proc/sys/net/ipv4/ip_forward
/sbin/ipvsadm -C
#set LVS
/sbin/ipvsadm -A -t $VIP:80 -s rr
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g
/sbin/ipvsadm -ln
;;
stop)
echo "close LVS Director Server"
echo 0 >/proc/sys/net/ipv4/ip_forward
/sbin/ipvsadm -C
/sbin/ifconfig bond4:0 down
;;
*)
echo "Usage:$0{start|stop}"
exit 1
esac

 

RS:

#!/bin/bash

VIP=10.132.2.254
RIP1=10.132.2.17
RIP2=10.132.2.18

#./etc/rc.d/init.d/functions
case "$1" in
start )
echo "set RS "

VIP=10.132.2.254
/sbin/ifconfig lo:0 $VIP broadcast $VIP 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

;;
stop)

/sbin/ifdown lo:0 
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
sysctl -p

;;
*)
echo "Usage:$0{start|stop}"
exit 1
esac

 

! Configuration File for keepalived

global_defs {
router_id lvs
}

vrrp_sync_group http {
group {
apache
}
}

vrrp_instance apache {
state MASTER
interface bond4
virtual_router_id 51
priority 200
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.132.2.254
}
}

virtual_server 10.132.2.254 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
# persistence_timeout 50
protocol TCP

real_server 10.132.2.17 80 {
weight 1
TCP_CHECK {
connect_timeout 3
connect_port 80
}
}
real_server 10.132.2.18 80 {
weight 1
TCP_CHECK {
connect_timeout 3
connect_port 80
}
}
}

 

LVS setup + keepalived

标签:enc   ipvs   top   ali   sync   pvs   rect   group   rip   

原文地址:https://www.cnblogs.com/zcx-python/p/8990458.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!