因为Zabbix自带的MySQL监控没有提供可以直接使用的Key,所以一般不采用,业界的同学们都使用Percona Monitoring Plugins 监控 MySQL的方式
Percona介绍
Percona 为 MySQL 数据库服务器进行了改进,在功能和性能上较 MySQL有着很显著的提升。该版本提升了在高负载情况下的 InnoDB 的性能、为 DBA 提供一些非常有用的性能诊断工具;另外有更多的参数和命令来控制服务器行为。
系统需要安装有zabbix-server、zabbix-agent、php、php-mysql
安装percona-zabbix-templates
[root@localhost ~]# rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm
warning: percona-zabbix-templates-1.1.8-1.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:percona-zabbix-templates-1.1.8-1 ################################# [100%]
Scripts are installed to /var/lib/zabbix/percona/scripts
Templates are installed to /var/lib/zabbix/percona/templates ##这是percona脚本存放位置
[root@localhost ~]# cd /var/lib/zabbix/percona/scripts/ ###脚本存放目录
[root@localhost scripts]# ls
get_mysql_stats_wrapper.sh ss_get_mysql_stats.php
[root@localhost scripts]# cd ..
[root@localhost percona]# ls
scripts templates
[root@localhost percona]# cd templates/ ##配置文件存放目录
root@localhost templates]# ls
userparameter_percona_mysql.conf zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml
[root@localhost templates]# cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/ ##将配置文件移到/etc/zabbix_agentde.d/目录下
root@localhost templates]# cd /etc/zabbix/zabbix_agentd.d/
[root@localhost zabbix_agentd.d]# ls
userparameter_mysql.conf userparameter_percona_mysql.conf
[root@localhost zabbix_agentd.d]# vim userparameter_percona_mysql.conf
[root@localhost zabbix_agentd.d]# systemctl restart zabbix-agent ##刷新使配置文件生效
添加脚本
root@localhost zabbix_agentd.d]# cd /var/lib/zabbix/percona/scripts/
[root@localhost scripts]# ls
get_mysql_stats_wrapper.sh ss_get_mysql_stats.php
[root@localhost scripts]# vim ss_get_mysql_stats.php.cnf ##添加新的一个脚本是加入用户和密码
[root@localhost scripts]# cat ss_get_mysql_stats.php.cnf
<?php
$mysql_user = 'root';
$mysql_pass = 'westos';
测试:
[root@localhost scripts]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
4
[root@localhost scripts]# cd /tmp/
[root@localhost tmp]# ls
ks-script-tq4eM5
localhost-mysql_cacti_stats.txt
systemd-private-6c60cb684ac04181bcaa6be0476a33c9-httpd.service-vYPseh
systemd-private-6c60cb684ac04181bcaa6be0476a33c9-mariadb.service-yBYHhs
systemd-private-86b28035559b4eee86f493ea932d93c0-httpd.service-9ikUzH
systemd-private-86b28035559b4eee86f493ea932d93c0-mariadb.service-H1PsU7
yum.log
[root@localhost tmp]# cat localhost-mysql_cacti_stats.txt |grep gg
[root@localhost tmp]# rm -fr localhost-mysql_cacti_stats.txt ##因为超级用户可写,所以删除
[root@localhost tmp]# cd /etc/zabbix/
[root@localhost zabbix]# ls
web zabbix_agentd.conf zabbix_agentd.d zabbix_server.conf
[root@localhost zabbix]# cd zabbix_agentd.d/
[root@localhost zabbix_agentd.d]# ls
userparameter_mysql.conf userparameter_percona_mysql.conf
[root@localhost zabbix_agentd.d]# vim userparameter_percona_mysql.conf
[root@localhost zabbix_agentd.d]# zabbix_get -s 127.0.0.1 -p 10050 -k 'MySQL.State-updating' ##测试是否可以弄出来
0
下载模块
zbx_percona_mysql_template.xml
在浏览器中导入模块:
可以看出监控项变多了,模块添加成功。