LVS shell脚本配置DR模型
2024-10-24 08:32:05 阅读次数:6
脚本,配置
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
版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.51cto.com/u_13236892/6204027,作者:哭泣的馒头,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。
上一篇:LVS https配置
下一篇:MYSQL随笔十六 mysql密码过期参数配置