You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
shell-project/os/lvs/lvs-dr-server.sh

30 lines
551 B

#!/usr/bin/bash
# VIP
VIP=192.168.96.200
# 真实服务器
REAL_SERVER=(192.168.96.167 192.168.96.168 192.168.96.170)
# 真实服务器权重
WEIGHT=(3 5 15)
# 调度算法
SCHEDULER=wrr
INTERFACE=ens33
NETMASK=32
case $1 in
start)
ip addr add $VIP/$NETMASK dev $INTERFACE
# 设置虚拟服务
ipvsadm -A -t $VIP:80 -s $SCHEDULER
for i in ${!REAL_SERVER[@]}
do
ipvsadm -a -t $VIP:80 -r ${REAL_SERVER[$i]}:80 -g -w ${WEIGHT[$i]}
done
;;
stop)
ipvsadm -C
;;
*)
echo "Usage: $0 {start|stop}"
;;
esac