#!/bin/bash
VIP=192.168.100.2
count=1
RIP=/home/"RIP"
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
cat /etc/sysctl.conf | sort |uniq > /etc/sysctl.conf #先输入 然后去重复 再写入/sysctl.conf
`ip addr del $VIP/32 dev eno16777736:0`
`ip addr add $VIP/32 dev eno16777736:0`
`rm -rf /etc/sysconfig/network-scripts/ifcfg-eno16777736:0`
touch /etc/sysconfig/network-scripts/ifcfg-eno16777736:0
echo 'DEVICE=eno16777736:0
IPADDR='$VIP'
NETMASK=255.255.255.255
ONBOOT=yes
NAME=eno16777736:0' > /etc/sysconfig/network-scripts/ifcfg-eno16777736:0
`ipvsadm -D -t $VIP:http` > /dev/null 2>&1
`ipvsadm -A -t $VIP:http -s rr` > /dev/null 2>&1
function STARTA {
for R in `cat $RIP`
do
curl --connect-timeout 1 $R > /dev/null 2>&1 #监听服务器是否运行
count=`echo $?`
if [ $count -eq 0 ]
then
ipvsadm -a -t $VIP:http -r $R:http -g > /dev/null 2>&1 #服务器在线
else
ipvsadm -d -t $VIP:http -r $R:http > /dev/null 2>&1 #服务器下线
fi
done
sleep 3
STARTA
}
STARTA
VIP=192.168.100.2
count=1
RIP=/home/"RIP"
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
cat /etc/sysctl.conf | sort |uniq > /etc/sysctl.conf #先输入 然后去重复 再写入/sysctl.conf
`ip addr del $VIP/32 dev eno16777736:0`
`ip addr add $VIP/32 dev eno16777736:0`
`rm -rf /etc/sysconfig/network-scripts/ifcfg-eno16777736:0`
touch /etc/sysconfig/network-scripts/ifcfg-eno16777736:0
echo 'DEVICE=eno16777736:0
IPADDR='$VIP'
NETMASK=255.255.255.255
ONBOOT=yes
NAME=eno16777736:0' > /etc/sysconfig/network-scripts/ifcfg-eno16777736:0
`ipvsadm -D -t $VIP:http` > /dev/null 2>&1
`ipvsadm -A -t $VIP:http -s rr` > /dev/null 2>&1
function STARTA {
for R in `cat $RIP`
do
curl --connect-timeout 1 $R > /dev/null 2>&1 #监听服务器是否运行
count=`echo $?`
if [ $count -eq 0 ]
then
ipvsadm -a -t $VIP:http -r $R:http -g > /dev/null 2>&1 #服务器在线
else
ipvsadm -d -t $VIP:http -r $R:http > /dev/null 2>&1 #服务器下线
fi
done
sleep 3
STARTA
}
STARTA