LVS-DR部署
更新:HHH   时间:2023-1-7


LVS-DR部署脚本
#!/bin/bash
VIP=192.168.11.100
DIP=192.168.11.11
RIP1=192.168.11.12
RIP2=192.168.11.13
POST=80
lvs_dr() {
ifconfig eth0:0 $VIP netmask 255.255.255.0 up
route add -host $VIP dev eth0:0
rpm -q ipvsadm && echo "ipvsadm exists" || yum -y install ipvsadm &> /dev/null
echo 1 > /proc/sys/net/ipv4/ip_forward
ipvsadm -C
ipvsadm -At ${VIP}:${POST} -s wrr
ipvsadm -at ${VIP}:${POST} -r ${RIP1}:${POST} -g -w 1
ipvsadm -at ${VIP}:${POST} -r ${RIP2}:${POST} -g -w 3
ipvsadm -Ln

}
rs_web() {
ifconfig lo:0 $VIP netmask 255.255.255.255 up
route add -host $VIP dev lo:0
rpm -q httpd && echo "httpd already installd" || yum -y install httpd &>/dev/null
systemctl restart httpd
systemctl enable httpd
web_ip=$(ifconfig eth0 | awk '/netmask/{print $2}')
echo $web_ip > /var/www/html/index.html
curl $web_ip
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p

}

case $1 in
start)
lvs_dr
ipvsadm --save
;;
stop)
ipvsadm -C
ipvsadm -Ln
;;
rs_web)
rs_web
;;
*)
echo "usage : $0 [start|stop|rs_web]"
;;
esac

返回云计算教程...