概述
zabbix3.0.2 使用percona mysql插件来监控mysql5.7的详细实现过程
--前言
上次用了zabbix自带的mysql插件来监控mysql数据库,但是太过简陋了,对于我们dba来说,基本没有啥作用,所以需要做更详细的监控,而percona就有这个详细监控的模版以及脚本,正好拿过来用。
1, 需要安装php脚本运行环境
percona监控zabbix的脚本使用php写的,所以需要准备好php运行环境,这里直接用yum安装就可以满足要求了:
yum install -y php php-mysql |
2, 加载官方percona模版
去percona官网下载:
[root@zabbix_serv_121_12 percona]# wget https://www.percona.com/downloads/percona-monitoring-plugins/1.1.6/percona-zabbix-templates-1.1.6-1.noarch.rpm
[root@zabbix_serv_121_12 percona]# rpm -ivh percona-zabbix-templates-1.1.6-1.noarch.rpm warning: percona-zabbix-templates-1.1.6-1.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY Preparing... ########################################### [100%] 1:percona-zabbix-template########################################### [100%]
Scripts are installed to /var/lib/zabbix/percona/scripts Templates are installed to /var/lib/zabbix/percona/templates [root@zabbix_serv_121_12 percona]#
|
看到会生成2个目录,/var/lib/zabbix/percona/scripts是监控脚本目录,/var/lib/zabbix/percona/templates是监控mysql的xml模版目录,然后把/var/lib/zabbix/percona/templates/目录下的模版文件zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.6_1.xml复制出来,在zabbix的管理界面import导入进去,但是报如下错误:
Import failed
Details
Invalid XML tag "/zabbix_export/date":"YYYY-MM-DDThh:mm:ssZ" is expected.
经过核查,这个原因是模版错误,是因为percona官方上1.1.6还是zabbix2.0的版本模版,所以需要跟新上来匹配zabbix3.0的模版规范,而且这个zabbix模版还是直接copy的cacti模版,比较粗糙,用more查看就可以看到里面都是cacti的内容,可见percona官网对zabbix也不是很重视嘛,至少不如cacti那样重视的,如下所示:
[root@zabbix_serv_121_12 scripts]# more get_mysql_stats_wrapper.sh |grep cacti CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt" TIMEFLM=`stat -c %Y /tmp/$HOST-mysql_cacti_stats.txt` [root@zabbix_serv_121_12 scripts]# [root@zabbix_serv_121_12 scripts]# [root@zabbix_serv_121_12 scripts]# more ss_get_mysql_stats.php |grep cacti $mysql_user = 'cactiuser'; $mysql_pass = 'cactiuser'; if ( file_exists('/etc/cacti/' . basename(__FILE__) . '.cnf' ) ) { require('/etc/cacti/' . basename(__FILE__) . '.cnf'); debug('Found configuration file /etc/cacti/' . basename(__FILE__) . '.cnf'); $cache_file = "$cache_dir/$sanitized_host-mysql_cacti_stats.txt" . ($port != 3306 ? ":$port" : ''); [root@zabbix_serv_121_12 scripts]# |
3,修改配置模版加载成功
在原来的zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.6_1.xml之上进行修改,改完后就可以import导入进去了,我将修改好的模版文件share下,地址是:http://download.csdn.net/detail/mchdba/9522634
4,添加参数支持
拷贝userparameter_percona_mysql.conf 文件到被监控的mysql服务器上
[root@zabbix_serv_121_12 ~]# scp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf 192.161.3.62:/etc/zabbix/zabbix_agentd.d/ The authenticity of host '192.161.3.62 (192.161.3.62)' can't be established. RSA key fingerprint is 24:b4:e8:76:08:89:e8:3b:75:c7:d3:34:79:19:ba:7c. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.161.3.62' (RSA) to the list of known hosts. root@192.161.3.62's password: userparameter_percona_mysql.conf 100% 18KB 18.4KB/s 00:00 [root@zabbix_serv_121_12 ~]# |
修改客户端的zabbix_agentd.conf文件,增加Include 把userparameter_percona_mysql.conf 所在的目录增加进去:
# 实际测试过程中,貌似不添加也行 vim /etc/zabbix/zabbix_agentd.conf Include=/etc/zabbix/zabbix_agentd.d/userparameter_percona_mysql.conf |
5,修改监控脚本
修改vim /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh脚本,若mysql没有使用默端口3006,则还需要修改如下脚本文件,哥在这里被坑了好久,修改端口号码文件:
# 1,这里要先建好这个文件,否则会报rm权限错误 vim /tmp/localhost-mysql_cacti_stats.txt:3317 chown -R zabbix.zabbix /tmp/$HOST-mysql_cacti_stats.txt:3317
#2,修改端口脚本 vim /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt " 换成: CACHEFILE="/tmp/$HOST-mysql_zabbix_stats.txt:3317"
TIMEFLM=`stat -c %Y /tmp/$HOST-mysql_cacti_stats.txt` 换成: TIMEFLM=`stat -c %Y /tmp/$HOST-mysql_zabbix_stats.txt:3317`
#3,修改mysql执行命令路径 #RES=`HOME=~zabbix mysql -e 'SHOW SLAVE STATUSG' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr 'n' ','` 换成: RES=`/usr/local/mysql/bin/mysql -e 'SHOW SLAVE STATUSG' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr 'n' ','`
|
修改vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php脚本,这里主要修改用户名密码:
# 修改用户名密码 vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php $mysql_user = 'zabbixmoniter'; $mysql_pass = 'ys_ipowerlong0418'; $mysql_port = 3306; |
6,登陆mysql创建监控要用的账号
GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT ON *.* TO 'zabbixmoniter'@'localhost'
IDENTIFIED BY "ys_iprlong0418";
mysql> GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT ON *.* TO 'zabbixmoniter'@'localhost' IDENTIFIED BY "ys_iprlong0418"; Query OK, 0 rows affected (0.06 sec)
mysql> |
7,测试下监控项
在客户端zabbix-agentd测试下:
[root@db_m2_slave2 ~]# /usr/bin/php -q/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host localhost --itemsgg
gg:13
[root@db_m2_slave2 ~]#
在服务器zabbix-server测试下:
[root@zabbix_serv_121_12 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.161.3.73-p10050 -k "MySQL.Threads-connected"
1
[root@zabbix_serv_121_12 ~]#
[root@zabbix_serv_121_12 ~]# /usr/local/zabbix/bin/zabbix_get -s 192.161.3.73-p10050 -k "MySQL.Handler-commit"
8777484
[root@zabbix_serv_121_12 ~]#
8,在zabbix管理界面添加perconamysql监控
在hosts里面的templates里面添加percona mysql 的连接,就可以加入percona mysql模版监控了,加完,会看到items增加到262个,graphs增加55个,如022.png所示:
9,然后去监控界面查看监控效果图
大概有40几个监控图,这里列出来平常经常会关注的3个图看看效果,虽然比不上cacti的多样性,不过也能暂时满足要求了:
比如InnoDBBuffer Pool,如021.png所示:
比如MySQLTransactions Handler,如023.png所示:
比如MySQLProcesslist,如024.png所示:
10,mysql从库监控slave配置
先在mysql slave的agent里面需要check下看是否生效:
[root@azure_orcl_dbm2_3_13 scripts]# sh /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh running-slave ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 0 [root@azure_orcl_dbm2_3_13 scripts]# |
所以需要配置下访问mysql的一些基本参数:
#在my.cnf配置用户名密码、sock路径 vim /usr/local/mysql/etc/my.cnf [mysql] user=zabbixmoniter password=ys_ipowerlong0418 socket=/usr/local/mysql/mysql.sock |
再check试试,就可以看到了:
[root@azure_orcl_dbm2_3_13 scripts]# sh /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh running-slave 1 [root@azure_orcl_dbm2_3_13 scripts]# |
最好在zabbix管理界面,进入Hosts的mysql从库里面,进入triggers选项栏下面会看到从percona模版加载进来的slave监控项“Slave isstopped on {HOST.NAME}”,过几分钟,就会看到slave监控生效了,如下图025.png所示:
转载:https://blog.csdn.net/mchdba/article/details/51447750
转载于:https://blog.51cto.com/xiaocao13140/2133526
最后
以上就是清秀夏天为你收集整理的zabbix3.0.2 使用percona mysql插件来监控mysql5.7的详细实现过程zabbix3.0.2 使用percona mysql插件来监控mysql5.7的详细实现过程的全部内容,希望文章能够帮你解决zabbix3.0.2 使用percona mysql插件来监控mysql5.7的详细实现过程zabbix3.0.2 使用percona mysql插件来监控mysql5.7的详细实现过程所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复