脑裂产生的原因
一般来说,裂脑的发生,有以下几种原因:
- 高可用服务器对之间心跳线链路发生故障,导致无法正常通信。
- 因心跳线坏了(包括断了,老化)。
- 因网卡及相关驱动坏了,ip配置及冲突问题(网卡直连)。
- 因心跳线间连接的设备故障(网卡及交换机)。
- 因仲裁的机器出问题(采用仲裁的方案)。
- 高可用服务器上开启了 iptables防火墙阻挡了心跳消息传输。
- 高可用服务器上心跳网卡地址等信息配置不正确,导致发送心跳失败。
- 其他服务配置不当等原因,如心跳方式不同,心跳广插冲突、软件Bug等。
注意:
Keepalived配置里同一 VRRP实例如果 virtual_router_id两端参数配置不一致也会导致裂脑问题发生。
脑裂常见的解决方案
在实际生产环境中,我们可以从以下几个方面来防止裂脑问题的发生:
- 同时使用串行电缆和以太网电缆连接,同时用两条心跳线路,这样一条线路坏了,另一个还是好的,依然能传送心跳消息。
- 当检测到裂脑时强行关闭一个心跳节点(这个功能需特殊设备支持,如Stonith、feyce)。相当于备节点接收不到心跳消患,通过单独的线路发送关机命令关闭主节点的电源。
- 做好对裂脑的监控报警(如邮件及手机短信等或值班).在问题发生时人为第一时间介入仲裁,降低损失。例如,百度的监控报警短倍就有上行和下行的区别。报警消息发送到管理员手机上,管理员可以通过手机回复对应数字或简单的字符串操作返回给服务器.让服务器根据指令自动处理相应故障,这样解决故障的时间更短.
当然,在实施高可用方案时,要根据业务实际需求确定是否能容忍这样的损失。对于一般的网站常规业务.这个损失是可容忍的。
配置zabbix监控脑裂
监控只是监控发生脑裂的可能性,不能保证一定是发生了脑裂,因为正常的主备切换VIP也是会到备上的
环境:
主机名 | IP |
---|---|
zabbix(zabbix_server) | 192.168.159.3 |
slave(zabbix_agent) | 192.168.159.5 |
master | 192.168.159.4 |
VIP在这里使用192.168.159.250。在做下面操作前,请确保zabbix的web界面能够访问
在slave上编写监控脚本
[root@slave ~]# mkdir -p /scripts
[root@slave ~]# cd /scripts
[root@slave scripts]# vim check_k.sh
#!/bin/bash
if [ `ip a show ens33 |grep 192.168.159.250|wc -l` -ne 0 ];then
echo "1"
else
echo "0"
fi
在slave上配置agent
[root@slave ~]# tar xf zabbix-5.0.1.tar.gz
[root@slave ~]# cd zabbix-5.0.1
[root@slave zabbix-5.0.1]# useradd -r -M -s /sbin/nologin zabbix
[root@slave zabbix-5.0.1]# yum -y install gcc gcc-c++ pcre-devel
[root@slave zabbix-5.0.1]# ./configure --enable-agent
[root@slave zabbix-5.0.1]# make install
[root@slave zabbix-5.0.1]# cd /usr/local/etc/
[root@slave zabbix-5.0.1]# cd /usr/local/etc/
[root@slave etc]# vim zabbix_agentd.conf
...
# Mandatory: yes, if StartAgents is not explicitly set to 0
# Default:
# Server=
Server=192.168.159.3 //将后面的IP改为server端的IP
### Option: ListenPort
# Agent will listen on this port for connections from the server.
...
# Mandatory: no
# Default:
# ServerActive=
ServerActive=192.168.159.3 //和上面一样
### Option: Hostname
# Unique, case sensitive hostname.
...
# Unique, case sensitive hostname.
# Hostname=
Hostname=slave //主机名不能和server端一样
### Option: HostnameItem
# Item used for generating Hostname if it is undefined. Ignored if Hostname is defined.
...
# Mandatory: no
# Range: 0-1
# Default:
UnsafeUserParameters=1 //将此行取消注释,并将0改为1
### Option: UserParameter
# User-defined parameter to monitor. There can be several user-defined parameters.
# Format: UserParameter=<key>,<shell command>
# See 'zabbix_agentd' directory for examples.
#
# Mandatory: no
# Default:
UserParameter=check_keepalived,/bin/bash /scripts/check_keepalived.sh //修改此行内容
...
[root@slave etc]# pkill zabbix
[root@slave etc]# zabbix_agentd
在master和slave上配置keepalived
master配置:
root@master ~]# yum -y install keepalived httpd
[root@master ~]# echo 'master' > /var/www/html/index.html
[root@master ~]# systemctl enable --now httpd
[root@master ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id lb01
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 25
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass dengzichen
}
virtual_ipaddress {
192.168.159.250
}
}
virtual_server 192.168.159.250 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.159.4 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.159.5 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
[root@master ~]# systemctl enable --now keepalived
slave配置:
[root@slave ~]# yum -y install keepalived httpd
[root@slave ~]# echo 'slave' > /var/www/html/index.html
[root@slave ~]# systemctl enable --now httpd
[root@slave ~]# vim /etc/keepalived/keepalived.conf
[root@slave ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id lb02
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 25
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass dengzichen
}
virtual_ipaddress {
192.168.159.250
}
}
virtual_server 192.168.159.250 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.159.4 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.159.5 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
[root@slave ~]# systemctl enable --now keepalived
在zabbix的web界面配置
创建主机组,并创建监控主机加入主机组
添加监控项
添加触发器
添加媒介
添加动作
整个监控至此就做好了
评论区