一直在用的系统版本是12.04,本次安装keepalived中,默认安装的是1.2.2的版本,需要安装新版本,可以通过下载tar.gz包编译安装,但个人更倾向于使用apt-get install 的方式安装,来避免一些不必要的问题。

添加PPA:

apt-get install python-software-properties
sudo add-apt-repository ppa:keepalived/daily
sudo apt-get update

安装:

apt-get install keepalived

配置实例:
MASTER:

! Configuration File for keepalived

global_defs {
   router_id LVS_DEVEL_SERVER 
}

vrrp_script chk_haproxy {
    script "killall -0 haproxy"
    interval 2 
    weight -2 
}

vrrp_instance vip1 {
    state MASTER
    interface eth0
    virtual_router_id 11 #同网域下该值每一对VRRP之间要区分开
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 9292
    }
    virtual_ipaddress {
        192.168.1.11/24
    }
    track_script {
        chk_haproxy              
    }
}

BACKUP:

! Configuration File for keepalived

global_defs {
   router_id LVS_DEVEL_SERVER
}

vrrp_script chk_haproxy {
    script "killall -0 haproxy"  
    interval 2                   
    weight -2                    
}

vrrp_instance vip1 {
    state BACKUP
    interface eth0
    virtual_router_id 11
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 9292
    }
    virtual_ipaddress {
        192.168.1.11/24
    }
    track_script {               
        chk_haproxy
    }
}

完。