zabbix监控mysql
2021/10/7 19:14:32
本文主要是介绍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的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-16MySQL资料:新手入门教程
- 2024-11-16MySQL资料:新手入门教程
- 2024-11-15MySQL教程:初学者必备的MySQL数据库入门指南
- 2024-11-15MySQL教程:初学者必看的MySQL入门指南
- 2024-11-04部署MySQL集群项目实战:新手入门教程
- 2024-11-04如何部署MySQL集群资料:新手入门指南
- 2024-11-02MySQL集群项目实战:新手入门指南
- 2024-11-02初学者指南:部署MySQL集群资料
- 2024-11-01部署MySQL集群教程:新手入门指南
- 2024-11-01如何部署MySQL集群:新手入门教程