CentOS6.5下 Keepalived高可用服务单实例配置

CentOS6.5下 Keepalived高可用服务单实例配置

一、环境说明
MASTER节点 192.168.89.100
BACKUP节点 192.168.89.101
VIP:192.168.89.102

二、MASTER节点的配置文件
1、主节点配置文件
! Configuration File for keepalived

global_defs {
  notification_email {
    acassen@firewall.loc
    failover@firewall.loc
    sysadmin@firewall.loc
  }
  notification_email_from Alexandre.Cassen@firewall.loc
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id 1b01
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.89.102/24 dev eth0 label eth0:1
    }
}

2、启动keepalived
[root@kep1 keepalived]# /etc/init.d/keepalived start

3、查看虚拟IP
[root@kep1 keepalived]# ip addr | grep 192.168.89.102
    inet 192.168.89.102/24 scope global secondary eth0

三、BACKUP节点配置文件
1、配置文件
! Configuration File for keepalived

global_defs {
  notification_email {
    acassen@firewall.loc
    failover@firewall.loc
    sysadmin@firewall.loc
  }
  notification_email_from Alexandre.Cassen@firewall.loc
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id 1b02
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.89.102/24 dev eth0 label eht0:1
    }
}

2、启动keepalived
[root@kep2 keepalived]# /etc/init.d/keepalived start

3、检查虚拟IP
[root@kep2 keepalived]# ip addr | grep 192.168.89.102
注意:如果MASTER活着的神话,BACKUP不会接管虚拟IP,所以这里没有输出IP是正常的
如果备节点有出现虚拟IP,那么说明高可用脑裂了,脑裂是两台服务器争抢统一资源导致的,

如果发生脑裂,排除思路如下:
1、主备是否通信正常?防火墙是否阻挡?
2、主备两台的keepalived配置文件是否正确?virtual_router_id是否一样?

四、进行高可用主备服务器切换测试
1、停掉主节点上的keepalived服务,然后在BACKUP节点查看是否接管虚拟IP
2、重新启动主节点上的keepalived服务,看看这时候主节点会不会重新接管VIP,BACKUP节点会不会释放VIP
如果上面两个测试正常,说明配置没有问题。
注意,如果发生脑裂问题,需要注意一下启动顺序

《Keepalived权威指南》下载见

Nginx+Keepalived实现站点高可用 

Nginx+Keepalived实现站点高可用(负载均衡) 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/01ce97f2bb908a62b428feb7a3645ca3.html