zabbix使用zabbix-agent2主动模式监控mysql
文章目录
https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/src/go/plugins/mysql/README.md
https://www.zabbix.com/cn/integrations/mysql#tab:official2
https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/db/mysql_agent2
1. 安装zabbix-agent2客户端
安装 zabbix 5.0 agent2客户端
# 安装 zabbix 5.0 官方centos7 yum源
rpm -ivh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# 安装 zabbix-agent2 客户端
yum -y install zabbix-agent2
配置zabbix-agent2.conf
vim /etc/zabbix/zabbix_agent2.conf
Server=192.168.0.226
ServerActive=192.168.0.226
Hostname=test-mariadb1
启动 zabbix-agent2 服务
systemctl enable zabbix-agent2 --now
防火墙放行zabbix-agent2服务
firewall-cmd --add-service=zabbix-agent --permanent
firewall-cmd --reload
登录mysql新建zabbix监控用户
CREATE USER 'zbx_monitor'@'%' IDENTIFIED BY '<password>';
GRANT USAGE,REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'%';
FLUSH PRIVILEGES;
# 如果mysql-server为被监控主机,为安全起见,新建local用户就行
CREATE USER 'zbx_monitor'@'localhost' IDENTIFIED BY '<password>';
GRANT USAGE,REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'localhost';
FLUSH PRIVILEGES;
2. 登录zabbix web页面
链接模板:Template OS Linux by Zabbix agent active
修改该模板相关宏的值
{$MYSQL.DSN} = tcp://localhost:3306
{$MYSQL.USER} = zbx_monitor
{$MYSQL.PASSWORD} = <password>
防火墙放行zabbix-server服务
firewall-cmd --add-service=zabbix-server --permanent
firewall-cmd --reload
3. 重启zabbix-agent2服务
systemctl restart zabbix-agent2
4. zabbix服务器端测试结果
zabbix_get -s <hostname> -p 10050 -k mysql.ping[tcp://localhost:3306,zbx_monitor,<password>]
1
# 返回1为正常
zabbix_get -s <hostname> -p 10050 -k mysql.version[tcp://localhost:3306,zbx_monitor,<password>]
10.3.27-MariaDB
# 返回数据库版本为正常