标签:stop int nsa director 客户 zab and gen top
搭建MySQL主从后,很多时候不知道从的状态是否ok,有时候出现异常不能及时知道,这里通过shell脚本结合zabbix实现监控并告警
在MySQL的从上查看从的运行状态是通过Slave_IO_Running线程和Slave_SQL_Running线程是否正常,通过命令“show slave status\G;”即可查看。根据这两个值进行判断。
这里已经配置好主从
环境说明:
zabbix_server | 192.168.32.136 |
---|---|
zabbix_agent (mysql主) | 192.168.32.125 |
zabbix_agent(mysql从) | 192.168.32.130 |
安装zabbix客户端
主机组自定义即可
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
......
UnsafeUserParameters=1
......
UserParameter=mysql_master_status,/bin/bash /scripts/mysql_master_status.sh
#配置完成之后重启服务
[root@localhost ~]# vim /scripts/mysql_master_status.sh
#!/bin/bash
status=$(mysql -uroot -p123456 -e ‘show slave status\G‘ 2>/dev/null |grep -E ‘Slave_IO_Running|Slave_SQL_Running:‘|grep -c ‘Yes‘)
if [ $status -ne 2 ];then
echo ‘1‘
else
echo ‘0‘
fi
关闭从库的mysql,查看是否触发警告
[root@localhost ~]# systemctl stop mariadb
已经配置了发送邮件媒介和动作,触发警告时直接发送了邮件
[root@localhost ~]# vim /scripts/mysql_delay
#!/bin/bash
delay=$(mysql -uroot -p123456 -e ‘show slave status\G‘ 2>/dev/null|grep ‘Seconds_Behind_Master‘|awk ‘{print $2}‘)
echo $delay
#编辑配置文件
UnsafeUserParameters=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=
UserParameter=mysql_master_status,/bin/bash /scripts/mysql_master_status.sh
UserParameter=mysql_delay,/bin/bash /scripts/mysql_delay.sh
......
#重启服务
应为主从没有数据,延迟值为0 ,所以修改触发器,延迟值为0的时候触发,来验证
标签:stop int nsa director 客户 zab and gen top
原文地址:https://www.cnblogs.com/shipment/p/13354275.html