通过使用mysql_performance_monitor软件包实现zabbix对mysql的监控。
1.安装依赖软件。
yum install perl-File-Which perl-libwww-perl perl-Digest-SHA perl-DBD-MySQL perl-Time-HiRes perl-Crypt-SSLeay php php-mysql
2.下载mysql_performance_monitor软件包。
wget -c http://www.shinguz.ch/download/mysql_performance_monitor-latest.tar.gz
tar xf mysql_performance_monitor-latest.tar.gz
3.安装percona-monitor-templates软件包。
[root@DB ~]# rpm -ihv https://www.percona.com/downloads/percona-monitoring-plugins/1.1.5/percona-zabbix-templates-1.1.5-1.noarch.rpm
Retrieving https://www.percona.com/downloads/percona-monitoring-plugins/1.1.5/percona-zabbix-templates-1.1.5-1.noarch.rpm
warning: /var/tmp/rpm-tmp.P8evAy: 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
4.查看percona-zabbix-templates软件包生成目录文件位置。
[root@DB ~]# rpm -ql percona-zabbix-templates
/var/lib/zabbix/percona
/var/lib/zabbix/percona/scripts
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
/var/lib/zabbix/percona/templates
/var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf
/var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.5.xml
5.拷贝配置文件userparameter_percona_mysql.conf到zabbix配置文件目录下。
[root@DB ~]# cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
6.重新启动zabbix-agent服务。
[root@DB ~]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent: [ OK ]
Starting Zabbix agent: [ OK ]
7.修改连接数据库的用户名和密码
[root@DB ~]# grep -A 1 root /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'user_name';
$mysql_pass = 'password';
8.测试。
[root@DB ~]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
2
如果没有数据,请执行如下操作,查看/etc/php.ini中MySQL的sock配置文件位置是否正确。
/usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mystats.php --host localhost --items gg
通过报错信息排查错误。
来源:https://www.cnblogs.com/xkops/p/5606557.html