zabbix监控mysql主从复制

有关mysql的主从复制内容请参考:

https://www.cnblogs.com/clsn/p/8150036.html

环境:

mysql版本:Server version: 5.1.73

主库:10.0.0.9

从库:10.0.0.10

1)在从库上测试slave的状态:

[root@web02 zabbix_agentd.conf.d]#  mysql -uroot -p123456 -e "show slave status\G"|grep -E " Slave_IO_Running| Slave_SQL_Running"|awk '{print $2}'|grep -c Yes
2

2)在zabbix_agent端加入mysql.replication监控项

说明:之前已经对mysql进项了监控,这里我仿照mysql,添加了要监控的内容如下:

UserParameter=mysql.ping,mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V
UserParameter=mysql.status[*],/application/zabbix_agent/scripts/chk_mysql.sh $1

#mysql repication_check UserParameter=mysql.replication,sh /application/zabbix_agent/scripts/chk_mysql_replication.sh

3)建立脚本文件chk_mysql_replication.sh

[root@web02 ~]# vim /application/zabbix_agent/scripts/chk_mysql_replication.sh 

/usr/bin/mysql -uroot -p123456 -e "show slave status\G"|grep -E " Slave_IO_Running| Slave_SQL_Running"|awk '{print $2}'|grep -c Yes
加执行权限:
chmod +x /application/zabbix_agent/scripts/chk_mysql_replication.sh

4)zabbix服务器端连接测试:

  (返回值是2,说明从库IO,SQL线程均YES,表示主从同步没问题)

[root@ZabbixServer zabbix_agentd.conf.d]# /application/zabbix/bin/zabbix_get -s 10.0.0.10 -k 'mysql.replication'
2 

5)创建监控item

 

6)创建监控图形

7)设置触发器

 

 

 

posted @ 2018-09-27 20:56  命由己造~  阅读(1003)  评论(0)    收藏  举报