LVS DR模式小实验(自定义脚本)

环境

 

 LVS端脚本

#!/bin/bash
###########

VIP="172.168.0.100"
NETMASK=24
IFACE="lo:1"
PORT="80"
RS1="10.0.0.17"
RS2="10.0.0.27"
MODE="wrr"
TYPE="-g"

rpm -q ipvsadm &> /dev/null || yum -y install ipvsadm

case $1 in
start)
  ip a a ${VIP}/${NETMASK} dev lo label ${IFACE}  #broadcast $VIP up
  iptables -F
  ipvsadm -A -t ${VIP}:${PORT} -s ${MODE}
  ipvsadm -a -t ${VIP}:${PORT} -r ${RS1} ${TYPE} -w 1
  ipvsadm -a -t ${VIP}:${PORT} -r ${RS2} ${TYPE} -w 1
  echo "VS 服务准备就绪"
  ;;
stop)
  ipvsadm -C
  ip a d ${VIP}/${NETMASK} dev lo label ${IFACE}  #broadcast $VIP down
  echo "VS 服务设置已清空"
  ;;
*)
  echo "输入start或stop 执行"
  exit 1
  ;;
esac

RS端脚本

#!/bin/bash
###########

VIP="172.168.0.100/24"
GW="10.0.0.28"
IFACE="lo:1"

ip a a ${VIP} dev lo label ${IFACE}

rpm -q httpd &> /dev/null || yum -y install httpd
service httpd start &> /dev/null && echo "http已启动"

case $1 in
start)
echo 1 > /proc/sys/net/ipv4/conf/all/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/lo/arp_announce
ip a a ${VIP} dev lo label ${IFACE}  #broadcast $VIP up
echo "关闭广播,网卡设置别名"
;;
stop)
echo 0 > /proc/sys/net/ipv4/conf/all/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/lo/arp_announce
ip a d ${VIP} dev lo label ${IFACE} #broadcast $VIP down
echo "广播恢复,网卡别名删除"
;;
*)
  echo "输入start或stop 执行"
  exit 1
  ;;
esac

注意查看是否关闭广播相应设置

cat /proc/sys/net/ipv4/conf/all/arp_ignore;cat /proc/sys/net/ipv4/conf/lo/arp_ignore;cat /proc/sys/net/ipv4/conf/all/arp_announce ;cat /proc/sys/net/ipv4/conf/lo/arp_announce

验证

 

posted @ 2020-11-07 17:33  天际之上可有蓝天  阅读(95)  评论(0编辑  收藏  举报