zabbix agent集成percona监控MySQL的插件实战案例

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: 这篇文章是关于如何使用Percona监控插件集成Zabbix agent来监控MySQL的实战案例。

作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.自行部署MySQL主从同步

  博主推荐阅读:
    https://www.cnblogs.com/yinzhengjie/p/11816066.html

二.安装percona

1>.percona官网文档

  安装教程:
    https://www.percona.com/doc/percona-monitoring-plugins/LATEST/zabbix/index.html#installation-instructions  
    
  下载地址:
    https://www.percona.com/downloads/
  插件地址:
    https://www.percona.com/doc/percona-monitoring-plugins/LATEST/zabbix/index.html

2>.下载percona

[root@node203.yinzhengjie.org.cn ~]# ll
total 0
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]# wget https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.8/binary/redhat/7/x86_64/percona-zabbix-templates-1.1.8-1.noarch.rpm
--2020-02-29 15:15:55--  https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.8/binary/redhat/7/x86_64/percona-zabbix-templates-1.1.8-1.noarch.rpm
Resolving www.percona.com (www.percona.com)... 74.121.199.234
Connecting to www.percona.com (www.percona.com)|74.121.199.234|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 28296 (28K) [application/x-redhat-package-manager]
Saving to: ‘percona-zabbix-templates-1.1.8-1.noarch.rpm’

100%[====================================================================================================================================================================================================================================>] 28,296       104KB/s   in 0.3s   

2020-02-29 15:15:56 (104 KB/s) - ‘percona-zabbix-templates-1.1.8-1.noarch.rpm’ saved [28296/28296]

[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]# ll
total 28
-rw-r--r-- 1 root root 28296 Jan 10  2018 percona-zabbix-templates-1.1.8-1.noarch.rpm
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]#

[root@node203.yinzhengjie.org.cn ~]# wget https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.8/binary/redhat/7/x86_64/percona-zabbix-templates-1.1.8-1.noarch.rpm

3>.安装percona

[root@node203.yinzhengjie.org.cn ~]# ll
total 28
-rw-r--r-- 1 root root 28296 Jan 10  2018 percona-zabbix-templates-1.1.8-1.noarch.rpm
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]# rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm 
warning: percona-zabbix-templates-1.1.8-1.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:percona-zabbix-templates-1.1.8-1 ################################# [100%]

Scripts are installed to /var/lib/zabbix/percona/scripts
Templates are installed to /var/lib/zabbix/percona/templates
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]# rpm -qpl percona-zabbix-templates-1.1.8-1.noarch.rpm 
warning: percona-zabbix-templates-1.1.8-1.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY
/var/lib/zabbix/percona
/var/lib/zabbix/percona/scripts
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
/var/lib/zabbix/percona/templates
/var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf
/var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]#

[root@node203.yinzhengjie.org.cn ~]# rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm

三.将percona的插件集成到zabbix agent端

1>.安装zabbix agent服务

  CentOS运行环境博主推荐阅读:
    https://www.cnblogs.com/yinzhengjie2020/p/12344057.html
  Ubuntu运行环境博主推荐阅读:
    https://www.cnblogs.com/yinzhengjie2020/p/12309682.html

2>.将percona的配置文件拷贝到zabbix agent的子配置文件目录并重启zabbix agent服务使得配置文件生效

[root@node203.yinzhengjie.org.cn ~]# cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]# systemctl restart zabbix-agent.service
[root@node203.yinzhengjie.org.cn ~]#

3>.配置MySQL的用户名和密码,我root用户密码为空,因此直接mysql_pass的值直接給空串即可。

[root@node203.yinzhengjie.org.cn ~]# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]# cat /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf
<?php
$mysql_user = 'root';
$mysql_pass = '';
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]#

4>.安装php环境,否则会运行报错,如下图所示

[root@node203.yinzhengjie.org.cn ~]# yum -y install php
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:5.4.16-46.1.el7_7 will be installed
--> Processing Dependency: php-cli(x86-64) = 5.4.16-46.1.el7_7 for package: php-5.4.16-46.1.el7_7.x86_64
--> Processing Dependency: httpd-mmn = 20120211x8664 for package: php-5.4.16-46.1.el7_7.x86_64
--> Processing Dependency: httpd for package: php-5.4.16-46.1.el7_7.x86_64
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-90.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-90.el7.centos for package: httpd-2.4.6-90.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-90.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-90.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-90.el7.centos.x86_64
---> Package php-cli.x86_64 0:5.4.16-46.1.el7_7 will be installed
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-5.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-90.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================================================================================
 Package                                                           Arch                                                         Version                                                                   Repository                                                     Size
