上次Zabbix添加了监控MysqL性能,因此此次在其基础上添加主从监控,文章过程中不在介绍MysqL5.6版本相关细节处理,具体可以参考上次文章:
http://www.jb51.cc/article/p-gidnbgtq-bhy.html
1. Zabbix添加自定义监控流程
2. 具体步骤
1. 编写监控MysqL主从脚本
vim /usr/local/zabbix/shell/check_MysqL_slave.sh
#!/usr/bin/envbash #Createbyzijin2014.09.28 ##Need"grantREPLICATIONCLIENTon*.*tozabbix_select@localhostidentifiedby'zabbix'" #MysqL5.6 #MysqL_config_editorset--login-path=local--host=localhost--user=zabbix_select-p MysqL_SOCK="/tmp/MysqL.sock" MysqL_PWD="zabbix" MysqL="/usr/local/MysqL/bin/MysqL" MysqL_ADMIN="${MysqL}admin" ARGS=1 if[$#-ne"$ARGS"];then echo"Pleaseinputonearguement:" fi case$1in Slave_Running) slave_is=($(sudo${MysqL}--login-path=local-S$MysqL_SOCK-e"showslavestatus\G"|egrep"\bSlave_.*_Running\b"|awk'{print$2}')) if["${slave_is[0]}"="Yes"-a"${slave_is[1]}"="Yes"];then result="1" else result="0" fi echo$result ;; Seconds_Behind) result=$(sudo${MysqL}--login-path=local-S$MysqL_SOCK-e"showslavestatus\G"|egrep"\bSeconds_Behind_Master\b"|awk'{print$2}') echo$result ;; *) echo"Usage:$0(Slave_Running|Seconds_Behind)" ;; esac
2. MysqL赋权
grant REPLICATION CLIENT on *.* to zabbix_select@localhost identified by 'zabbix';
3. 查看脚本执行效果
[root@MysqL64shell]#chmoda+xcheck_MysqL_slave.sh [root@MysqL64shell]#shcheck_MysqL_slave.shSlave_Running 1 [root@MysqL64shell]#shcheck_MysqL_slave.shSlave_Seconds 0 [root@MysqL64shell]#
vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/check_MysqL_slave_key
UserParameter=MysqL.slave[*],/usr/local/zabbix/shell/check_MysqL_slave.sh$1$2
5. 添加Zabbix监控MysqL主从模板
从Zabbix页面导入模板Template App MysqL Slave.xml,如下链接为模板地址:
https://github.com/ygqygq2/zabbix/blob/master/%E6%A8%A1%E6%9D%BF/Template%20App%20MySQL%20Slave.xml
图片描述" style="margin:0px;padding:0px;border:0px;width:869px;" src="http://img.blog.csdn.net/20170122201559122">
6. 主机链接模板
图片描述" style="margin:0px;padding:0px;border:0px;width:869px;" src="http://img.blog.csdn.net/20170122202350283">
7. 查看结果
在Zabbi Server端查看:
[root@zabbix-server~]#/usr/local/zabbix/bin/zabbix_get-sMysqL-slave-IP-k"MysqL.slave[Seconds_Behind]" 0 [root@zabbix-server~]#/usr/local/zabbix/bin/zabbix_get-sMysqL-slave-IP-k"MysqL.slave[Slave_Running]" 1
在页面上查看:
图片描述" style="margin:0px;padding:0px;border:0px;width:869px;" src="http://img.blog.csdn.net/20170122202956583">
原文链接:https://www.f2er.com/centos/378928.html