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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 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天前
|
运维 监控 安全
七载耕耘,全面盘点:Zabbix实战文章精华大全分享
在数字化转型的推动下,IT监控系统的重要性日益凸显。Zabbix作为开源监控领域的佼佼者,以其卓越的功能集成和灵活性赢得了全球企业的青睐。乐维社区由一群热爱技术的运维人员于七年前创立,现已成为国内最大的开源专业社区之一,汇聚了众多Zabbix用户的智慧与经验。社区提供了从基础安装到高级优化的全方位实战指导,并整理了“Zabbix实战文章精华大全”,涵盖基础知识、安全配置、性能优化等内容,为广大用户提供系统化的学习资源。欢迎下载使用,共同成长。
13 1
|
1月前
|
监控 Linux
Zabbix 5.0 LTS的agent服务部署实战篇
文章介绍了如何在CentOS 7.6操作系统上部署Zabbix 5.0 LTS版本的agent服务,包括配置软件源、安装agent、修改配置文件、启动服务,并在Zabbix web界面添加监控。
83 4
Zabbix 5.0 LTS的agent服务部署实战篇
|
1月前
|
监控 前端开发 数据库
Zabbix 5.0 LTS部署实战篇
这篇文章是关于Zabbix 5.0 LTS部署的详细教程,包括版本选择、服务器平台选择、安装步骤、数据库配置、前端安装以及修改时区和设置开机自启等内容。
106 1
Zabbix 5.0 LTS部署实战篇
|
3天前
|
自然语言处理 关系型数据库 MySQL
MySQL数据库使用Match语法需要安装什么插件吗?
【10月更文挑战第1天】MySQL数据库使用Match语法需要安装什么插件吗?
10 0
|
2月前
|
机器学习/深度学习 存储 定位技术
强化学习Agent系列(一)——PyGame游戏编程,Python 贪吃蛇制作实战教学
本文是关于使用Pygame库开发Python贪吃蛇游戏的实战教学,介绍了Pygame的基本使用、窗口初始化、事件处理、键盘控制移动、以及实现游戏逻辑和对象交互的方法。
|
2月前
|
SQL 关系型数据库 MySQL
干货!python与MySQL数据库的交互实战
干货!python与MySQL数据库的交互实战
|
2月前
|
C# Windows 开发者
当WPF遇见OpenGL:一场关于如何在Windows Presentation Foundation中融入高性能跨平台图形处理技术的精彩碰撞——详解集成步骤与实战代码示例
【8月更文挑战第31天】本文详细介绍了如何在Windows Presentation Foundation (WPF) 中集成OpenGL,以实现高性能的跨平台图形处理。通过具体示例代码,展示了使用SharpGL库在WPF应用中创建并渲染OpenGL图形的过程,包括开发环境搭建、OpenGL渲染窗口创建及控件集成等关键步骤,帮助开发者更好地理解和应用OpenGL技术。
117 0
|
2月前
|
机器学习/深度学习 存储 搜索推荐
Elasticsearch与深度学习框架的集成案例研究
Elasticsearch 是一个强大的搜索引擎和分析引擎,广泛应用于实时数据处理和全文搜索。深度学习框架如 TensorFlow 和 PyTorch 则被用来构建复杂的机器学习模型。本文将探讨如何将 Elasticsearch 与这些深度学习框架集成,以实现高级的数据分析和预测任务。
29 0
|
5月前
|
存储 SQL 监控
修改Zabbix源码实现监控数据双写,满足业务需求!
虽然对接Elasticsearch后有诸多好处,但是它不往数据库写历史数据了,同时还不再计算趋势数据了。有这么一个场景...
修改Zabbix源码实现监控数据双写,满足业务需求!
|
5月前
|
数据采集 监控 数据库
OceanBase社区版可以通过Zabbix监控
OceanBase社区版可以通过Zabbix监控
245 4

推荐镜像

更多