==============================================================================================================================================================================================================================================================================
Installing:
 php                                                               x86_64                                                       5.4.16-46.1.el7_7                                                         updates                                                       1.4 M
Installing for dependencies:
 apr                                                               x86_64                                                       1.4.8-5.el7                                                               base                                                          103 k
 apr-util                                                          x86_64                                                       1.5.2-6.el7                                                               base                                                           92 k
 httpd                                                             x86_64                                                       2.4.6-90.el7.centos                                                       base                                                          2.7 M
 httpd-tools                                                       x86_64                                                       2.4.6-90.el7.centos                                                       base                                                           91 k
 mailcap                                                           noarch                                                       2.1.41-2.el7                                                              base                                                           31 k
 php-cli                                                           x86_64                                                       5.4.16-46.1.el7_7                                                         updates                                                       2.7 M

Transaction Summary
==============================================================================================================================================================================================================================================================================
Install  1 Package (+6 Dependent packages)

Total download size: 7.1 M
Installed size: 23 M
Downloading packages:
(1/7): apr-1.4.8-5.el7.x86_64.rpm                                                                                                                                                                                                                      | 103 kB  00:00:00     
(2/7): apr-util-1.5.2-6.el7.x86_64.rpm                                                                                                                                                                                                                 |  92 kB  00:00:00     
(3/7): httpd-tools-2.4.6-90.el7.centos.x86_64.rpm                                                                                                                                                                                                      |  91 kB  00:00:00     
(4/7): php-cli-5.4.16-46.1.el7_7.x86_64.rpm                                                                                                                                                                                                            | 2.7 MB  00:00:00     
(5/7): mailcap-2.1.41-2.el7.noarch.rpm                                                                                                                                                                                                                 |  31 kB  00:00:00     
(6/7): php-5.4.16-46.1.el7_7.x86_64.rpm                                                                                                                                                                                                                | 1.4 MB  00:00:00     
(7/7): httpd-2.4.6-90.el7.centos.x86_64.rpm                                                                                                                                                                                                            | 2.7 MB  00:00:01     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                                                         6.4 MB/s | 7.1 MB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.4.8-5.el7.x86_64                                                                                                                                                                                                                                     1/7 
  Installing : apr-util-1.5.2-6.el7.x86_64                                                                                                                                                                                                                                2/7 
  Installing : httpd-tools-2.4.6-90.el7.centos.x86_64                                                                                                                                                                                                                     3/7 
  Installing : mailcap-2.1.41-2.el7.noarch                                                                                                                                                                                                                                4/7 
  Installing : httpd-2.4.6-90.el7.centos.x86_64                                                                                                                                                                                                                           5/7 
  Installing : php-cli-5.4.16-46.1.el7_7.x86_64                                                                                                                                                                                                                           6/7 
  Installing : php-5.4.16-46.1.el7_7.x86_64                                                                                                                                                                                                                               7/7 
  Verifying  : php-cli-5.4.16-46.1.el7_7.x86_64                                                                                                                                                                                                                           1/7 
  Verifying  : mailcap-2.1.41-2.el7.noarch                                                                                                                                                                                                                                2/7 
  Verifying  : httpd-tools-2.4.6-90.el7.centos.x86_64                                                                                                                                                                                                                     3/7 
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                                                                                                                                                                                                                4/7 
  Verifying  : httpd-2.4.6-90.el7.centos.x86_64                                                                                                                                                                                                                           5/7 
  Verifying  : apr-1.4.8-5.el7.x86_64                                                                                                                                                                                                                                     6/7 
  Verifying  : php-5.4.16-46.1.el7_7.x86_64                                                                                                                                                                                                                               7/7 

Installed:
  php.x86_64 0:5.4.16-46.1.el7_7                                                                                                                                                                                                                                              

Dependency Installed:
  apr.x86_64 0:1.4.8-5.el7             apr-util.x86_64 0:1.5.2-6.el7             httpd.x86_64 0:2.4.6-90.el7.centos             httpd-tools.x86_64 0:2.4.6-90.el7.centos             mailcap.noarch 0:2.1.41-2.el7             php-cli.x86_64 0:5.4.16-46.1.el7_7            

