当前位置: 首页 > news >正文

zabbix-6.4 监控 MySQL

目录

1、rpm安装zabbix_agentd服务

2、编写zabbix_agentd.conf文件

3、编写模板文件

4、创建mysql用户并赋权限

5、创建.my.cnf文件

6、将规则添加到SELinux策略中

注意:

若模板无法读取.my.cnf 信息,从而导致监控报错,可以尝试修改模板配置配置文件:


1、rpm安装zabbix_agentd服务

​
rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/7/x86_64/zabbix-release-6.4-1.el7.noarch.rpm
yum clean all# b. Install Zabbix agent
yum install zabbix-agent
# c. Start Zabbix agent process
# Start Zabbix agent process and make it start at system boot.sudo systemctl stop zabbix-agent
systemctl restart zabbix-agent
systemctl enable zabbix-agent

2、编写zabbix_agentd.conf文件

cd /etc/zabbix
vim zabbix_agentd.confPidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd_1.log
LogFileSize=0
Server=192.168.3.246
ServerActive=192.168.3.246
Hostname=192.168.3.244
Include=/etc/zabbix/zabbix_agentd.d/*.conf
UnsafeUserParameters=1

3、编写模板文件

​
vim /etc/zabbix/zabbix_agentd.d/template_db_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,BASEDIR\my.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 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"​

4、创建mysql用户并赋权限

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

5、创建.my.cnf文件

mkdir -p /var/lib/zabbix
vim /var/lib/zabbix/.my.cnf[client]
user='zbx_monitor'
password='123456'

6、将规则添加到SELinux策略中

systemctl edit zabbix-agent.service# 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

注意:

若模板无法读取.my.cnf 信息,从而导致监控报错,可以尝试修改模板配置配置文件:

#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,BASEDIR\\my.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 --defaults-extra-file='/var/lib/zabbix/.my.cnf' -h"$1" -P"$2" ping
UserParameter=mysql.get_status_variables[*], mysql --defaults-extra-file='/var/lib/zabbix/.my.cnf' -h"$1" -P"$2" -sNX -e "show global status"
UserParameter=mysql.version[*], mysqladmin --defaults-extra-file='/var/lib/zabbix/.my.cnf' -h"$1" -P"$2" version
UserParameter=mysql.db.discovery[*], mysql --defaults-extra-file='/var/lib/zabbix/.my.cnf' -h"$1" -P"$2" -sN -e "show databases"
UserParameter=mysql.dbsize[*], mysql --defaults-extra-file='/var/lib/zabbix/.my.cnf' -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 --defaults-extra-file='/var/lib/zabbix/.my.cnf' -h"$1" -P"$2" -sNX -e "show slave status"
UserParameter=mysql.slave_status[*], mysql --defaults-extra-file='/var/lib/zabbix/.my.cnf' -h"$1" -P"$2" -sNX -e "show slave status"

http://www.lryc.cn/news/124437.html

相关文章:

  • 深入探索:解读创意的力量——idea的下载、初步使用
  • Redis详解
  • 【Linux】高级IO
  • 动态HTTP代理与竞争情报收集的关联
  • kafka基本概念及操作
  • 分享个试卷去笔迹什么软件,几个步骤轻松擦除
  • ClickHouse(十八):Clickhouse Integration系列表引擎
  • 日常BUG——代码提交到了本地但是没有push,删除了本地分支如何恢复
  • Markdown语法
  • vue3表格,编辑案例
  • SQL Server Reporting Services 报错:报表服务器无法访问服务帐户的私钥
  • QT报表Limereport v1.5.35编译及使用
  • 互联网发展历程:从中继器口不够到集线器的引入
  • vue+flask基于知识图谱的抑郁症问答系统
  • 操作格子---算法集
  • 科研绘图chapter1:绘图原则与配色基础
  • Linux下grep通配容易混淆的地方
  • WebRTC音视频通话-WebRTC本地视频通话使用ossrs服务搭建
  • 基于SpringBoot和Freemarker的页面静态化
  • 给软件增加license
  • vue中实现订单支付倒计时
  • 途乐证券-新手炒股快速入门教程?
  • 【冒泡排序及其优化】
  • TypeScript 泛型的深入解析与基本使用
  • 【Terraform学习】保护敏感变量(Terraform配置语言学习)
  • 海国图志#1:这一周难忘瞬间,吐血整理,不得不看
  • 【Android】okhttp爆java.lang.IllegalStateException: closed的解决方法
  • Django之定时任务--apscheduler
  • Spring Boot 项目应用消息服务器RabbitMQ(简单介绍)
  • HBuilderX