[root@shard0 templates]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.2 (Maipo)
wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-agent-3.2.7-1.el7.x86_64.rpm rpm -i zabbix-agent-3.2.7-1.el7.x86_64.rpm yum install php php-mysql [root@shard0 zabbix]# rpm -qa zabbix-agent php php-mysql php-5.4.16-42.el7.x86_64 php-mysql-5.4.16-42.el7.x86_64 zabbix-agent-3.2.7-1.el7.x86_64
wget https://www.percona.com/downloads/percona-monitoring-plugins/1.1.6/percona-zabbix-templates-1.1.6-1.noarch.rpm rpm -i percona-zabbix-templates-1.1.6-1.noarch.rpm #自动生成两个目录 scripts:脚本目录 templates:模板目录 [root@shard0 templates]# cd /var/lib/zabbix/percona [root@shard0 percona]# ll total 4 drwxr-xr-x. 2 root root 68 Mar 15 01:17 scripts drwxr-xr-x. 2 root root 4096 Mar 15 01:17 templates [root@shard0 percona]# ll scripts/ total 64 -rwxr-xr-x. 1 root root 1251 Jan 11 2016 get_mysql_stats_wrapper.sh -rwxr-xr-x. 1 root root 59640 Jan 11 2016 ss_get_mysql_stats.php [root@shard0 percona]# ll templates/ total 284 -rw-r--r--. 1 root root 18866 Jan 11 2016 userparameter_percona_mysql.conf -rw-r--r--. 1 root root 269258 Jan 11 2016 zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.6.xml
/var/lib/zabbix/percona/scripts/目录中,sh的脚本是监控获取MySQL状态的,php文件是配置链接数据库用户名密码的。php
/var/lib/zabbix/percona/templates/目录中,conf文件是要放在agent端/etc/zabbix/zabbix_agentd.d/下面的,XML文件是模版文件。mysql
my3306->GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT ON *.* TO 'zabbix'@'localhost' IDENTIFIED BY "123456"; my3306->flush privileges; Query OK, 0 rows affected (0.00 sec)
[root@shard0 scripts]# cd var/lib/zabbix/percona/scripts [root@shard0 scripts]# vim ss_get_mysql_stats.php
#1 这里要先建好这个文件,不然会报rm权限错误 vim /tmp/localhost-mysql_cacti_stats.txt chown -R zabbix.zabbix /tmp/$HOST-mysql_cacti_stats.txt #2 若是MySQL端口非3306,则要修改端口脚本,如下为3317为例 vim /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt " 换成: CACHEFILE="/tmp/$HOST-mysql_zabbix_stats.txt:3317" TIMEFLM=`stat -c %Y /tmp/$HOST-mysql_cacti_stats.txt` 换成: TIMEFLM=`stat -c %Y /tmp/$HOST-mysql_zabbix_stats.txt:3317 #3 修改mysql执行命令路径,修改成对应MySQL命令的位置,本例的位置为 /u01/MySQL5.7/bin #RES=`HOME=~zabbix mysql -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','` 换成: RES=`/u01/MySQL5.7/bin -u root -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
上面的步骤6中 若是 mysql -uroot 把密码带上 : /u01/MySQL5.7/bin -u root -pxxxx -e 'SHOW SLAVE STATUS\G' 会出现附加提示,Warning: Using a password on the command line interface can be insecure. 此时zabbix会提示获取数据格式错误! #解决方案: vim /etc/my.cnf [mysql] user=your_backup_user_name password=your_backup_password
cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
[root@shard0 zabbix]# cd /etc/zabbix/ [root@shard0 zabbix]# vi zabbix_agentd.conf Server=172.253.32.79 ServerActive=172.253.32.79 Hostname=DESKTOP-4O8JRR9 参数说明: Server: zabbix server的ip地址, ServerActive: zabbix 主动监控server的ip地址, 其中Server和ServerActive都指定zabbix Server的IP地址,不一样的是,前者是被动后者是主动。也就是说Server这个配置是用来容许 172.253.32.79这个ip来我这取数据。而ServerActive的172.253.32.79的意思是,客户端主动提交数据给他。 Hostname 主机名,必须惟一,区分大小写。Hostname必须和zabbix web上配置的一直,不然zabbix主动监控没法正常工做。 由于agent拿着这个主机名去问server,我有配置主动监控项吗?server拿着这个主机名去配置里面查询,而后返回信息。 zabbix agent检测分为主动(agent active)和被动(agent)两种形式,主动与被动的说法均是相对于agent来讨论的。 主动:agent请求server获取主动的监控项列表,并主动将监控项内须要检测的数据提交给server/proxy 被动:server向agent请求获取监控项的数据,agent返回数据。
[root@shard0 zabbix]# systemctl restart zabbix-agent
wget https://www.percona.com/downloads/percona-monitoring-plugins/1.1.6/percona-monitoring-plugins-1.1.6.tar.gz
解决办法: 将zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml导入zabbix2.4中再导出。以后将新的导出xml导入 到3.2中问题解决。 我将修改好的模版文件share下,地址是:https://download.csdn.net/download/chinesern/10472518
#解决方法 vi /etc/selinux/config文件 #SELINUX=enforcing 注释掉 添加SELINUX=disabled SELINUXTYPE=targeted 注释掉 #使配置当即生效 setenforce 0