系統版本: centos6 x86_64php
mysql版本: mysql5.6mysql
實施目的: 監控mysqlsql
客戶端配置:centos
一、準備工做:搭建zabbix服務,使服務端客戶端鏈接成功,並有基礎監控項bash
二、使用percona監控服務,由於percona是監控項更全面,本來支持cacti 目前支持zabbix服務器
yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm -y #安裝percona源(agent安裝) yum install percona-zabbix-templates php php-mysql #安裝監控腳本,由於要調用php發送給服務器端因此需安裝php組件(agent安裝)
三、複製配置文件到agent配置目錄app
[root@fmysql1 ~]# 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.8.xml [root@fmysql1 ~]# cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
四、進入mysql配置zabbix專用監控帳戶socket
mysql> GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT ON *.* TO 'zabbix'@'localhost' IDENTIFIED BY "wxgdwxwx2323";
五、配置mysql登陸測試
[root@bmysql1 ~]# cat /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf <?php $mysql_user = 'zabbix'; $mysql_pass = 'wxgdwxwx2323';
$mysql_port = 3306;
#後期發現監控沒法取值緣由.cnf文件沒有加入執行權限
[root@bmysql2 dev]# cd /var/lib/zabbix/percona/script
[root@bmysql2 scripts]# chmod +x ss_get_mysql_stats.php.cnf
[root@bmysql2 scripts]# ll
total 68
-rwxr-xr-x 1 root root 1251 Jan 10 2018 get_mysql_stats_wrapper.sh
-rwxr-xr-x 1 root root 60681 Jan 25 11:32 ss_get_mysql_stats.php
-rwxr-xr-x 1 root root 60 Jan 25 14:22 ss_get_mysql_stats.php.cnfspa
六、測試
[root@fmysql1 ~]# /etc/init.d/zabbix-agent restart Shutting down Zabbix agent: [ OK ] Starting Zabbix agent: [ OK ] #重啓服務 [root@fmysql1 ~]# cd /var/lib/zabbix/percona/scripts/ [root@fmysql1 scripts]# /usr/bin/php -q ./ss_get_mysql_stats.php --host 'localhost' --items gg ERROR: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)[root@fmysql1 scripts]# #提示獲取不到沒法鏈接sock接口文件,多是由於本身編譯安裝sock文件在其它目錄,直接找到現有sock軟連接到這個報錯目錄下就行了 [root@fmysql1 scripts]# mkdir /var/lib/mysql/ [root@fmysql1 scripts]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock [root@fmysql1 scripts]# /usr/bin/php -q ./ss_get_mysql_stats.php --host 'localhost' --items gg gg:157611224525[root@fmysql1 scripts]# #取值成功!客戶端配置OVER
zabbix_get -s 172.18.10.120 -p 10050 -k "MySQL.Handler-commit"
#服務端測試
服務端配置: