ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

Template DB MySQL学习总结

2020-07-19 11:00:59  阅读:846  来源: 互联网

标签:monitor DB zabbix agent Zabbix Template MySQL home


Zabbix 5.0下如何应用Template DB MySQL来监控MySQL数据库呢?下面简单整理一下如何配置、应用Zabbix下自带的模板Template DB MySQL。其实非常简单。

 

Template DB MySQL可以在Zabbix 5.0的模板下面查看,也有简单的安装相关说明,如下所示:

 

clip_image001

 

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>

 

在GitHub上https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/db/mysql_agent上,你可以看到更详细的信息

 

 

Overview

 

For Zabbix version: 5.0

The template is developed for monitoring DBMS MySQL and its forks.

 

This template was tested on:

 

·         MySQL, version 5.7, 8.0

·         Percona, version 8.0

·         MariaDB, version 10.4

·         Zabbix, version 4.2.1

 

Setup

 

See Zabbix template operation for basic instructions.

 

1. Install Zabbix agent and MySQL client. If necessary, add the path to the mysql and mysqladmin utilities to the global environment variable PATH.

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

3. Create MySQL user for monitoring (<password> at your discretion):

 

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

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

 

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

 

4. Create .my.cnf in home directory of Zabbix agent for Linux (/var/lib/zabbix by default ) or my.cnf in c:\ for Windows. The file must have three strings:

 

[client]

user='zbx_monitor'

password='<password>'

 

NOTE: Use systemd to start the Zabbix agent on Linux OS. For example in Centos use "systemctl edit zabbix-agent.service" to set the required user to start the Zabbix agent.

 

Add the rule to the SELinux policy (example for Centos):

 

# cat <<EOF > zabbix_home.te

module zabbix_home 1.0;

 

require {

        type zabbix_agent_t;

        type zabbix_var_lib_t;

        type mysqld_etc_t;

        type mysqld_port_t;

        type mysqld_var_run_t;

        class file { open read };

        class tcp_socket name_connect;

        class sock_file write;

}

 

#============= zabbix_agent_t ==============

 

allow zabbix_agent_t zabbix_var_lib_t:file read;

allow zabbix_agent_t zabbix_var_lib_t:file open;

allow zabbix_agent_t mysqld_etc_t:file read;

allow zabbix_agent_t mysqld_port_t:tcp_socket name_connect;

allow zabbix_agent_t mysqld_var_run_t:sock_file write;

EOF

# checkmodule -M -m -o zabbix_home.mod zabbix_home.te

# semodule_package -o zabbix_home.pp -m zabbix_home.mod

# semodule -i zabbix_home.pp

# restorecon -R /var/lib/zabbix

 

 

下面用中文简单总结概括一下

 

 

1:在被监控的主机上安装Zabbix Agent和 MySQL Client,如有必要,将mysql和mysqladmin应用程序的路径添加到全局环境变量PATH中。

 

2:将Template_DB_MySQL.conf文件拷贝到Zabbix Agent的配置目录(默认为etc/zabbix/zabbix_agentd.d/),不要忘记重启Zabbix Agent。

 

    注意,Template_DB_MySQL.conf文件在哪里呢?相信有些人会懵逼。这个文件在https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/db/mysql_agent下

 

    我将zabbix源码download下面,此文件位于zabbix-master@18cf3730036\templates\db\mysql_agent下。

 

3:在被监控的数据库上创建数据库账号

 

CREATE USER 'zbx_monitor'@'%' IDENTIFIED BY 'xxxxx';
GRANT USAGE,REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'%'

标签:monitor,DB,zabbix,agent,Zabbix,Template,MySQL,home
来源: https://www.cnblogs.com/kerrycode/p/13338983.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有