經過使用mysql_performance_monitor軟件包實現zabbix對mysql的監控。php
1.安裝依賴軟件。
yum install perl-File-Which perl-libwww-perl perl-Digest-SHA perl-DBD-MySQL perl-Time-HiRes perl-Crypt-SSLeay php php-mysqlmysql
2.下載mysql_performance_monitor軟件包。
wget -c http://www.shinguz.ch/download/mysql_performance_monitor-latest.tar.gz
tar xf mysql_performance_monitor-latest.tar.gzsql
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/templatesapp
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/spa
6.從新啓動zabbix-agent服務。
[root@DB ~]# /etc/init.d/zabbix-agent restart
Shutting down Zabbix agent: [ OK ]
Starting Zabbix agent: [ OK ]rest
7.修改鏈接數據庫的用戶名和密碼
[root@DB ~]# grep -A 1 root /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'user_name';
$mysql_pass = 'password';orm
8.測試。
[root@DB ~]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
2server
若是沒有數據,請執行以下操做,查看/etc/php.ini中MySQL的sock配置文件位置是否正確。
/usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mystats.php --host localhost --items gg
經過報錯信息排查錯誤。