virtual ip:192.168.0.124 load balancer:192.168.0.8 backup:192.168.0.33 real server1:192.168.0.125 real server2:192.168.0.77 load balancer的主备机配置: 安装: lftp 192.168.0.254 cd /pub/docs/keepalived/ get keepalived-1.2.2.tar.gz quit tar zxf keepalived-1.2.2.tar.gz cd keepalived-1.2.2 ./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.32-71.el6.x86_64/ make && make install 注意编译时需看到以下即为OK。 Use IPVS Framework : Yes IPVS sync daemon support : Yes Use VRRP Framework : Yes 配置: mkdir /etc/keepalived ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/ ln -s /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ ln -s /usr/local/keepalived/sbin/keepalived /sbin/ vim /etc/keepalived/keepalived.conf ======================================================= ! Configuration File for keepalived global_defs { notification_email { josion1989@163.com } notification_email_from root@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER //on backup change this to: BACKUP interface eth0 virtual_router_id 7 //this must keep same with backup priority 150 //主机优先级,备机改为50 advert_int 1 //主备间通告间隔秒数 authentication { //主备切换时的验证 auth_type PASS auth_pass 1111 } virtual_ipaddress { //HA 的virtual ip,可多个 192.168.0.124 } } virtual_server 192.168.0.124 80 { delay_loop 6 //每隔6秒查询real server 状态 lb_algo rr //lvs 轮叫调度RR lb_kind DR //lvs负载均衡机制,直连路由 persistence_timeout 50 //同一IP的连接50秒内被分配到同一台real server protocol TCP //用TCP协议检查real server 状态 real_server 192.168.0.125 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 //故障重试秒数 delay_before_retry 3 //重试延迟 } } real_server 192.168.0.77 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } } ======================================================== real server配置: vi /etc/sysctl.conf net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.lo.arp_ignore = 1 net.ipv4.conf.all.arp_announce = 2 net.ipv4.conf.lo.arp_announce = 2 sysctl -p ifconfig eth0:0 192.168.0.124 netmask 255.255.255.255 up route add -host 192.168.0.124 dev eth0:0 echo `hostname` > /var/www/html/index.html /etc/init.d/httpd start 测试: 访问http://192.168.0.124 不断刷新看到在两个real server上切换即OK! ipvsadm -Lnc 查看详细连接情况.