1:yum -y install ipvsadm keepalived
2:在/etc/rc.local里添加
echo 1 > /proc/sys/net/ipv4/ip_forward
3:编辑/etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { //每个实例取一个好记的名字 state MASTER //主配MASTER,备配BACKUP interface eth1 virtual_router_id 200 //这个值主备要一样,但是不要和其他lvs冲突 priority 100 //主配100,备配80 advert_int 1 authentication { auth_type PASS auth_pass 111158 } virtual_ipaddress { 211.151.111.4 } } virtual_server 211.151.111.4 80 { delay_loop 6 lb_algo wrr lb_kind DR persistence_timeout 50 protocol TCP real_server 10.4.11.24 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 10.4.11.25 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } }
4:编辑/etc/sysconfig/keepalived
KEEPALIVED_OPTIONS="-D -S 2"
5:编辑/etc/logrotate.d/syslog,加一行
/var/log/keepalived.log
6:service keepalived restart
1:编辑/opt/script/lvs_dr.sh
#!/bin/sh VIP=211.151.111.4 #这里填VS的VIP /etc/rc.d/init.d/functions case "$1" in start) echo "Start LVS of RealServer" /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce ;; stop) /sbin/ifconfig lo:0 down echo "Stop LVS of RealServer" echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce ;; *) echo "Usage:$0{start|stop}" exit 1 esac
2:设置权限,启动服务
chmod 777 /opt/script/lvs_dr.sh /opt/script/lvs_dr.sh start
3:编辑/etc/rc.local,添加一行
/opt/script/lvs_dr.sh start