keepalived实现IP地址高可用

yum -y install keepalived

vim /etc/keepalived/keepalived.conf

global_defs {  
   router_id LVS_DEVEL_nginx  # 设置lvs的id,在一个网络内应该是唯一的
}  
vrrp_instance VI_1 {  
    state BACKUP   #指定Keepalived的角色,MASTER为主,BACKUP为备          
    interface ens192  #指定Keepalived的角色,MASTER为主,BACKUP为备
    virtual_router_id 61  #虚拟路由编号,主备要一致
    priority 99  #定义优先级,数字越大,优先级越高,主DR必须大于备用DR    
    advert_int 1  #检查间隔,默认为1s
    authentication {  
        auth_type PASS  
        auth_pass 1111  
    }  
    virtual_ipaddress {  
        192.168.2.33  #定义虚拟IP(VIP)为192.168.2.33,可多设,每行一个
    }  
}  

  systemctl start keepalived

yum安装后默认的日志在/var/log/message

tail -f /var/log/message查看keepalived开启跟关闭输出结果,当一主一备时,对外的虚拟IP地址飘在主上,当主挂了,IP地址飘向备,当主开启后,IP地址会从备飘向主

posted on 2019-04-15 14:37  一直用这名字  阅读(975)  评论(0编辑  收藏  举报

导航