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

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

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'@'%';

个人观点:出于安全考虑,账号限定只能本机访问,不要设置为任意IP可以访问。

CREATE USER 'zbx_monitor'@'localhost' IDENTIFIED BY 'xxxxx';

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

4:找不到这个目录/var/lib/zabbix,那么新建此目录,然后创建.my.cnf

# rpm -ql zabbix-agent 

/etc/logrotate.d/zabbix-agent

/etc/zabbix/zabbix_agentd.conf

/etc/zabbix/zabbix_agentd.d

/usr/lib/systemd/system/zabbix-agent.service

/usr/lib/tmpfiles.d/zabbix-agent.conf

/usr/sbin/zabbix_agentd

/usr/share/doc/zabbix-agent-5.0.1

/usr/share/doc/zabbix-agent-5.0.1/AUTHORS

/usr/share/doc/zabbix-agent-5.0.1/COPYING

/usr/share/doc/zabbix-agent-5.0.1/ChangeLog

/usr/share/doc/zabbix-agent-5.0.1/NEWS

/usr/share/doc/zabbix-agent-5.0.1/README

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

/usr/share/man/man8/zabbix_agentd.8.gz

/var/log/zabbix

/var/run/zabbix

新建目录/var/lib/zabbix

# mkdir /var/lib/zabbix

添加访问数据库的账号信息。

[client]

user='zbx_monitor'

password='<password>'

关于Template DB MySQL的Discovery rules、Items 、Triggers、Macros,下面参考资料中已有详细介绍,在此略过。

 

参考资料:

https://www.zabbix.com/integrations/mysql

https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/db/mysql_agent

Template DB MySQL学习总结的更多相关文章

  1. 我的MYSQL学习心得(六) 函数

    我的MYSQL学习心得(六) 函数 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类 ...

  2. 我的MYSQL学习心得(十) 自定义存储过程和函数

    我的MYSQL学习心得(十) 自定义存储过程和函数 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心 ...

  3. 我的MYSQL学习心得(十三) 权限管理

    我的MYSQL学习心得(十三) 权限管理 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) ...

  4. 我的MYSQL学习心得(十五) 日志

    我的MYSQL学习心得(十五) 日志 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据 ...

  5. 我的MYSQL学习心得(十七) 复制

    我的MYSQL学习心得(十七) 复制 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据 ...

  6. 别人的的MYSQL学习心得(十五) 日志

    我的MYSQL学习心得(十五) 日志 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据 ...

  7. 我的MYSQL学习心得 mysql的权限管理

    这一篇<我的MYSQL学习心得(十三)>将会讲解MYSQL的用户管理 在mysql数据库中,有mysql_install_db脚本初始化权限表,存储权限的表有: 1.user表 2.db表 ...

  8. 我的MYSQL学习心得 mysql日志

    这一篇<我的MYSQL学习心得(十五)>将会讲解MYSQL的日志 MYSQL里的日志主要分为4类,使用这些日志文件,可以查看MYSQL内部发生的事情. 分别是 1.错误日志:记录mysql ...

  9. 我的MYSQL学习心得(六)

    原文:我的MYSQL学习心得(六) 我的MYSQL学习心得(六) 我的MYSQL学习心得(一) 我的MYSQL学习心得(二) 我的MYSQL学习心得(三) 我的MYSQL学习心得(四) 我的MYSQL ...

随机推荐

  1. SpringBoot整合Shiro自定义Redis存储

    Shiro Shiro 主要分为 安全认证 和 接口授权 两个部分,其中的核心组件为 Subject. SecurityManager. Realms,公共部分 Shiro 都已经为我们封装好了,我们 ...

  2. WebMvcConfigurerAdapter在2.x向上过时问题

    在spring boot2.x向上,书写配置类时集成的WebMvcConfigurerAdapter会显示此类已经过时. 解决:不继承WebMvcConfigurerAdapter类,该实现WebMv ...

  3. Could not update Activiti database schema: unknown version from database: '5.22.x.x'

    原因:activiti 相关的jar版本和表 act_ge_property 中 schema.version 所存储的版本不一致导致报错的. 查看activiti 相关jar版本 然后修改表中的版本 ...

  4. C++实现二叉树的链接存储结构(先根、中根和后根遍历)

    验证二叉树的链接存储结构及其上的基本操作. [实验要求]: 1. 从文件创建一棵二叉树,并对其初始化: 2. 先根.中根.后根遍历二叉树: 3. 在二叉树中搜索给定结点的父结点: 4. 搜索二叉树中符 ...

  5. BLE MESH 学习[1] - ESP32 篇

    BLE MESH 学习 BLE MESH 是一种蓝牙(n:m)组网的技术. 本篇先介绍 BLE MESH 到使用 ESP32 的官方示例对其进行学习讲解. 后面会进一步学习 SIG 的 BLE MES ...

  6. JavaScript学习系列博客_1_JavaScript简介

    这个系列博客主要用来记录本人学习JavaScript的笔记,从0开始,即使有些知识我也是知道的.但是会经常忘记,干脆就写成博客,没事的时候翻来看一看,留下一点学习的痕迹也好.可能写博客的水平暂时不太好 ...

  7. HM16.0之PCM模式——xCheckIntraPCM

    参考:https://blog.csdn.net/cxy19931018/article/details/79781042 1.源代码: /** Check R-D costs for a CU wi ...

  8. 从 BIO、NIO 聊到 Netty,最后还要实现个 RPC 框架!

    大家好,我是 「后端技术进阶」 作者,一个热爱技术的少年. 觉得不错的话,欢迎 star!ღ( ´・ᴗ・` )比心 Netty 从入门到实战系列文章地址:https://github.com/Snai ...

  9. spring如何创建RESTful Service

    REST REST,是指REpresentational State Transfer,有个精辟的解释什么是RESTful, 看url就知道要什么 看method就知道干什么 看status code ...

  10. Kubernetes Operator基础入门

    本文转自Rancher Labs 你是否曾经想过SRE团队是如何有效地成功管理复杂的应用?在Kubernetes生态系统中,Kubernetes Operator可以给你答案.在本文中,我们将研究Op ...