标签:
本文主要介绍zabbix监控mysql的配置,包含使用zabbix自带模板监控mysql相关信息及自定义key监控mysql同步情况。同时介绍了触发器的创建及zabbix通过邮件方式告警配置。
一、配置自带模板监控mysql
1.提供配置文件模板
文件位置在源码包/usr/local/src/zabbix-3.0.4/conf/zabbix_agentd/userparameter_mysql.conf
1
|
#cp/usr/local/src/zabbix-3.0.4/conf/zabbix_agentd/userparameter_mysql.conf /usr/local/zabbix/etc/zabbix_agentd.conf.d |
2.修改模板文件
1
|
#sed -i ‘s@/var/lib/zabbix@/usr/local/zabbix/etc@g‘ /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf |
修改后的文件
UserParameter=mysql.status[*],echo "show global status where Variable_name=‘$1‘;" | HOME=/usr/local/zabbix/etc /usr/local/mysql/bin/mysql -N | awk ‘{print $$2}‘
UserParameter=mysql.size[*],bash -c ‘echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");" | HOME=/usr/local/zabbix/etc /usr/local/mysql/bin/mysql -N‘
UserParameter=mysql.ping,HOME=/usr/local/zabbix/etc /usr/local/mysql/bin/mysqladmin ping | grep -c alive
UserParameter=mysql.version,/usr/local/mysql/bin/mysql -V
3.提供agent连数据库的文件
1
2
3
4
5
6
7
8
9
10
11
|
#vi /usr/local/zabbix/etc/.my.cnf [mysql] host=localhost user=zabbixagent password=123456 socket= /tmp/mysql .sock [mysqladmin] host=localhost user=zabbixagent password=123456 socket= /tmp/mysql .sock |
4.创建授权账号
1
2
|
mysql> GRANT USAGE,PROCESS,REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO ‘zabbixagent‘ @ ‘localhost‘ IDENTIFIED BY ‘123456‘ ; mysql> flush privileges; |
5.修改zabbix_agentd.conf
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
重启服务
6.在web界面关联mysql模板
7.最终效果
二、自定义key监控slave
1.提供监控slave的配置文件
#cat/usr/local/zabbix/etc/zabbix_agentd.conf.d/mysql_slave.conf
UserParameter=mysql.slave.Seconds_Behind_Master,echo "show slave status\G"| HOME=/usr/local/zabbix/etc /usr/local/mysql/bin/mysql |grep "Seconds_Behind_Master"|awk ‘{print $2}‘
UserParameter=mysql.slave.Slave_IO_Running,echo "show slave status\G"| HOME=/usr/local/zabbix/etc /usr/local/mysql/bin/mysql |grep "Slave_IO_Running"|awk ‘{print $2}‘
UserParameter=mysql.slave.Slave_SQL_Running,echo "show slave status\G"|HOME=/usr/local/zabbix/etc /usr/local/mysql/bin/mysql |grep "\<Slave_SQL_Running\>"|awk ‘{print $2}‘
2.重启agent服务
# service zabbix_agentd restart
3.命令测试key获取的值
# /usr/local/zabbix/bin/zabbix_get -s 192.168.1.16 -k "mysql.slave.Seconds_Behind_Master"
# /usr/local/zabbix/bin/zabbix_get -s 192.168.1.16 -k "mysql.slave.Slave_IO_Running"
# /usr/local/zabbix/bin/zabbix_get -s 192.168.1.16 -k "mysql.slave.Slave_SQL_Running"
以上命令均返回正常值说明自定义key成功
4.在web界面配置监控项
创建slave延迟items
创建slave io线程items
创建slave sql线程items
三、主从同步延迟报警配置
1.定义触发器
创建主从延迟触发器
2.定义action
3.定义邮件发送用户
修改报警媒介类型的邮件服务器地址
用户关联到报警媒介并设置邮件账号
查看邮件
邮件具体内容
四、主从同步状态报警配置
1.创建主从同步状态触发器
定义io thread状态
定义sql thread状态
2.测试
在slave上分别停止io线程和sql线程
模拟停止io线程
mysql> stop slave io_thread;
同时告警邮件发出
恢复io线程
mysql> start slave io_thread;
故障恢复通知邮件
模拟停止sql线程
mysql> stop slave sql_thread;
同时告警邮件发出
恢复sql线程
mysql> start slave sql_thread;
故障恢复通知邮件
http://hnr520.blog.51cto.com/4484939/1852838
标签:
原文地址:http://www.cnblogs.com/chen110xi/p/5891318.html