ZABBIX4.0 添加mysql监控

本文介绍如何使用Zabbix监控MySQL数据库的状态,包括设置监控所需的MySQL账户、配置zabbix_agentd以确保正常的数据通信、验证数据返回及添加监控模板等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境简介:

zabbix 服务器IP:192.168.101.1

mysql 服务器IP:192.168.101.2 (agent端)

前提条件:是192.168.102已经安装zabbix_agent

1.创建监控所需mysql账户(agent端):
grant usage on *.* to zabbix@127.0.0.1 identified by '123456';
flush privileges;

 
2.agent端:创建.my.cnf并检查zabbix账号是否能正常连接数据库
/etc/zabbix/下创建一个包含MySQL用户名和密码的配置文件“.my.cnf”

[client]
user=zabbix
host=127.0.0.1
password=123456

有了这个文件后,检查zabbix账号是否能正常连接数据库:
HOME=/etc/zabbix/ mysqladmin ping | grep -c alive

我这里是把已经改好的模板直接放到/etc/zabbix/zabbix_agentd.conf.d/ 目录下 ,注意HOME=路径的配置 配置完后续重启zabbix-agent:
kill -9 XXX
/usr/sbin/zabbix_agentd

3.zabbix服务端验证zabbix代理服务端是否正常返回数据

同时,在Server端也可以使用使用zabbix_get命令来测试从Server端获取指定的Client端的数据,如下:

[root@Zabbixserver alertscripts]# zabbix_get -s172.18.200.61 -p 10050 -k mysql.ping

如果返回数据,证明zabbix服务端可获取客户端信息!

4.页面对主机添加监控模板

至此,可看到监控数据!添加mysql监控成功!

监控脚本:

# For all the following commands HOME should be set to the directory that has .my.cnf file with password information.

# Flexible parameter to grab global variables. On the frontend side, use keys like mysql.status[Com_insert].
# Key syntax is mysql.status[variable].
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/etc/zabbix mysql -N | awk '{print $$2}'

# Flexible parameter to determine database or table size. On the frontend side, use keys like mysql.size[zabbix,history,data].
# Key syntax is mysql.size[<database>,<table>,<type>].
# Database may be a database name or "all". Default is "all".
# Table may be a table name or "all". Default is "all".
# Type may be "data", "index", "free" or "both". Both is a sum of data and index. Default is "both".
# Database is mandatory if a table is specified. Type may be specified always.
# Returns value in bytes.
# 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table
UserParameter=mysql.size[*],bash -c 'echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");" | HOME=/etc/zabbix mysql -N'

UserParameter=mysql.ping,HOME=/etc/zabbix mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V

 

 

 

 

 

 

 

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值