一、安装keepalived,httpd,略
二、Master配置
Master:
!要使用ha功能,不能使用vrrp_sync_group
!vrrp_sync_group VG1 {
!         group {
!                VI_1
!         }
!}
vrrp_script chk_http_port {
          ! script "/usr/local/keepalived/sbin/nginx_sh.sh"
           script "killall -0 httpd"
          interval 2
          weight 4
}
vrrp_instance VI_1 {
        interface eth0
        state MASTER
        virtual_router_id 51
        priority 100
        authentication {
            auth_type PASS
            auth_pass 111
        }
        track_script {
            chk_http_port
        }
        virtual_ipaddress {
            192.168.8.20/24 dev eth0
            192.168.8.30/24 dev eth0
        }
}
三、Backup配置
Backup:
!vrrp_sync_group VG1 {
!         group {
!                VI_1
!         }
!}
!要使用ha功能,不能使用vrrp_sync_group
vrrp_script chk_http_port {
         ! script "/usr/local/keepalived/sbin/nginx_sh.sh"
          script "killall -0 httpd"
          interval 2
          weight 4
}
vrrp_instance VI_1 {
        interface eth0
        state BACKUP
        virtual_router_id 51
        priority 98
        authentication {
            auth_type PASS
            auth_pass 111
        }
        track_script {
            chk_http_port
        }
        virtual_ipaddress {
            192.168.8.20/24 dev eth0
            192.168.8.30/24 dev eth0
        }
}
四、keepalived启动处理
#keepalived 启动方式放在脚本里
[root@ora2 keepalived]# cat /usr/bin/keepalived_start
/usr/local/keepalived/sbin/keepalived -D -f /usr/local/keepalived/etc/keepalived/keepalived.conf
五、处理vip无法被应用绑定
net.ipv4.ip_nonlocal_bind=1
五、注意:主备(m/s)的priority值不能相差太多,一般在1-2个点,备机priority值需在加上weight值时超过master上的priority值.