zabbix5监控mysql配置

2021-07-05 18:04:26 浏览数 (1)

1、登陆页面-配置-模版-搜索模版名称-mysql

Requirements for template operation:

1.Install Zabbix agent and MySQL client.

2.Copy Template_DB_MySQL.conf into folder with Zabbix agent configuration (/etc/zabbix/zabbix_agentd.d/ by default). Don't forget restart zabbix-agent.

3.Create MySQL user for monitoring. For example:

CREATE USER 'zbx_monitor'@'%' IDENTIFIED BY '<password>';

GRANT USAGE,REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'%';

For more information read the MYSQL documentation https://dev.mysql.com/doc/refman/8.0/en/grant.html , please.

4.Create .my.cnf in home directory of Zabbix agent for Linux (/var/lib/zabbix by default ) or my.cnf in c: for Windows. For example:

[client]

user=zbx_monitor

password=<password>

由此可看到配置步骤

安装zabbix-agent、mysql客户端

将mysql监控模版拷贝到zabbix-agent的安装目录,默认/etc/zabbix/zabbix_agent.d/下

在mysql数据库中创建用户以及赋权工作

2、配置mysql监控

查找mysql监控模版

# find / -name userparameter_mysql.conf

/usr/share/doc/zabbix-agent-5.0.12/userparameter_mysql.conf

拷贝到对应目录

# cp /usr/share/doc/zabbix-agent-5.0.12/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/

修改对应配置文件

# vi /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf

#template_db_mysql.conf created by Zabbix for "Template DB MySQL" and Zabbix 4.2

#For OS Linux: You need create .my.cnf in zabbix-agent home directory (/var/lib/zabbix by default)

#For OS Windows: You need add PATH to mysql and mysqladmin and create my.cnf in %WINDIR%my.cnf,C:my.cnf,BASEDIRmy.cnf https://dev.mysql.com/doc/refman/5.7/en/option-files.html

#The file must have three strings:

#[client]

#user=zbx_monitor

#password=<password>

#

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 SUM(DATA_LENGTH INDEX_LENGTH) 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"

修改后的,主要区别就在于加了一个HOME=/etc/zabbix

By default, a MariaDB installation has an anonymous user, allowing anyone

#template_db_mysql.conf created by Zabbix for "Template DB MySQL" and Zabbix 4.2

#For OS Linux: You need create .my.cnf in zabbix-agent home directory (/var/lib/zabbix by default)

#For OS Windows: You need add PATH to mysql and mysqladmin and create my.cnf in %WINDIR%my.cnf,C:my.cnf,BASEDIRmy.cnf https://dev.mysql.com/doc/refman/5.7/en/option-files.html

#The file must have three strings:

#[client]

#user=zbx_monitor

#password=<password>

#

UserParameter=mysql.ping[*],HOME=/etc/zabbix mysqladmin -h"$1" -P"$2" ping

UserParameter=mysql.get_status_variables[*],HOME=/etc/zabbix mysql -h"$1" -P"$2" -sNX -e "show global status"

UserParameter=mysql.version[*],HOME=/etc/zabbix mysqladmin -s -h"$1" -P"$2" version

UserParameter=mysql.db.discovery[*],HOME=/etc/zabbix mysql -h"$1" -P"$2" -sN -e "show databases"

UserParameter=mysql.dbsize[*],HOME=/etc/zabbix mysql -h"$1" -P"$2" -sN -e "SELECT SUM(DATA_LENGTH INDEX_LENGTH) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'"

UserParameter=mysql.replication.discovery[*],HOME=/etc/zabbix mysql -h"$1" -P"$2" -sNX -e "show slave status"

UserParameter=mysql.slave_status[*],HOME=/etc/zabbix mysql -h"$1" -P"$2" -sNX -e "show slave status"

进入到mysql库

MariaDB [(none)]> CREATE USER 'zbx_monitor'@'%' IDENTIFIED BY '1qaz@WSX';

MariaDB [(none)]> GRANT USAGE,REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'%';

创建.my.cnf文件,目录在/etc/zabbix/目录下

# ll -a

总用量 32

drwxr-xr-x 3 root root 70 7月 5 14:40 .

drwxr-xr-x. 77 root root 8192 7月 5 14:07 ..

-rw-r--r-- 1 root root 91 7月 5 14:40 .my.cnf

-rw-r--r-- 1 root root 15104 6月 29 14:28 zabbix_agentd.conf

drwxr-xr-x 2 root root 38 7月 5 14:38 zabbix_agentd.d

# cat .my.cnf

[mysql]

user=zbx_monitor

password=1qaz@WSX

[mysqladmin]

user=zbx_monitor

password=1qaz@WSX

# pwd

/etc/zabbix

0 人点赞