Zabbix通过percona监控Mysql

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Hannah_zh/article/details/83863191

1、安装percona-zabbix-templates

[root@server11 ~]# rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm 

2、配置zabbix agent

[root@server11 scripts]# cd /var/lib/zabbix/percona/templates/
[root@server11 templates]# ls
userparameter_percona_mysql.conf
zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml
[root@server11 templates]# cp userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/

3、zabbix agent配置mysql连接

[root@server11 ~]# cd /var/lib/zabbix/percona/scripts/
[root@server11 scripts]# ls   ##sh的脚本是监控获取MySQL状态的,php文件是配置连接数据库用户名密码的
get_mysql_stats_wrapper.sh  ss_get_mysql_stats.php
[root@server11 scripts]# vim ss_get_mysql_stats.php.cnf  ##创建 .cnf 文件指定Mysql用户名和密码
<?php
$mysql_user = 'root';
$mysql_pass = 'westos';
[root@server11 scripts]# ls
get_mysql_stats_wrapper.sh  ss_get_mysql_stats.php  ss_get_mysql_stats.php.cnf
[root@server11 templates]# systemctl restart zabbix-agent

4、测试脚本

注意:测试完必须删除/tmp/localhost-mysql_cacti_stats.txt , 否则会因为权限问题报错(root、zabbix)
[root@server11 ~]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg    ##验证,返回数字
0
[root@server11 ~]# cd /tmp/
[root@server11 tmp]# rm -fr localhost-mysql_cacti_stats.txt 

5、配置Mysql slave监控

  • 配置访问mysql的基本参数:
[root@server11 tmp]# cd /var/lib/zabbix/
[root@server11 zabbix]# vim .my.cnf 
[mysql]
host=localhost
user=zabbix
password=westos
socket=/var/lib/mysql/mysql.sock

[mysqladmin]
host=localhost
user=zabbix
password=westos
socket=/var/lib/mysql/mysql.sock

[client]
user=root
password=westos
  • 在mysql slave的agent里面需要check下看是否生效:
[root@server11 zabbix]# sudo -u zabbix -H /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh running-slave
0
[root@server11 zabbix]# ls /tmp/       ##确保无".txt"文件
systemd-private-c1ddf0ad51564235bd754efafcac49bd-httpd.service-tCBDey
systemd-private-c1ddf0ad51564235bd754efafcac49bd-mariadb.service-jcGip9
[root@server11 zabbix]# systemctl restart zabbix-agent

7、导入模板(配置—>模板—>导入)

  • 选择模板并导入
    在这里插入图片描述在这里插入图片描述
  • 成功导入模板
    在这里插入图片描述
  • 添加模板
    在这里插入图片描述在这里插入图片描述在这里插入图片描述
  • 查看模板(191项监控项)
    在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Hannah_zh/article/details/83863191