Linux/Python学习论坛-京峰教育

 找回密码
 立即注册

一键登录:

搜索
热搜: 活动 交友 discuz
查看: 1023|回复: 0

keepalived故障处理一例

[复制链接]

238

主题

288

帖子

1925

积分

超级版主

Rank: 8Rank: 8

积分
1925
QQ
发表于 2015-3-18 15:43:42 | 显示全部楼层 |阅读模式
一日发现keepalived+haproxy的主从自动切换失效了,即当keepalived的MASTER机宕或haproxy程序挂后不会自动切换到从机。
我的keepalived配置文件如下:
! Configuration File for keepalived


global_defs {
   notification_email {
      xx@xx.com
   }
   notification_email_from xx@xx.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 3
   router_id Mysql_HA
}


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


vrrp_instance VI_1 {
    state MASTER    #从为BACKUP
    interface eth1
    virtual_router_id 52
    garp_master_delay 1
    priority 101       #从为100
    advert_int 1


    authentication {
        auth_type PASS
        auth_pass 3333
!        auth_pass FDGdgerg34juyjTD5
    }


    virtual_ipaddress {
        192.168.1.100
    }


    track_interface {
!        eth0
        eth1
    }


    track_script {
        chk_haproxy
    }
#mail notify
    notify_master "/etc/keepalived/Mailnotify.py master"
    notify_backup "/etc/keepalived/Mailnotify.py backup"
    notify_fault "/etc/keepalived/Mailnotify.py fault"
}


查看日志
cat /var/log/messages|grep Keepalived|more
发现如下错误信息:
MASTER端
May 22 12:00:05 chinaface-web4 Keepalived: Starting Keepalived v1.2.2 (05/18,2011)
May 22 12:00:05 chinaface-web4 Keepalived: Starting VRRP child process, pid=13085
May 22 12:00:05 chinaface-web4 Keepalived_vrrp: Registering Kernel netlink reflector
May 22 12:00:05 chinaface-web4 Keepalived_vrrp: Registering Kernel netlink command channel
May 22 12:00:05 chinaface-web4 Keepalived_vrrp: Registering gratutious ARP shared channel
May 22 12:00:05 chinaface-web4 Keepalived_vrrp: Opening file '/etc/keepalived/keepalived.conf'.
May 22 12:00:05 chinaface-web4 Keepalived_vrrp: Configuration is using : 67066 Bytes
May 22 12:00:05 chinaface-web4 Keepalived_vrrp: Using LinkWatch kernel netlink reflector...
May 22 12:00:05 chinaface-web4 Keepalived_vrrp: cant do IP_ADD_MEMBERSHIP errno=No such device (19)
May 22 12:00:05 chinaface-web4 Keepalived_vrrp: VRRP sockpool: [ifindex(3), proto(112), fd(-1,-1)]
May 22 12:00:05 chinaface-web4 Keepalived_vrrp: VRRP_Script(chk_haproxy) succeeded
May 22 12:00:06 chinaface-web4 Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
May 22 12:00:07 chinaface-web4 Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
May 22 12:00:07 chinaface-web4 Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
May 22 12:00:07 chinaface-web4 Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.1.100
BACKUP端
May 22 11:12:21 chinaface-manager1 Keepalived: Starting Keepalived v1.2.2 (05/18,2011)
May 22 11:12:21 chinaface-manager1 Keepalived: Starting VRRP child process, pid=17935
May 22 11:12:21 chinaface-manager1 Keepalived_vrrp: Registering Kernel netlink reflector
May 22 11:12:21 chinaface-manager1 Keepalived_vrrp: Registering Kernel netlink command channel
May 22 11:12:21 chinaface-manager1 Keepalived_vrrp: Registering gratutious ARP shared channel
May 22 11:12:21 chinaface-manager1 Keepalived_vrrp: Opening file '/etc/keepalived/keepalived.conf'.
May 22 11:12:21 chinaface-manager1 Keepalived_vrrp: Configuration is using : 67174 Bytes
May 22 11:12:21 chinaface-manager1 Keepalived_vrrp: Using LinkWatch kernel netlink reflector...
May 22 11:12:21 chinaface-manager1 Keepalived_vrrp: cant do IP_ADD_MEMBERSHIP errno=No such device (19)
May 22 11:12:21 chinaface-manager1 Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
May 22 11:12:21 chinaface-manager1 Keepalived_vrrp: VRRP sockpool: [ifindex(3), proto(112), fd(-1,-1)]
May 22 11:12:21 chinaface-manager1 Keepalived_vrrp: VRRP_Script(chk_haproxy) succeeded
May 22 11:12:24 chinaface-manager1 Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
May 22 11:12:25 chinaface-manager1 Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
May 22 11:12:25 chinaface-manager1 Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
May 22 11:12:25 chinaface-manager1 Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.1.100
日志中都有一条信息:cant do IP_ADD_MEMBERSHIP errno=No such device (19)


