DataLife Engine / How to monitoring MySQL with Zabbix Agent

How to monitoring MySQL with Zabbix Agent


1. Create a MySQL user for monitoring:
CREATE USER 'zbx_usr'@'%' IDENTIFIED BY '5TobJ4vxRLchV2O11Wx6';
GRANT REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_usr'@'%';

2. Create mysql user params conf file:
vi /etc/zabbix/zabbix_agentd.d/template_db_mysql.conf
UserParameter=mysql.ping[*], mysqladmin -h"$1" -P"$2" ping
UserParameter=mysql.get_status_variables[*], mysql -h"$1" -P"$2" -sNX -e "show global status"
UserParameter=mysql.version[*], mysqladmin -s -h"$1" -P"$2" version
UserParameter=mysql.db.discovery[*], mysql -h"$1" -P"$2" -sN -e "show databases"
UserParameter=mysql.dbsize[*], mysql -h"$1" -P"$2" -sN -e "SELECT COALESCE(SUM(DATA_LENGTH + INDEX_LENGTH),0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'"
UserParameter=mysql.replication.discovery[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"
UserParameter=mysql.slave_status[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"

3. Create the home directory of Zabbix agent:
mkdir /var/lib/zabbix

4. Create .my.cnf in the home directory of Zabbix agent:
vi /var/lib/zabbix/.my.cnf
[client]
user='zbx_usr'
password='5TobJ4vxRLchV2O11Wx6'

5. Change perms and apply settings:
chown -R zabbix:zabbix /var/lib/zabbix
systemctl restart zabbix-agent

6. Add template MySQL by Zabbix agent to your host.
27-04-2023, 20:27
Вернуться назад