创建监控账号

首先在被监控服务器上增加监控账户,方便agent能够访问到服务器。

[root@server10 ~]# mysql -uroot -p580a71609c087e15
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create user zabbix@localhost identified by '1qaz!QAZ';
Query OK, 0 rows affected (0.23 sec)

mysql> grant usage,select  on *.* to zabbix@localhost ;
Query OK, 0 rows affected (0.00 sec)

设置监控用户到配置文件当中

在/etc/my.cnf.d中,创建zabbix_client.cnf 文档

[root@server10 my.cnf.d]# cat <zabbix_client.cnf
[client]
user=zabbix
password=1qaz!QAZ
EOF

配置 MySQL 监 控的相关参数:

查看官方zabbix配置mysql文档

确定zabbix_agent配置文件包含下面这行,并且没被注释,查看配置文件(通常位于 /etc/zabbix/zabbix_agentd.conf)

修改mysql的监控指标

因为我们使用的agent2,安装的时候已经安装了检测指标,
/etc/zabbix/plugins.d/mysql.conf
修改里面的2处配置

### Option: Plugins.Mysql.Default.User
#       Username to be used for MySQL authentication. Default value used if no other is specified.
#
# Mandatory: no
# Default:
Plugins.Mysql.Default.User=zabbix

### Option: Plugins.Mysql.Default.Password
#       Password to be used for MySQL authentication. Default value used if no other is specified.
#
# Mandatory: no
# Default:
Plugins.Mysql.Default.Password=1qaz!QAZ

是的插件启动的时候能直接访问数据库进行检测。

作者:严锋  创建时间:2023-11-23 09:27
最后编辑:严锋  更新时间:2025-05-09 15:48