zabbix4.2官方支持mysql监控,使用的模板是Template DB MySQL,但是我们还是需要配置下agent客户端的机器
1.先被监控端需要将mysql添加到环境变量,主要用到了mysql和mysqladmin两个命令
2.复制template_db_mysql.conf配置到/etc/zabbix/zabbix_agentd.d/目录
3.在agent客户端机器mysql中创建一个监控账户
CREATE USER 'zbx_monitor'@'%' IDENTIFIED BY '<password>';GRANT USAGE,REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'%'
4.在agent客户端机器/etc/zabbix目录下创建.my.cnf文件,内容为
[client] user=zbx_monitor password=<password>
zabbix上所用到的宏
Name | Description | Default |
---|---|---|
{$MYSQL.HOST} | Hostname or IP of MySQL host or container | localhost |
{$MYSQL.PORT} | MySQL service port | 3306 |
{$MYSQL.REPL_LAG.MAX.WARN} | The lag of slave from master for trigger expression. | 30m |
{$MYSQL.SLOW_QUERIES.MAX.WARN} | The number of slow queries for trigger expression. | 3 |
{$MYSQL.ABORTED_CONN.MAX.WARN} | The number of failed attempts to connect to the MySQL server for trigger expression. | 3 |
官网zabbix监控mysql解决方案:https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/db/mysql