Press "Enter" to skip to content

Zabbix通过percona监控MySQL/MariaDB

主机环境:
[root@test ~]# uname -a
Linux test 3.10.0-693.el7.x86_64 #1 SMP Thu Jul 6 19:56:57 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@test ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.4 (Maipo)
[root@test ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.139.132 netmask 255.255.255.0 broadcast 192.168.139.255
ether 00:0c:29:ca:b7:70 txqueuelen 1000 (Ethernet)
RX packets 356 bytes 41989 (41.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 224 bytes 41057 (40.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Zabbix版本:3.4.9
mysql版本:
[root@test ~]# mysql -V
mysql Ver 15.1 Distrib 5.5.56-MariaDB, for Linux (x86_64) using readline 5.1
主机防火墙和selinux关闭
Zabbix yum安装参考:https://www.tracymc.cn/archives/614,编译安装可参考https://www.tracymc.cn/archives/218.
msyql/mariadb安装:https://www.tracymc.cn/archives/614,https://www.tracymc.cn/archives/218
利用Zabbix自带模板监控Mysql:https://www.tracymc.cn/archives/460
percona官网:www.percona.com
安装文档:https://www.percona.com/doc/percona-monitoring-plugins/LATEST/zabbix/index.html
环境要求:
msyql主机需要安装Zabbix agent,php,php-mysql

具体步骤:
1.下载相关组件
[root@test ~]# yum install -y https://www.percona.com/redir/downloads/percona-release/redhat/latest/percona-release-0.1-6.noarch.rpm
[root@test ~]# yum install percona-zabbix-templates php php-mysql -y //安装依赖包
[root@test ~]# rpm -ql percona-zabbix-templates
/var/lib/zabbix/percona
/var/lib/zabbix/percona/scripts
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh //shell脚本
/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php //php获取mysql信息
/var/lib/zabbix/percona/templates
/var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf //zabbix配置文件
/var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml //zabbix模板文件

2.设置键值
[root@test ~]# cat /etc/zabbix/zabbix_agentd.conf |grep conf|grep -v ‘#’ //yum安装zabbix的话agent默认配置文件为/etc/zabbix/zabbix_agentd.conf
Include=/etc/zabbix/zabbix_agentd.d/*.conf //你懂的,包含/etc/zabbix/zabbix_agentd.d下面的配置
[root@test ~]# cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d
[root@test ~]# ll /etc/zabbix/zabbix_agentd.d/userparameter_percona_mysql.conf
-rw-r--r-- 1 root root 18866 6月 15 10:57 /etc/zabbix/zabbix_agentd.d/userparameter_percona_mysql.conf
创建配置文件/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf,内容如下:
<?php
$mysql_user = 'root';
$mysql_pass = '123456';
编辑ss_get_mysql_stats.php文件,修改具体的用户名、密码、socket、Mysql端口等参数,只修改如下内容:
$mysql_user = 'root'; //与/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf相同
$mysql_pass = '123456'; //与/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf相同
$mysql_port = 3306;
$mysql_socket = "/var/lib/mysql/mysql.sock"; //根据实际情况填写,一定要加双引号,不然会报错,这个sock具体路径可以看mysql的配置文件或者ps -ef|grep mysql查看
[root@test tmp]# chown zabbix:zabbix /tmp/localhost-mysql_cacti_stats.txt   //这步一定要做,不然可能获取不到数据,默认情况下zabbix会在这个文件中获取值
[root@test ~]# systemctl restart zabbix-agent //重启agent
测试脚本是否能获取到值:
[root@test scripts]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
0

3.导入模板
自带的模板导入会有报错,报错如下:
修改后模板如下:zbx_percona_mysql_template;Percona-MySQL-Server-Template
上面两个模板都可以,随便选哪个.
导入下载模板,如下:
导入成功后可以在配置-模板查看已导入的模板,如下:

4.关联模板
添加模板:
配置-主机点击相关主机进去配置模板,如下:

5.zabbix web验证是否有数据
关联模板后,稍等一会,查看web页面是否有数据.
部分截图如下:

监控项还是很多的,有需要的可以自行安装测试.

Be First to Comment

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注