使用zabbix监控mysql
Posted taj-zhang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用zabbix监控mysql相关的知识,希望对你有一定的参考价值。
系统版本: centos6 x86_64
mysql版本: mysql5.6
实施目的: 监控mysql
客户端配置:
1、准备工作:搭建zabbix服务,使服务端客户端连接成功,并有基础监控项
2、使用percona监控服务,因为percona是监控项更全面,原本支持cacti 目前支持zabbix
yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm -y
#安装percona源(agent安装)
yum install percona-zabbix-templates php php-mysql
#安装监控脚本,因为要调用php发送给服务器端所以需安装php组件(agent安装)
3、复制配置文件到agent配置目录
[[email protected] ~]# rpm -ql percona-zabbix-templates /var/lib/zabbix/percona /var/lib/zabbix/percona/scripts /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php /var/lib/zabbix/percona/templates /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml [[email protected] ~]# cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
4、进入mysql配置zabbix专用监控账户
mysql> GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT ON *.* TO ‘zabbix‘@‘localhost‘ IDENTIFIED BY "wxgdwxwx2323";
5、配置mysql登录
[[email protected] ~]# cat /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf <?php $mysql_user = ‘zabbix‘; $mysql_pass = ‘wxgdwxwx2323‘;
$mysql_port = 3306;
#后期发现监控无法取值原因.cnf文件没有加入执行权限
[[email protected] dev]# cd /var/lib/zabbix/percona/script
[[email protected] scripts]# chmod +x ss_get_mysql_stats.php.cnf
[[email protected] scripts]# ll
total 68
-rwxr-xr-x 1 root root 1251 Jan 10 2018 get_mysql_stats_wrapper.sh
-rwxr-xr-x 1 root root 60681 Jan 25 11:32 ss_get_mysql_stats.php
-rwxr-xr-x 1 root root 60 Jan 25 14:22 ss_get_mysql_stats.php.cnf
6、测试
[[email protected] ~]# /etc/init.d/zabbix-agent restart Shutting down Zabbix agent: [ OK ] Starting Zabbix agent: [ OK ] #重启服务 [[email protected] ~]# cd /var/lib/zabbix/percona/scripts/ [[email protected] scripts]# /usr/bin/php -q ./ss_get_mysql_stats.php --host ‘localhost‘ --items gg ERROR: Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)[[email protected] scripts]# #提示获取不到无法连接sock接口文件,可能是因为自己编译安装sock文件在其它目录,直接找到现有sock软链接到这个报错目录下就好了 [[email protected] scripts]# mkdir /var/lib/mysql/ [[email protected] scripts]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock [[email protected] scripts]# /usr/bin/php -q ./ss_get_mysql_stats.php --host ‘localhost‘ --items gg gg:157611224525[[email protected] scripts]# #取值成功!客户端配置OVER
zabbix_get -s 172.18.10.120 -p 10050 -k "MySQL.Handler-commit"
#服务端测试
服务端配置:
以上是关于使用zabbix监控mysql的主要内容,如果未能解决你的问题,请参考以下文章
zabbix监控mysql-如何使用zabbix自带的模板监控-nagios监控mysql主从