LVS成功安装之后,可以命令行模式命令实现,也可以自定义脚本执行,方便快捷,可扩展性较好;DR主机也可以使用脚本执行vip的绑定和arp的抑制;
DR自动启动ipvs的脚本:
VIP如有多个的话可以定义数组,RIP定义为数组,如有多个添加即可;
[root@localhost ~]# cat ipvs.sh
#!/bin/bash
#written by linuxidc@2015-11-17
#simple ipvs start/stop scripts
. /etc/init.d/functions
VIP=192.168.20.100
RIP=(
192.168.20.10
192.168.20.11
)
PORT=80
IPVSADM=/sbin/ipvsadm
IFCONFIG=/sbin/ifconfig
function ipvs_start(){
$IFCONFIG eth0:0 $VIP/24 up
$IPVSADM -C
$IPVSADM --set 30 5 60
$IPVSADM -A -t $VIP:$PORT -s rr -p 20
for((i=0;i<${#RIP[*]};i++))
do
$IPVSADM -a -t $VIP:$PORT -r ${RIP[$i]} -g -w 1
done
}
function ipvs_stop(){
$IFCONFIG eth0:0 down
$IPVSADM -C
}
case "$1" in
start)
ipvs_start
action "ipvs is started" /bin/true
;;
stop)
ipvs_stop
action "ipvs is stopped" /bin/true
;;
*)
printf "USAGE:$0 {start|stop} \n"
esac
RS启动ipvs脚本:
[root@localhost ~]# cat lvs_rs.sh
#!/bin/bash
#written by linuxidc@2015-11-17
VIP=192.168.20.100
IFCONFIG=/sbin/ifconfig
$IFCONFIG lo:0 $VIP/32 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
CentOS 7.0下安装部署LVS