Complete!
[root@node203.yinzhengjie.org.cn ~]#

[root@node203.yinzhengjie.org.cn ~]# yum -y install php            #安装php程序的运行环境

[root@node203.yinzhengjie.org.cn ~]# yum -y install php-mysql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package php-mysql.x86_64 0:5.4.16-46.1.el7_7 will be installed
--> Processing Dependency: php-pdo(x86-64) = 5.4.16-46.1.el7_7 for package: php-mysql-5.4.16-46.1.el7_7.x86_64
--> Running transaction check
---> Package php-pdo.x86_64 0:5.4.16-46.1.el7_7 will be installed
--> Processing Dependency: php-common(x86-64) = 5.4.16-46.1.el7_7 for package: php-pdo-5.4.16-46.1.el7_7.x86_64
--> Running transaction check
---> Package php-common.x86_64 0:5.4.16-46.1.el7_7 will be installed
--> Processing Dependency: libzip.so.2()(64bit) for package: php-common-5.4.16-46.1.el7_7.x86_64
--> Running transaction check
---> Package libzip.x86_64 0:0.10.1-8.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================================================================================
 Package                                                          Arch                                                         Version                                                                    Repository                                                     Size
==============================================================================================================================================================================================================================================================================
Installing:
 php-mysql                                                        x86_64                                                       5.4.16-46.1.el7_7                                                          updates                                                       101 k
Installing for dependencies:
 libzip                                                           x86_64                                                       0.10.1-8.el7                                                               base                                                           48 k
 php-common                                                       x86_64                                                       5.4.16-46.1.el7_7                                                          updates                                                       565 k
 php-pdo                                                          x86_64                                                       5.4.16-46.1.el7_7                                                          updates                                                        99 k

Transaction Summary
==============================================================================================================================================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 814 k
Installed size: 4.3 M
Downloading packages:
(1/4): libzip-0.10.1-8.el7.x86_64.rpm                                                                                                                                                                                                                  |  48 kB  00:00:00     
(2/4): php-mysql-5.4.16-46.1.el7_7.x86_64.rpm                                                                                                                                                                                                          | 101 kB  00:00:00     
(3/4): php-pdo-5.4.16-46.1.el7_7.x86_64.rpm                                                                                                                                                                                                            |  99 kB  00:00:00     
(4/4): php-common-5.4.16-46.1.el7_7.x86_64.rpm                                                                                                                                                                                                         | 565 kB  00:00:00     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                                                         2.9 MB/s | 814 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libzip-0.10.1-8.el7.x86_64                                                                                                                                                                                                                                 1/4 
  Installing : php-common-5.4.16-46.1.el7_7.x86_64                                                                                                                                                                                                                        2/4 
  Installing : php-pdo-5.4.16-46.1.el7_7.x86_64                                                                                                                                                                                                                           3/4 
  Installing : php-mysql-5.4.16-46.1.el7_7.x86_64                                                                                                                                                                                                                         4/4 
  Verifying  : php-common-5.4.16-46.1.el7_7.x86_64                                                                                                                                                                                                                        1/4 
  Verifying  : libzip-0.10.1-8.el7.x86_64                                                                                                                                                                                                                                 2/4 
  Verifying  : php-mysql-5.4.16-46.1.el7_7.x86_64                                                                                                                                                                                                                         3/4 
  Verifying  : php-pdo-5.4.16-46.1.el7_7.x86_64                                                                                                                                                                                                                           4/4 

Installed:
  php-mysql.x86_64 0:5.4.16-46.1.el7_7                                                                                                                                                                                                                                        

Dependency Installed:
  libzip.x86_64 0:0.10.1-8.el7                                                        php-common.x86_64 0:5.4.16-46.1.el7_7                                                        php-pdo.x86_64 0:5.4.16-46.1.el7_7                                                       

Complete!
[root@node203.yinzhengjie.org.cn ~]#

[root@node203.yinzhengjie.org.cn ~]# yum -y install php-mysql        #安装php连接MySQL的驱动

5>.测试数据

[root@node203.yinzhengjie.org.cn ~]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
6913
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]# ll /tmp/
total 4
-rw-r--r-- 1 root root 1233 Feb 29 15:53 localhost-mysql_cacti_stats.txt
drwx------ 3 root root 17 Feb 29 05:38 systemd-private-a58aea3cb3bc4f2088bea3737fa8e295-chronyd.service-HP0GYE
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]# rm -f /tmp/localhost-mysql_cacti_stats.txt 
[root@node203.yinzhengjie.org.cn ~]#

