MySql教程

zabbix监控mysql

本文主要是介绍zabbix监控mysql,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

zabbix监控mysql

在被监控端,安装zabbix监控客户端

下载客户端

wget https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-agent-5.0.15-1.el7.x86_64.rpm

安装客户端

rpm -ivh zabbix-agent-5.0.15-1.el7.x86_64.rpm

修改配置

vim /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.31.158
ServerActive=192.168.1.31.158
Hostname=192-168-31-157
Include=/etc/zabbix/zabbix_agentd.d/*.conf

启动客户端

systemctl start zabbix-agent.service

创建zabbix的mysql账号

mysql> create user zabbix@'%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)

mysql> grant usage,replication client,process,show databases,show view on *.* to zabbix@'%';
Query OK, 0 rows affected (0.00 sec)

在/etc/zabbix/目录下创建.my.cnf文件,vim .my.cnf

[client]
host=localhost
user='root'
password='123456'

复制userparameter_mysql.conf文件到/etc/zabbix/zabbix_agentd.d目录下

cp /usr/share/doc/zabbix-agent-5.0.15/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/

编辑修改参数,增加.my.cnf的环境变量,指定mysqladmin等命令的位置vim userparameter_mysql.conf

#template_db_mysql.conf created by Zabbix for "Template DB MySQL" and Zabbix 4.2
#For OS Linux: You need create .my.cnf in zabbix-agent home directory (/var/lib/zabbix by default) 
#For OS Windows: You need add PATH to mysql and mysqladmin and create my.cnf in %WINDIR%\my.cnf,C:\my.cnf,BASEDIR\my.cnf https://dev.mysql.com/doc/refman/5.7/en/option-files.html
#The file must have three strings:
#[client]
#user=zbx_monitor
#password=<password>
#
UserParameter=mysql.ping[*],HOME=/etc/zabbix /usr/local/mysql/bin/mysqladmin -h"$1" -P"$2" ping
UserParameter=mysql.get_status_variables[*],HOME=/etc/zabbix /usr/local/mysql/bin/mysql -h"$1" -P"$2" -sNX -e "show global status"
UserParameter=mysql.version[*],HOME=/etc/zabbix /usr/local/mysql/bin/mysqladmin -s -h"$1" -P"$2" version
UserParameter=mysql.db.discovery[*],HOME=/etc/zabbix /usr/local/mysql/bin/mysql -h"$1" -P"$2" -sN -e "show databases"
UserParameter=mysql.dbsize[*],HOME=/etc/zabbix /usr/local/mysql/bin/mysql -h"$1" -P"$2" -sN -e "SELECT SUM(DATA_LENGTH + INDEX_LENGTH) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'"
UserParameter=mysql.replication.discovery[*],HOME=/etc/zabbix /usr/local/mysql/bin/mysql -h"$1" -P"$2" -sNX -e "show slave status"
UserParameter=mysql.slave_status[*],HOME=/etc/zabbix /usr/local/mysql/bin/mysql -h"$1" -P"$2" -sNX -e "show slave status"

在zabbix服务端页面增加配置模板


这篇关于zabbix监控mysql的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!