1、DS脚本配置
#!/usr/bin/bash
VIP=172.16.1.100
RS1=172.16.1.5
RS2=172.16.1.6
PORT=80
SCHEDULER=rr
DEV=eth1:1
case $1 in
start)
# 配置虚拟IP地址 VIP
cat >/etc/sysconfig/network-scripts/ifcfg-${DEV} <<-EOF
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
NAME=${DEV}
DEVICE=${DEV}
ONBOOT=yes
IPADDR=${VIP}
PREFIX=24
EOF
# 启动网卡
ifup ${DEV}
# 配置LVS规则
ipvsadm -C
ipvsadm -A -t ${VIP}:${PORT} -s ${SCHEDULER}
ipvsadm -a -t ${VIP}:${PORT} -r ${RS1} -g
ipvsadm -a -t ${VIP}:${PORT} -r ${RS2} -g
;;
stop)
ifdown ${DEV}
rm -f /etc/sysconfig/network-scripts/ifcfg-${DEV}
ipvsadm -C
;;
*)
echo "Usage: sh $0 { start | stop }"
;;
esac
2、RS脚本配置
#!/usr/bin/bash
VIP=172.16.1.100
DEV=lo:0
case $1 in
start)
# ARP抑制
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "1" >/proc/sys/net/ipv4/conf/default/arp_ignore
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "2" >/proc/sys/net/ipv4/conf/default/arp_announce
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
# VIP
cat >/etc/sysconfig/network-scripts/ifcfg-${DEV} <<-EOF
DEVICE=lo:0
IPADDR=${VIP}
NETMASK=255.0.0.0
ONBOOT=yes
NAME=loopback
EOF
ifup ${DEV} # 启动网卡
systemctl start nginx
;;
stop)
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/default/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/default/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
ifdown ${DEV} # 停止网卡
rm -f /etc/sysconfig/network-scripts/ifcfg-${DEV}
systemctl stop nginx
;;
*)
echo "Usage: sh $0 { start | stop }"
esac
标签:arp,shell,LVS,proc,echo,ipv4,conf,net,DR
From: https://blog.51cto.com/u_13236892/6204027