6>.在zabbix server端测试数据是否可以正常获得

[root@zabbix203.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/zabbix/bin/zabbix_get -s 172.200.1.203 -p 10050 -k "MySQL.Key-read-requests"

7>.在Zabbix WebUI配置监控MySQL

  博主推荐阅读:
    https://www.cnblogs.com/yinzhengjie2020/p/12381448.html
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
3月前
|
存储 人工智能
|
16天前
|
缓存 监控 关系型数据库
如何根据监控结果调整 MySQL 数据库的参数以提高性能?
【10月更文挑战第28天】根据MySQL数据库的监控结果来调整参数以提高性能,需要综合考虑多个方面的因素
54 1
|
16天前
|
监控 关系型数据库 MySQL
如何监控和诊断 MySQL 数据库的性能问题?
【10月更文挑战第28天】监控和诊断MySQL数据库的性能问题是确保数据库高效稳定运行的关键
35 1
|
2月前
|
监控 Linux
Zabbix 5.0 LTS的agent服务部署实战篇
文章介绍了如何在CentOS 7.6操作系统上部署Zabbix 5.0 LTS版本的agent服务,包括配置软件源、安装agent、修改配置文件、启动服务,并在Zabbix web界面添加监控。
132 4
Zabbix 5.0 LTS的agent服务部署实战篇
|
3月前
|
机器学习/深度学习 存储 定位技术
强化学习Agent系列(一)——PyGame游戏编程,Python 贪吃蛇制作实战教学
本文是关于使用Pygame库开发Python贪吃蛇游戏的实战教学,介绍了Pygame的基本使用、窗口初始化、事件处理、键盘控制移动、以及实现游戏逻辑和对象交互的方法。
|
4月前
|
Prometheus 监控 Cloud Native
Prometheus结合Consul采集多个MySQL实例的监控指标
将 Prometheus 与 Consul 结合使用,实现对多个 MySQL 实例的自动发现与监控,不仅提高了监控的效率和准确性,也为管理动态扩缩容的数据库环境提供了强大的支持。通过细致配置每一部分,业务可以获得关键的性能指标和运行健康状况的即时反馈,进而优化资源配置,提高系统的稳定性和可用性。
162 3
|
8天前
|
存储 人工智能 自然语言处理
AI经营|多Agent择优生成商品标题
商品标题中关键词的好坏是商品能否被主搜检索到的关键因素,使用大模型自动优化标题成为【AI经营】中的核心能力之一,本文讲述大模型如何帮助商家优化商品素材,提升商品竞争力。
AI经营|多Agent择优生成商品标题
|
9天前
|
人工智能 算法 搜索推荐
清华校友用AI破解162个高数定理,智能体LeanAgent攻克困扰陶哲轩难题!
清华校友开发的LeanAgent智能体在数学推理领域取得重大突破,成功证明了162个未被人类证明的高等数学定理,涵盖抽象代数、代数拓扑等领域。LeanAgent采用“持续学习”框架,通过课程学习、动态数据库和渐进式训练,显著提升了数学定理证明的能力,为数学研究和教育提供了新的思路和方法。
21 3
|
10天前
|
人工智能 自然语言处理 算法
企业内训|AI/大模型/智能体的测评/评估技术-某电信运营商互联网研发中心
本课程是TsingtaoAI专为某电信运营商的互联网研发中心的AI算法工程师设计,已于近日在广州对客户团队完成交付。课程聚焦AI算法工程师在AI、大模型和智能体的测评/评估技术中的关键能力建设,深入探讨如何基于当前先进的AI、大模型与智能体技术,构建符合实际场景需求的科学测评体系。课程内容涵盖大模型及智能体的基础理论、测评集构建、评分标准、自动化与人工测评方法,以及特定垂直场景下的测评实战等方面。
55 4
|
23天前
|
人工智能 API 决策智能
swarm Agent框架入门指南:构建与编排多智能体系统的利器 | AI应用开发
Swarm是OpenAI在2024年10月12日宣布开源的一个实验性质的多智能体编排框架。其核心目标是让智能体之间的协调和执行变得更轻量级、更容易控制和测试。Swarm框架的主要特性包括轻量化、易于使用和高度可定制性,非常适合处理大量独立的功能和指令。【10月更文挑战第15天】
157 6

热门文章

最新文章

推荐镜像

更多