3.撰写realserver脚本(三台一样)
[root@localhost ~]# vi /etc/init.d/lvs-realserver.sh
#/bin/bash
VIP=162.28.29.75
start(){
/sbin/ifconfig eth0:1 ${VIP} broadcast ${VIP} netmask 255.255.255.0 up
/sbin/route add -host ${VIP} dev eth0:1
/sbin/sysctl -w net.ipv4.conf.lo.arp_ignore=1
/sbin/sysctl -w net.ipv4.conf.lo.arp_announce=2
/sbin/sysctl -w net.ipv4.conf.all.arp_ignore=1
/sbin/sysctl -w net.ipv4.conf.all.arp_announce=2
/sbin/sysctl -p
}
stop(){
/sbin/ifconfig eth0:1 down
/sbin/sysctl -w net.ipv4.conf.lo.arp_ignore=0
/sbin/sysctl -w net.ipv4.conf.lo.arp_announce=0
/sbin/sysctl -w net.ipv4.conf.all.arp_ignore=0
/sbin/sysctl -w net.ipv4.conf.all.arp_announce=0
}
restart(){
stop
start
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
/sbin/ifconfig
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
4.添加执行权限并启动realserver的脚本,加人开机启动(三台都需要)
[root@localhost server]# chmod +x /etc/init.d/lvs-realserver.sh
[root@localhost server]# sh /etc/init.d/lvs-realserver.sh
[root@localhost server]# echo "sh /etc/init.d/lvs-realserver.sh" >> /etc/rc.local
5.打开内核的路由转发功能(MASTER和BACKUP)
[root@localhost~]# vi /etc/sysctl.conf
把net.ipv4.ip_forward = 0 给为 1
执行一下: sysctl -p
6.启动LVS集群(先MASTER.后BACKUP)
[root@localhost ~]# /etc/init.d/keepalived start
7.查看运行情况
[root@localhost ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 162.28.29.75:81 rr persistent 60
-> 162.28.29.40:81 Route 100 1961 0
-> 162.28.29.39:81 Route 100 1648 1
-> 162.28.29.38:81 Local 100 0 227
