按照{负载均衡lvs+keepalived 配置1}配置好后继续下面keepalived 配置:

环境

lvs-master:192.168.1.22

lvs-backup:192.168.1.175 多增加了一台备份机器

rea1:192.168.1.23

rea2:192.168.1.24


1 下载软件

#wget http://www.keepalived.org/software/keepalived-1.1.20.tar.gz 
#tar -zxvf keepalived-1.1.20.tar.gz 

# cd keepalived-1.1.20

#./configure (安装不成功提示需要安装openssl:yum -y install openssl*)

#make & & make install

#cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/

#cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/

#mkdir /etc/keepalived

#cp /usr/local/sbin/keepalived /usr/sbin/

#vi /etc/keepalived/keepalived.conf (master服务器:192.168.1.22)

! Configuration File for keepalived

global_defs {
   notification_email {
     gzbenetbobo@163.com

   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id bobo1
}

vrrp_instance VI_1 {
    state MASTER     备份机是:BACKUP
    interface eth0
    virtual_router_id 51
    priority 100     优先级需要设置,值越大就是master
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1
    }
    virtual_ipaddress {
        192.168.1.25   虚拟vip
    }
}

virtual_server 192.168.1.25 80 {    虚拟vip
    delay_loop 6
    lb_algo rr
    lb_kind NAT
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP

    real_server 192.168.1.23 80 {
        weight 1
        SSL_GET {
            url {
              path /
              digest ff20ad2481f97b1754ef3e12ecd3a9cc
            }
            url {
              path /mrtg/
              digest 9b3a0c85a887a256d6939da88aabd8cd
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
       }
}
 real_server 192.168.1.24 80 {
        weight 1
        SSL_GET {
            url {
              path /
              digest ff20ad2481f97b1754ef3e12ecd3a9cc
            }
            url {
              path /mrtg/
              digest 9b3a0c85a887a256d6939da88aabd8cd
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
       }
    }
}


上述配置完毕后,先查看lvs-master与lvs-backup的IP状态负载均衡lvs+keepalived 配置2_lvs



然后停止lvs-master查看两台分别状态:

负载均衡lvs+keepalived 配置2_负载均衡_02

如果IP成功切换到备份机器,但是测试80不通,又可能是ipvsadm没有启动没有监听到real服务,重新启动再行测试,

启动顺序,先启动keepalived 然后重启ipvsadm,查看ipvsadm是否监听:

负载均衡lvs+keepalived 配置2_lvs _03


最后一定要在主备设置开机启动,免得日后到出找原因:
chkconfig ipvsadm on
chkconfig keepalived on