使用Zabbix监控MySQL主从图文讲解,希望对你有所帮助。
#脚本如下,截取主从关键字
cat check_mysql_slave.sh
#!/bin/bash
# declare -a 定义数组,slave_is 会被视为数组
declare -a slave_is
slave_is=($(/data/mysql/bin/mysql -e "show slave status\G"|grep -E "Slave_IO_Running|Slave_SQL_Running:"|awk '{print $2}'))
if [ "${slave_is[0]}" = "Yes" -a "${slave_is[1]}" = "Yes" ];then
echo "ok -slave is running"
exit 0
else
echo "down -slave is not running"
exit 2
fi
#zabbix_agentd.conf文件的配置如下:
cat zabbix_agentd.conf | grep -v "^#" | grep -v "^$"
LogFile=/tmp/zabbix_agentd.log
EnableRemoteCommands=1
Server=10.74.246.70
ListenPort=10050
ServerActive=10.74.246.70
Hostname=10.74.244.33
AllowRoot=1
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
UnsafeUserParameters=1
UserParameter=tomcat_port,/usr/local/zabbix/share/zabbix/alertscripts/tomcat_port.sh $1
UserParameter=tcp[*],/usr/local/zabbix/share/zabbix/alertscripts/tcp_connection.sh $1
UserParameter=nginx_port,/usr/local/zabbix/share/zabbix/alertscripts/nginx_port.sh $1
UserParameter=erro_log[*],/usr/local/zabbix/share/zabbix/alertscripts/error_log.sh $1
#mysql主从监控脚本,grep -c "ok",ok出现的次数
UserParameter=mysql.slave,/usr/local/zabbix/share/zabbix/alertscripts/check_mysql_slave.sh | grep -c 'ok'
#创建自定义模板:
#创建应用集:
#创建监控项:
#创建触发器:
#添加mysql-slave监控图形:
#查看图形监控效果:
一些Zabbix相关教程集合:
CentOS 7上Zabbix使用总结
CentOS 7.2 安装部署 Zabbix 3.0.4 详解
Ubuntu 14.04下Zabbix2.4.5 源码编译安装 .com/Linux/2015-05/117657.htm