一个lvs的安装脚本,大家可以参考一下
说明:
1.给一个可执行权限,在第一台realserver上运行-h,看帮助,
2.创建realserver :运行脚本输入realsever
3.创建lvs:运行脚本输入lvs
#!/bin/bash
#builed realserver
realserver() {
A=`cat /proc/sys/net/ipv4/conf/all/arp_ignore`
if [ $A -eq 0 ]; then
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce
#lo:0 绑定VIP:192.168.2.219
ifconfig lo:0 192.168.2.219/32 up
ifconfig lo:0 192.168.2.219 netmask 255.255.255.255 broadcast 192.168.2.219 up
#指定路由走lo口
route add -host 192.168.2.219 dev lo:0
echo ‘builed realserver --------- ok‘
return 0
else
echo ‘builed realserver --------- ok‘
fi
}
back() {
A=`cat /proc/sys/net/ipv4/conf/all/arp_ignore`
if [ $A -ne 0 ]; then
echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 0 > /proc/sys/net/ipv4/conf/eth0/arp_announce
exit 0
else
echo ‘realserver is back‘
exit 0
}
#lvs安装ipvsadm,
lvs() {
yum -y install ipvsadm & > /dev/null
sleep 30
service ipvsadm start & > /dev/null
chkconfig ipvsadm on
#添加一个虚ip
ip addr add dev eth0 192.168.2.219/32
echo ‘ipvsadm install ok‘
route add -host 192.168.2.219 dev eth0
ipvsadm -C
ipvsadm -A -t 192.168.2.219:3380 -s rr
ipvsadm -a -t 192.168.2.219:3380 -r 192.168.2.213 -g -w1
ipvsadm -a -t 192.168.2.219:3380 -r 192.168.2.214 -g -w1
ipvsadm -a -t 192.168.2.219:3380 -r 192.168.2.215 -g -w1
}
read -p "pleace input realserver|lvs|back|-h|--help"
case $1 in
realserver)
realserver
;;
lvs)
lvs
;;
back)
back
;;
-h|--help)
echo ‘pleace input realserver|lvs|back|-h|--help‘
;;
*)
echo ‘pleace input realserver|lvs|back|-h|--help‘
;;
esac