Google之,从如下URL中获得提示:
http://archive.linuxvirtualserver.org/html/lvs-users/2005-08/msg00007.html
http://www-shrimp.cs.ucl.ac.uk/multimedia/software/documentation/ipv6.html#mroute


keepalived用来进行监控或心跳的网卡需要是拥有IP地址的网卡。
这让我想起了不久前将所有服务器的双网卡都进行了绑定,生成一个虚拟网卡bond0,而原先配有IP地址的eth1现在是无IP地址状态。
于是修改下keepalived的配置文件keepalived.conf,将其中的所有eth1换成了bond0,故障排除。更改后的配置文件如下:
! Configuration File for keepalived


global_defs {
   notification_email {
      xx@xx.com
   }
   notification_email_from xx@xx.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 3
   router_id Mysql_HA
}


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


vrrp_instance VI_1 {
    state MASTER    #从为BACKUP
    interface bond0
    virtual_router_id 52
    garp_master_delay 1
    priority 101       #从为100
    advert_int 1


    authentication {
        auth_type PASS
        auth_pass 3333
!        auth_pass FDGdgerg34juyjTD5
    }


    virtual_ipaddress {
        192.168.1.100
    }


    track_interface {
!        eth0
        bond0
    }


    track_script {
        chk_haproxy
    }
#mail notify
    notify_master "/etc/keepalived/Mailnotify.py master"
    notify_backup "/etc/keepalived/Mailnotify.py backup"
    notify_fault "/etc/keepalived/Mailnotify.py fault"
}




日志信息如下:
MASTER
May 22 14:52:36 chinaface-web4 Keepalived: Starting Keepalived v1.2.2 (05/18,2011)
May 22 14:52:36 chinaface-web4 Keepalived: Starting VRRP child process, pid=23796
May 22 14:52:36 chinaface-web4 Keepalived_vrrp: Registering Kernel netlink reflector
May 22 14:52:36 chinaface-web4 Keepalived_vrrp: Registering Kernel netlink command channel
May 22 14:52:36 chinaface-web4 Keepalived_vrrp: Registering gratutious ARP shared channel
May 22 14:52:36 chinaface-web4 Keepalived_vrrp: Opening file '/etc/keepalived/keepalived.conf'.
May 22 14:52:36 chinaface-web4 Keepalived_vrrp: Configuration is using : 67040 Bytes
May 22 14:52:36 chinaface-web4 Keepalived_vrrp: Using LinkWatch kernel netlink reflector...
May 22 14:52:36 chinaface-web4 Keepalived_vrrp: VRRP sockpool: [ifindex(4), proto(112), fd(10,11)]
May 22 14:52:36 chinaface-web4 Keepalived_vrrp: VRRP_Script(chk_haproxy) succeeded
May 22 14:52:37 chinaface-web4 Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
May 22 14:52:38 chinaface-web4 Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
May 22 14:52:38 chinaface-web4 Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
May 22 14:52:38 chinaface-web4 Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on bond0 for 192.168.1.100
BACKUP
May 22 14:53:17 chinaface-manager1 Keepalived: Starting VRRP child process, pid=2561
May 22 14:53:17 chinaface-manager1 Keepalived_vrrp: Opening file '/etc/keepalived/keepalived.conf'.
May 22 14:53:17 chinaface-manager1 Keepalived_vrrp: Configuration is using : 67048 Bytes
May 22 14:53:17 chinaface-manager1 Keepalived_vrrp: Using LinkWatch kernel netlink reflector...
May 22 14:53:17 chinaface-manager1 Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
May 22 14:53:17 chinaface-manager1 Keepalived_vrrp: VRRP sockpool: [ifindex(4), proto(112), fd(10,11)]
May 22 14:53:17 chinaface-manager1 Keepalived_vrrp: VRRP_Script(chk_haproxy) succeeded

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|京峰教育,只为有梦想的人 ( 京ICP备15013173号 )

GMT+8, 2020-2-25 13:33 , Processed in 0.025136 second(s), 11 queries , Redis On.

快速回复 返回顶部 返回列表