keepalived 配置,vip 配置
A主机:
! Configuration File for keepalived
global_defs {
    router_id mycat
}
vrrp_script chk_haproxy {
  script  "killall -0 haproxy"  #cheaper than pidof
    interval 2                  #check every 2 seconds
}
vrrp_instance Mycat1 {
    state BACKUP 
    interface eth0
    track_interface {
        eth0
     }
    virtual_router_id 150
    priority 200
    ! nopreempt
    advert_int 5
    authentication {
        auth_type PASS
        auth_pass test_mycat1
     }
    virtual_ipaddress {
        192.168.1.200/24   brd 192.168.1.255   dev eth0 label eth0:1
     }
    track_script {
       check_haproxy weight=0    #+2 if process is present 
     }
}
vrrp_instance Mycat2 {
    state BACKUP
    interface eth0
    track_interface {
        eth0
     }
    virtual_router_id 151
    priority 100
    nopreempt
    advert_int 5
    authentication {
        auth_type PASS
        auth_pass test_mycat2
     }
    virtual_ipaddress {
        192.168.1.201/24   brd 192.168.1.255   dev eth0 label eth0:2
     }
    track_script {
        check_haproxy weight=0    #+2 if process is present 
     }
}
B主机:
! Configuration File for keepalived
global_defs {
    router_id mycat
}
vrrp_script chk_haproxy {
  script  "killall -0 haproxy"  #cheaper than pidof
    interval 2                  #check every 2 seconds
}
vrrp_instance Mycat1 {
    state BACKUP
    interface eth0
    track_interface {
        eth0
     }
    virtual_router_id 150
    priority 100
    nopreempt 
    advert_int 5
    authentication {
        auth_type PASS
        auth_pass test_mycat1
     }
    virtual_ipaddress {
        192.168.1.200/24   brd 192.168.1.255   dev eth0 label eth0:1
     }
    track_script {
        check_haproxy weight=0    #+2 if process is present 
     }
}
vrrp_instance Mycat2 {
    state BACKUP
    interface eth0
    track_interface {
        eth0
     }
    virtual_router_id 151
    priority 200
    ! nopreempt
    advert_int 5
    authentication {
        auth_type PASS
        auth_pass test_mycat2
     }
    virtual_ipaddress {
        192.168.1.201/24   brd 192.168.1.255   dev eth0 label eth0:2
     }
   track_script {
       check_haproxy weight=0    #+2 if process is present 
    }
}
#都存活A为1.200,B为1.201 ; 任一挂了,另一同时为1.200,1.201,两倍工作量;
最后通过DNS将两个IP(A记录)指向相同域名轮询。
原文:https://www.cnblogs.com/hmj589119/p/10922698.html