官方地址:https://www.percona.com/software/mysql-database/percona-server
在官网找到下载页面:
percona模板需要php环境,因此,需要安装:
[root@DB2 ~]#yum -y install php php-mysql
下载安装percona:
[root@DB2 ~]# rpm -ivh https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.7/binary/redhat/7/x86_64/percona-zabbix-templates-1.1.7-2.noarch.rpm Retrievinghttps://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.7/binary/redhat/7/x86_64/percona-zabbix-templates-1.1.7-2.noarch.rpm warning:/var/tmp/rpm-tmp.0ad5dL: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY Preparing... ################################# [100%] Updating /installing... 1:percona-zabbix-templates-1.1.7-2################################# [100%] Scripts areinstalled to /var/lib/zabbix/percona/scripts Templates areinstalled to /var/lib/zabbix/percona/templates
查看percona安装后的细节:
[root@DB2 ~]#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.7.xml
复制percona配置文件到zabbix agent目录:
[root@DB2 ~]# cd /var/lib/zabbix/percona/scripts/ [root@DB2scripts]# ll total 64 -rwxr-xr-x 1root root 1251 Dec 10 2016 get_mysql_stats_wrapper.sh -rwxr-xr-x 1root root 59976 Dec 10 2016ss_get_mysql_stats.php [root@DB2scripts]# cd .. [root@DB2percona]# ll total 8 drwxr-xr-x 2root root 4096 Nov 13 14:33 scripts drwxr-xr-x 2root root 4096 Nov 13 14:33 templates [root@DB2percona]# cd templates/ [root@DB2templates]# ll total 284 -rw-r--r-- 1root root 18866 Dec 10 2016 userparameter_percona_mysql.conf -rw-r--r-- 1root root 269258 Dec 10 2016zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml [root@DB2templates]# pwd /var/lib/zabbix/percona/templates [root@DB2templates]# cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
备份配置文件:
[root@DB2scripts]# cp get_mysql_stats_wrapper.sh get_mysql_stats_wrapper.sh.ori.20171114
修改配置文件get_mysql_stats_wrapper.sh后,再执行出现下面的报错。这是好的转机,修改bash脚本前,执行此命令没有任何输出。
在zabbix agent的percona配置文件,找到获取监控值的参数脚本:
[root@DB2scripts]# more /etc/zabbix/zabbix_agentd.d/userparameter_percona_mysql.conf|grep MySQL.Threads-connected UserParameter=MySQL.Threads-connected,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh iu [root@DB2scripts]# ./get_mysql_stats_wrapper.sh gg ERROR: run thecommand manually to investigate the problem: /usr/bin/php -q./ss_get_mysql_stats.php --host 10.253.40.67 --items gg [root@DB2scripts]# sh /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh kt ERROR: run thecommand manually to investigate the problem: /usr/bin/php -q/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host localhost --itemsgg
根据网上的办法执行命令:执行配置文件里面的脚本,发现报错信息和上面的一样。
参考文档:http://blog.csdn.net/mchdba/article/details/51447560——zabbix3.0.2使用percona的mysql插件的遇到的诡异问题解决记录
登录数据库,查看当前的用户:
mysql> select user,host from mysql.user; +------------------+--------------+ | user | host | +------------------+--------------+ | amq | 10.253.% | | anzhengtong_user | 10.253.% | | crm | 10.253.% | | dzqz_user | 10.253.% | | rep | 10.253.40.% | | yqd_pro_user | 10.253.40.% | | jump_machine | 10.253.40.64 | | jump_machine | 10.253.41.91 | | yqd_onlys | 10.253.41.91 | | yqd_pro_user | 10.253.43.% | | root | localhost | +------------------+--------------+ 11 rows in set (0.02 sec)
创建用于zabbix的数据库用户并授权:
mysql> grant process,super,select on *.* to zabbix@'localhost' identified by 'zabbix'; Query OK, 0 rowsaffected (0.02 sec) mysql> flushprivileges; Query OK, 0 rowsaffected (0.07 sec) mysql> exit Bye
把配置文件里的数据库用户替换成刚创建的,之前使用的是数据库root用户:
[root@DB2 ~]#cat /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf重启zabbix agent:
[root@DB2scripts]# ps -ef|grep zabbix zabbix 16822 1 0 16:05 ? 00:00:00 zabbix_agentd -c/etc/zabbix/zabbix_agentd.conf zabbix 16823 16822 0 16:05 ? 00:00:00zabbix_agentd: collector [idle 1 sec] zabbix 16824 16822 0 16:05 ? 00:00:00zabbix_agentd: listener #1 [waiting for connection] zabbix 16825 16822 0 16:05 ? 00:00:00zabbix_agentd: listener #2 [waiting for connection] zabbix 16826 16822 0 16:05 ? 00:00:00zabbix_agentd: listener #3 [waiting for connection] zabbix 16827 16822 0 16:05 ? 00:00:00zabbix_agentd: active checks #1 [idle 1 sec] root 17925 20105 0 16:17 pts/0 00:00:00 grep --color=auto zabbix [root@DB2scripts]# pkill -f /etc/zabbix/zabbix_agentd.conf [root@DB2scripts]# ps -ef|grep zabbix root 17932 20105 0 16:17 pts/0 00:00:00 grep --color=auto zabbix [root@DB2scripts]# zabbix_agentd -c/etc/zabbix/zabbix_agentd.conf [root@DB2scripts]# ps -ef|grep zabbix zabbix 17936 1 0 16:17 ? 00:00:00 zabbix_agentd -c/etc/zabbix/zabbix_agentd.conf zabbix 17937 17936 0 16:17 ? 00:00:00zabbix_agentd: collector [idle 1 sec] zabbix 17938 17936 0 16:17 ? 00:00:00zabbix_agentd: listener #1 [waiting for connection] zabbix 17939 17936 0 16:17 ? 00:00:00zabbix_agentd: listener #2 [waiting for connection] zabbix 17940 17936 0 16:17 ? 00:00:00zabbix_agentd: listener #3 [waiting for connection] zabbix 17941 17936 0 16:17 ? 00:00:00zabbix_agentd: active checks #1 [idle 1 sec] root 17943 20105 0 16:18 pts/0 00:00:00 grep --color=auto zabbix出现的报错发生变化:
[root@DB2scripts]# ./get_mysql_stats_wrapper.sh gg ERROR: run thecommand manually to investigate the problem: /usr/bin/php -q./ss_get_mysql_stats.php --host localhost --items gg执行报错信息提供的命令:
[root@DB2scripts]# /usr/bin/php -q ./ss_get_mysql_stats.php --host localhost --items gg ERROR: Can't connect tolocal MySQL server through socket '/var/lib/mysql/mysql.sock' (2)找到/mysql.sock的文件路径:
[root@DB2scripts]# ps -ef|grep mysql mysql 1107 23209 25 Nov01 ? 3-07:55:38 /usr/local/mysql/bin/mysqld--basedir=/usr/local/mysql --datadir=/mysql/data/--plugin-dir=/usr/local/mysql/lib/mysql/plugin --user=mysql--log-error=/mysql/data/mysql-error.log --open-files-limit=65535--pid-file=/mysql/data/mysql.pid --socket=/mysql/data/mysql.sock root 17989 20105 0 16:21 pts/0 00:00:00 grep --color=auto mysql root 23209 1 0 2016 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/mysql/data/--pid-file=/mysql/data/mysql.pid创建软链接:
[root@DB2scripts]# mkdir -p /var/lib/mysql [root@DB2scripts]# ln -s /mysql/data/mysql.sock /var/lib/mysql/mysql.sock这样执行是成功的:
[root@DB2scripts]# /usr/bin/php -q./ss_get_mysql_stats.php --host localhost --items gg gg:955693623参考文档:https://www.cnblogs.com/ivictor/p/5803415.html——如何在Zabbix上安装MySQL监控插件PMP
但是,这样还是报错:
[root@DB2scripts]# ./get_mysql_stats_wrapper.sh gg ERROR: run thecommand manually to investigate the problem: /usr/bin/php -q./ss_get_mysql_stats.php --host localhost --items gg确认mysql命令的路径:
[root@DB2scripts]# which mysql /usr/local/mysql/bin/mysql手动创建文件并授权:
[root@DB2scripts]# touch /tmp/localhost-mysql_zabbix_stats.txt [root@DB2scripts]# chown -R zabbix:zabbix /tmp/localhost-mysql_zabbix_stats.txt过了一段时间,执行成功:
[root@DB2scripts]# ./get_mysql_stats_wrapper.sh gg 958675246 [root@DB2scripts]# ./get_mysql_stats_wrapper.sh gw 3186887 [root@DB2 scripts]#pwd /var/lib/zabbix/percona/scripts最后修改的脚本:不使用msyql的全路径好像也能使用
[root@DB2 ~]#cat /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh #!/bin/sh # The wrapperfor Cacti PHP script. # It runs thescript every 5 min. and parses the cache file on each following run. # Version: 1.1.7 # # This programis part of Percona Monitoring Plugins # License: GPLLicense (see COPYING) # Copyright:2016 Percona # Authors: RomanVynar ITEM=$1 HOST=localhost DIR=`dirname $0` CMD="/usr/bin/php-q $DIR/ss_get_mysql_stats.php --host $HOST --items gg" CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt" if ["$ITEM" = "running-slave" ]; then # Check for running slave RES=`/usr/local/mysql/bin/mysql -e 'SHOW SLAVESTATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print$2}' | tr '\n' ','` if [ "$RES" = " Yes,Yes," ]; then echo 1 else echo 0 fi exit elif [ -e$CACHEFILE ]; then # Check and run the script TIMEFLM=`stat -c %Y/tmp/$HOST-mysql_cacti_stats.txt` TIMENOW=`date +%s` if [ `expr $TIMENOW - $TIMEFLM` -gt 300 ];then rm -f $CACHEFILE $CMD 2>&1 > /dev/null fi else $CMD 2>&1 > /dev/null fi # Parse cachefile if [ -e$CACHEFILE ]; then cat$CACHEFILE | sed 's/ /\n/g; s/-1/0/g'| grep $ITEM | awk -F: '{print $2}' else echo "ERROR: run the command manuallyto investigate the problem: $CMD" fi参考文档:http://blog.csdn.net/mchdba/article/details/51447750——zabbix3.0.2使用percona mysql插件来监控mysql5.7的详细实现过程
在zabbix服务端执行成功:
[root@iZ23ejm6lkdZ~]# zabbix_get -s 10.253.40.67 -k 'MySQL.pages-written' 3191043 [root@iZ23ejm6lkdZ~]# zabbix_get -s 10.253.40.67 -k 'MySQL.max-connections' 10000zabbix服务端出现报错:
[root@iZ23ejm6lkdZ~]# zabbix_get -s 10.253.40.67 -k 'MySQL.pages-written' rm: cannotremove ‘/tmp/localhost-mysql_cacti_stats.txt’: Operation not permitted 3191043/tmp目录无法自动创建文件,手动创建并授权:
[root@iZ23ejm6lkdZ~]# ll /tmp/ total 348560 drwxr-xr-x 2root root 4096 Nov 1 09:56 hsperfdata_root drwxr-xr-x 2tomcat tomcat 4096 Sep 12 15:58hsperfdata_tomcat -rw-r--r-- 1root root 537998919 Nov 14 17:39 iostat_output -rw-rw-r-- 1root root 1488 Nov 14 17:37localhost-mysql_cacti_stats.txt -rw-r--r-- 1zabbix zabbix 58 Nov 14 17:39 netstat.tmp drwxrwxrwx 2root root 4096 Oct 26 17:53 rmagent -rw-rw-r-- 1root root 409670 Nov 14 17:39zabbix_agentd.log -rw-rw-r-- 1root root 1048674 Nov 14 09:54zabbix_agentd.log.old -rw-rw-r-- 1root root 5 Nov 14 17:39 zabbix_agentd.pid [root@iZ23ejm6lkdZ~]# touch /tmp/localhost-mysql_cacti_stats.txt [root@iZ23ejm6lkdZ~]# chown -R zabbix:zabbix /tmp/localhost-mysql_cacti_stats.txt [root@iZ23ejm6lkdZ~]# zabbix_get -s 10.253.40.67 -k 'MySQL.pages-written' 3194382下面的命令,可以找到执行“./get_mysql_stats_wrapper.sh gg”命令时,最后参数所对应的zabbixkey值:
[root@DB2scripts]# cat /etc/zabbix/zabbix_agentd.d/userparameter_percona_mysql.conf|grep gw UserParameter=MySQL.pages-written,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.shgwWEB界面导入模板:
这部分内容这次忽略,下次再补充。
下图是模板导入成功后的画面:
汇总参考文档:
http://blog.csdn.net/mchdba/article/details/51447560——zabbix3.0.2使用percona的mysql插件的遇到的诡异问题解决记录
https://www.cnblogs.com/ivictor/p/5803415.html——如何在Zabbix上安装MySQL监控插件PMP
http://blog.csdn.net/mchdba/article/details/51447750——zabbix3.0.2使用percona mysql插件来监控mysql5.7的详细实现过程
https://www.abcdocker.com/abcdocker/1498——Zabbix 3.0 监控MySQL [六]