标签:soc nmp mis system https 基本 加载 query 模版
因为Zabbix自带的MySQL监控没有提供可以直接使用的Key,所以一般不采用,业界的同学们都使用Percona Monitoring Plugins 监控 MySQL的方式
[root@linux-node1 ~]# yum install zabbix-agent php php-mysql
[root@linux-node1 ~]# rpm -qa zabbix-agent php php-mysql
php-mysql-5.4.16-36.1.el7_2.1.x86_64
php-5.4.16-36.1.el7_2.1.x86_64
zabbix-agent-3.0.3-1.el7.x86_64
# 安装 percona-zabbix-templates
yum install https://www.percona.com/downloads/percona-monitoring-plugins/1.1.6/percona-zabbix-templates-1.1.6-1.noarch.rpm
# 也可配置 Percona yum 仓库后安装
[root@linux-node1 ~]# yum install https://www.percona.com/redir/downloads/percona-release/redhat/latest/percona-release-0.1-3.noarch.rpm
# 配置 Zabbix Agent
[root@linux-node1 ~]# cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
# 启动zabbix-agent
[root@linux-node1 ~]# systemctl restart zabbix-agent
[root@linux-node1 ~]# ls /var/lib/zabbix/percona/
scripts templates
[root@linux-node1 ~]# ls /var/lib/zabbix/percona/scripts/
get_mysql_stats_wrapper.sh ss_get_mysql_stats.php
[root@linux-node1 ~]# ls /var/lib/zabbix/percona/templates/
userparameter_percona_mysql.conf zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.5.xml
# 创建 .cnf 文件指定 MySQL 用户名和密码
# 生产环境请一定要设置复杂密码
[root@linux-node1 ~]# cat /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf
<?php
$mysql_user =‘zabbixmoniter‘;
$mysql_pass =‘123456‘;
# 测试脚本
[root@linux-node1 ~]#/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
[root@linux-node1 ~]# sh /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh running-slave
ERROR 1045(28000):Access denied for user ‘root‘@‘localhost‘(using password: NO)
0
#在my.cnf配置用户名密码、sock路径
[root@linux-node1 ~]# vim /usr/local/mysql/etc/my.cnf
[mysql]
user=zabbixmoniter
password=123456
socket=/usr/local/mysql/mysql.sock
Invalid tag “/zabbix_export/date”:“YYYY-MM-DDThh:mm:ssZ” is expected.
Invalid tag “/zabbix_export/templates/template(1)/items/item(1)”: the tag “snmp_community” is missing.
# zabbix_get 能获取数据,但是不出图。
[root@linux-node1 ~]# zabbix_get -s 192.168.56.11-k "MySQL.max-connections"
151
# 查看状态文件权限,为之前测试脚本时的 root 权限,zabbix 用户并不能读写,所以获取不到数据
[root@linux-node1 ~]# ll /tmp/localhost-mysql_cacti_stats.txt
-rw-r--r--1 root root 1374Jun2211:33/tmp/localhost-mysql_cacti_stats.txt
# 删除 root 用户测试时生成的 mysql 状态文件
[root@linux-node1 ~]# rm -f /tmp/localhost-mysql_cacti_stats.txt
# 会自动生成 zabbix用户权限的 mysql 状态文件
[root@linux-node1 ~]# ll /tmp/localhost-mysql_cacti_stats.txt
-rw-rw-r--1 zabbix zabbix 1374Jun2211:41/tmp/localhost-mysql_cacti_stats.txt
# 过一会儿就可以看到出图了
mysql> GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT ON *.* TO ‘zabbixmoniter‘@‘localhost‘ IDENTIFIED BY "123456";
Query OK,0 rows affected (0.06 sec)
标签:soc nmp mis system https 基本 加载 query 模版
原文地址:http://www.cnblogs.com/gaoyuechen/p/7868682.html