189 8069 5689

Zabbix中使用PerconaMonitoringPlugins监控MySQL

Zabbix 中使用 Percona Monitoring Plugins 监控 MySQL

为京山等地区用户提供了全套网页设计制作服务,及京山网站建设行业解决方案。主营业务为做网站、成都网站制作、京山网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

 

1.安装zabbix agent

[root@szlinux01 ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-agent-3.2.0-1.el7.x86_64.rpm
[root@szlinux01 ~]# yum install zabbix-agent

 

2.修改配置

[root@szlinux01 ~]# vim /etc/zabbix/zabbix_agentd.conf

Server=192.168.137.3

ServerActive=192.168.137.3

Hostname=szlinux01

 

3.启动代理

[root@szlinux01 ~]# systemctl enable zabbix-agent
[root@szlinux01 ~]# systemctl start zabbix-agent
[root@szlinux01 ~]# netstat -tunpl | grep 10050

 

4.在服务端测试数据获取

[root@szzabbix ~]# zabbix_get -s 192.168.137.3 -p 10050 -k system.uptime

 

5.安装php和php-mysql

[root@szlinux01 ~]# yum install epel-release
[root@szlinux01 ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[root@szlinux01 ~]# yum install php php-mysql
[root@szlinux01 ~]# rpm -qa zabbix-agent php php-mysql

 

6.安装配置percona-zabbix-templates

[root@szlinux01 ~]# yum install 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
[root@szlinux01 ~]# cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
[root@szlinux01 ~]# systemctl restart zabbix-agent

 

7.首先在被监控服务器szlinux01的mysql里添加权限,即本机使用zabbix账号连接本地的mysql

mysql> grant usage, process, replication client on *.* to 'zabbix'@'localhost' identified by 'ABCabc!@#123';
mysql> flush privileges;

 

8.修改php文件的mysql用户名和密码

[root@szlinux01 ~]# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php

$mysql_user = 'zabbix';

$mysql_pass = 'ABCabc!@#123';

 

9.测试脚本

[root@szlinux01 ~]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg

 

10.配置~zabbix/.my.cnf

[root@szlinux01 ~]# vim ~zabbix/.my.cnf

[client]

user = zabbix

password = 'ABCabc!@#123'

注意:复杂密码需要引号。

 

11.zabbix用户测试脚本

[root@szlinux01 ~]# sudo -u zabbix -H /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh running-slave

 

12.导入模板

将被监控服务器szlinux01上的/var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml下载到本地,通过Zabbix页面导入到模板里。

配置->模板->导入

Zabbix 中使用 Percona Monitoring Plugins 监控 MySQL

 

报错:

Zabbix 中使用 Percona Monitoring Plugins 监控 MySQL

解决方法:

手动修改模板文件解决报错比较麻烦,有人提到可以将此模板导入 Zabbix 2.X 系列后,再导出到 Zabbix 3.X。

这里直接使用现成可用的 Zabbix 3.X 的 percona-zabbix-templates

zbx_percona_mysql_template.xml模板地址

 

Zabbix 中使用 Percona Monitoring Plugins 监控 MySQL

 

13.添加主机并链接模板

Zabbix 中使用 Percona Monitoring Plugins 监控 MySQL

 

发现没有最新的数据。于是,测试数据获取:

[root@szzabbix ~]# zabbix_get -s 192.168.137.3 -p 10050 -k "MySQL.max-connections"

 

报错:

rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted

解决方法:

在被监控服务器szlinux01上面执行如下操作即可

[root@szlinux01 ~]# rm -rf /tmp/localhost-mysql_cacti_stats.txt
[root@szlinux01 ~]# touch /tmp/localhost-mysql_cacti_stats.txt
[root@szlinux01 ~]# chown -R zabbix:zabbix /tmp/localhost-mysql_cacti_stats.txt

 再在zabbix上测试获取数据:

[root@szzabbix ~]# zabbix_get -s 192.168.137.3 -p 10050 -k "MySQL.max-connections"
[root@szzabbix ~]# zabbix_get -s 192.168.137.3 -p 10050 -k "MySQL.Threads-connected"
[root@szzabbix ~]# zabbix_get -s 192.168.137.3 -p 10050 -k "MySQL.running-slave"

数据也有了,过一会,就可以看到有图了。


网站题目:Zabbix中使用PerconaMonitoringPlugins监控MySQL
网站地址:http://cdxtjz.cn/article/pijhch.html

其他资讯