zabbix监控mariadb

zabbix 服务端安装请参阅:红帽 9 zabbix 安装流程_红帽安装zabbix-CSDN博客

源码包安装mariadb请参阅:源码包安装mariadb_mariadb 11 源码编译安装-CSDN博客

  • 在MariaDB中,你需要创建一个专门的用户,用于Zabbix进行监控。这个用户需要有足够的权限来查询数据库的状态和性能信息。
创建一个新用户
[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 10.6.17-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 
MariaDB [(none)]> 
MariaDB [(none)]> create user 'mariadb'@'%' identified by '1';
Query OK, 0 rows affected (0.008 sec)

MariaDB [(none)]> grant replication client,process,show databases,show view on *.* to 'mariadb'@'%';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> 
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> exit
Bye
安装zabbix Agent
[root@localhost ~]# systemctl  stop firewalld.service 
[root@localhost ~]# systemctl  disable firewalld.service 
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".
[root@localhost ~]# 
[root@localhost ~]# setenforce  0
[root@localhost ~]# sed  -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config 
[root@localhost ~]# 
[root@localhost ~]# rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/9/x86_64/zabbix-release-6.4-1.el9.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/6.4/rhel/9/x86_64/zabbix-release-6.4-1.el9.noarch.rpm
warning: /var/tmp/rpm-tmp.0UftJZ: Header V4 RSA/SHA512 Signature, key ID 08efa7dd: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-6.4-1.el9         ################################# [100%]
[root@localhost ~]# dnf clean all
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

13 files removed
[root@localhost ~]# yum -y install  zabbix-agent
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

aa                                                                                                                               241 MB/s | 6.3 MB     00:00    
bb                                                                                                                               133 MB/s | 1.7 MB     00:00    
Zabbix Official Repository - x86_64                                                                                               13 kB/s | 236 kB     00:17    
Zabbix Official Repository non-supported - x86_64                                                                                150  B/s | 1.1 kB     00:07    
Dependencies resolved.
=================================================================================================================================================================
 Package                                Architecture                     Version                                          Repository                        Size
=================================================================================================================================================================
Installing:
 zabbix-agent                           x86_64                           6.4.14-release1.el9                              zabbix                           560 k

Transaction Summary
=================================================================================================================================================================
Install  1 Package

Total download size: 560 k
Installed size: 2.4 M
Downloading Packages:
zabbix-agent-6.4.14-release1.el9.x86_64.rpm                                                                                       11 kB/s | 560 kB     00:50    
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                             11 kB/s | 560 kB     00:50     
Zabbix Official Repository - x86_64                                                                                              3.0 MB/s | 3.1 kB     00:00    
Importing GPG key 0x08EFA7DD:
 Userid     : "Zabbix LLC (Jul 2022) <packager@zabbix.com>"
 Fingerprint: D9AA 84C2 B617 479C 6E4F CF4D 19F2 4753 08EF A7DD
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-08EFA7DD
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                         1/1 
  Running scriptlet: zabbix-agent-6.4.14-release1.el9.x86_64                                                                                                 1/1 
  Installing       : zabbix-agent-6.4.14-release1.el9.x86_64                                                                                                 1/1 
  Running scriptlet: zabbix-agent-6.4.14-release1.el9.x86_64                                                                                                 1/1 
  Verifying        : zabbix-agent-6.4.14-release1.el9.x86_64                                                                                                 1/1 
Installed products updated.

Installed:
  zabbix-agent-6.4.14-release1.el9.x86_64                                                                                                                        

Complete!
[root@localhost ~]#

修改agent配置文件

[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf 
117 Server=192.168.200.133                  //此两行修改为服务端的IP地址
171 ServerActive=192.168.200.133
333 Include=/etc/zabbix/zabbix_agentd.d/*.conf
[root@localhost ~]# mkdir /var/lib/zabbix/
[root@localhost ~]# vim /var/lib/zabbix/.my.cnf     //此文件新建
[client]
host = localhost
user = mariadb
password = 1
[root@localhost ~]# cp /usr/share/doc/zabbix-agent/userparameter_mysql.conf   /etc/zabbix/zabbix_agentd.d/  //复制一份过去
[root@localhost ~]# cd /etc/zabbix/zabbix_agentd.d/
[root@localhost zabbix_agentd.d]# vim  userparameter_mysql.conf
.......
UserParameter=mysql.ping[*], /usr/local/mysql/bin/mysqladmin -h"$1" -P"$2" ping
UserParameter=mysql.get_status_variables[*],/usr/local/mysql/bin/mysql -h"$1" -P"$2" -sNX -e "show global status"
UserParameter=mysql.version[*],/usr/local/mysql/bin/mysqladmin -s -h"$1" -P"$2" version
UserParameter=mysql.db.discovery[*], /usr/local/mysql/bin/mysql -h"$1" -P"$2" -sN -e "show databases"
UserParameter=mysql.dbsize[*],/usr/local/mysql/bin/ 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[*], /usr/local/mysql/bin/mysql -h"$1" -P"$2" -sNX -e "show slave status"
UserParameter=mysql.slave_status[*], /usr/local/mysql/bin/mysql -h"$1" -P"$2" -sNX -e "show slave status"
~                                                                                                               
[root@localhost ~]# systemctl  restart  zabbix-agent.service 
[root@localhost ~]# systemctl  enable  zabbix-agent.service 
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-agent.service → /usr/lib/systemd/system/zabbix-agent.service.
[root@localhost ~]# 

在服务端上添加mariadb主机

相关推荐
DashVector18 分钟前
如何通过HTTP API检索Doc
数据库·人工智能·http·阿里云·数据库开发·向量检索
SEO-狼术1 小时前
Enhance Security in Software Crack
数据库
计算机毕设定制辅导-无忧学长1 小时前
Redis 初相识:开启缓存世界大门
数据库·redis·缓存
Rverdoser2 小时前
redis延迟队列
数据库·redis·缓存
weisian1512 小时前
Redis篇--常见问题篇6--缓存一致性1(Mysql和Redis缓存一致,更新数据库删除缓存策略)
数据库·redis·缓存
中草药z3 小时前
【Spring】深入解析 Spring 原理:Bean 的多方面剖析(源码阅读)
java·数据库·spring boot·spring·bean·源码阅读
地球资源数据云3 小时前
全国30米分辨率逐年植被覆盖度(FVC)数据集
大数据·运维·服务器·数据库·均值算法
Ahern_4 小时前
Oracle 普通表至分区表的分区交换
大数据·数据库·sql·oracle
夜半被帅醒4 小时前
MySQL 数据库优化详解【Java数据库调优】
java·数据库·mysql
不爱学习的啊Biao4 小时前
【13】MySQL如何选择合适的索引?
android·数据库·mysql