【Zabbix】Zabbix 分布式监控—创建Proxy主机

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: 【Zabbix】Zabbix 分布式监控—创建Proxy主机

Zabbix三种架构

Server-Agent

Server-Node-Agent

Server-Proxy-Agent


配置介绍

Zabbix Proxy的配置

  • Server-Node-Agent
  • Server-Proxy-Agent


1、配置proxy主机

① 安装相应的zabbix包
zabbix-proxy-mysql zabbix-get zabbix-agent zabbix-sender
② 准备数据库
创建、授权用户、导入schema.sql
③ 修改配置文件
④ 在server端添加此Proxy
Administration ——> Proxies
⑤ 在Server端配置通过此Proxy监控的主机

注意:zabbix agent端要允许zabbix proxy主机执行数据采集操作


实战演练—分布式监控

实验部署架构

主机名称 IP地址 服务角色 架构类型
zabbix-server 192.168.200.60 Zabbix 监控端 /

zabbix-agent-centos 192.168.200.70 Zabbix 客户端 Server-Agent
zbxproxy 192.168.200.90 Zabbix Proxy /

zabbix-agent-02 192.168.200.100 Zabbix 客户端 Server-Proxy-Agent


1、实验前期准备(Server端、Proxy端)

配置服务端和代理端时间同步

# 服务端和代理端安装ntpdate服务包
yum install -y ntpdate
# 服务端和代理端同步阿里云时间服务器
ntpdate ntp1.aliyun.com

关闭防火墙、SELinux安全模式

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
getenforce
iptables -nL

设置主机名

[root@zabbix-server ~]# hostnamectl set-hostname zabbix-server 
[root@zabbix-proxy ~]# hostnamectl set-hostname zbxproxy.xybdiy.com
[root@zabbix-agent-02 ~]# hostnamectl set-hostname zabbix-agent-02

配置域名解析

[root@zabbix-agent-02 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.60  zabbix-server
192.168.200.90  zbxproxy.xybdiy.com zbxproxy
192.168.200.100 zabbix-agent-02

zabbix-server 直接监控一台主机zabbix-agent-centos

zabbix-server 通过代理zbproxy 监控zabbix-agent-02

2、在代理服务器上配置MySQL

  • 创建MariaDB.repo
[root@zbproxy yum.repos.d]# vim mariadb.repo
[root@zbproxy yum.repos.d]# cat mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64/
gpgkey=http://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
  • 安装mariadb
[root@zbproxy ~]# yum install -y MariaDB-server MariaDB-client

cf379a8aa2d5c43c30fd84a3f0a24cdb.png

  • 修改数据库配置文件
[root@zbproxy ~]# vim /etc/my.cnf.d/server.cnf 
[mysqld]
skip_name_resolve = ON      # 跳过主机名解析
innodb_file_per_table = ON    # 开启独立表空间
innodb_buffer_pool_size = 256M  # 缓存池大小
max_connections = 2000      # 最大连接数
log-bin = master-log      # 开启二进制日志
  • 启动数据库服务
[root@zbproxy ~]# systemctl start mariadb
[root@zbproxy ~]# systemctl enable mariadb

  • 初始化数据库
[root@zbproxy ~]# mysql_secure_installation 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): 
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y     
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
 ... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@zbproxy ~]# mysql -uroot -p000
  • 创建数据库 和 授权用户
# 创建数据库zbxproxydb
MariaDB [(none)]> create database zbxproxydb character set 'utf8';
Query OK, 1 row affected (0.00 sec)
# 授权用户zbxproxydb
MariaDB [(none)]> grant all on zbxproxydb.* to 'zbxproxyuser'@'192.168.200.%' identified by 'zbxproxypass';
Query OK, 0 rows affected (0.00 sec)
# 刷新,重新加载
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
# 退出
MariaDB [(none)]> exit
Bye
[root@zbproxy ~]# 

3、在代理服务器上下载zabbix相应的包。

主要是代理proxy的包

[root@zbproxy src]# yum localinstall zabbix-agent-5.0.20-1.el7.x86_64.rpm zabbix-p

d905e9c44ba0c3a574c1bbfc3b554638.png

  • 初始化数据库
#查询数据库包
[root@zbproxy src]# rpm -ql zabbix-proxy-mysql
/etc/logrotate.d/zabbix-proxy
/etc/zabbix/zabbix_proxy.conf
/usr/lib/systemd/system/zabbix-proxy.service
/usr/lib/tmpfiles.d/zabbix-proxy.conf
/usr/lib/zabbix/externalscripts
/usr/sbin/zabbix_proxy_mysql
/usr/share/doc/zabbix-proxy-mysql-5.0.20
/usr/share/doc/zabbix-proxy-mysql-5.0.20/AUTHORS
/usr/share/doc/zabbix-proxy-mysql-5.0.20/COPYING
/usr/share/doc/zabbix-proxy-mysql-5.0.20/ChangeLog
/usr/share/doc/zabbix-proxy-mysql-5.0.20/NEWS
/usr/share/doc/zabbix-proxy-mysql-5.0.20/README
/usr/share/doc/zabbix-proxy-mysql-5.0.20/schema.sql.gz
/usr/share/man/man8/zabbix_proxy.8.gz
/var/log/zabbix
/var/run/zabbix

zabbix-proxymysql 包里带有导入数据的文件schema.sql.gz

# 复制schema.sql.gz
[root@zbproxy ~]# cp /usr/share/doc/zabbix-proxy-mysql-5.0.20/schema.sql.gz .
[root@zbproxy ~]# ls
anaconda-ks.cfg  schema.sql.gz
# 解压
[root@zbproxy ~]# gzip -d schema.sql.gz 
[root@zbproxy ~]# ls
anaconda-ks.cfg  schema.sql
# 导入数据,出现以下问题
[root@zbproxy ~]# mysql -uroot -p000 < schema.sql 
ERROR 1046 (3D000) at line 1: No database selected
解决办法:
[root@zbproxy ~]# vim schema.sql 
在首部添加如下内容:
USE zbxproxydb;
按:wq保存退出
[root@zbproxy ~]# mysql -uroot -p000 < schema.sql 
  • 查看数据已经生成
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| zbxproxydb         |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> use zbxproxydb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [zbxproxydb]> show tables;
+----------------------------+
| Tables_in_zbxproxydb       |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
| auditlog_details           |
| autoreg_host               |
| conditions                 |
| config                     |
| config_autoreg_tls         |
| corr_condition             |
| corr_condition_group       |
| corr_condition_tag         |
| corr_condition_tagpair     |
| corr_condition_tagvalue    |
| corr_operation             |
| correlation                |
| dashboard                  |
| dashboard_user             |
| dashboard_usrgrp           |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_suppress             |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| history                    |
| history_log                |
| history_str                |
| history_text               |
| history_uint               |
| host_discovery             |
| host_inventory             |
| host_tag                   |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| hstgrp                     |
| httpstep                   |
| httpstep_field             |
| httpstepitem               |
| httptest                   |
| httptest_field             |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
| interface                  |
| interface_discovery        |
| interface_snmp             |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| item_preproc               |
| item_rtdata                |
| items                      |
| items_applications         |
| lld_macro_path             |
| lld_override               |
| lld_override_condition     |
| lld_override_opdiscover    |
| lld_override_operation     |
| lld_override_ophistory     |
| lld_override_opinventory   |
| lld_override_opperiod      |
| lld_override_opseverity    |
| lld_override_opstatus      |
| lld_override_optag         |
| lld_override_optemplate    |
| lld_override_optrends      |
| maintenance_tag            |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| mappings                   |
| media                      |
| media_type                 |
| media_type_message         |
| media_type_param           |
| module                     |
| opcommand                  |
| opcommand_grp              |
| opcommand_hst              |
| opconditions               |
| operations                 |
| opgroup                    |
| opinventory                |
| opmessage                  |
| opmessage_grp              |
| opmessage_usr              |
| optemplate                 |
| problem                    |
| problem_tag                |
| profiles                   |
| proxy_autoreg_host         |
| proxy_dhistory             |
| proxy_history              |
| regexps                    |
| rights                     |
| screen_user                |
| screen_usrgrp              |
| screens                    |
| screens_items              |
| scripts                    |
| service_alarms             |
| services                   |
| services_links             |
| services_times             |
| sessions                   |
| slides                     |
| slideshow_user             |
| slideshow_usrgrp           |
| slideshows                 |
| sysmap_element_trigger     |
| sysmap_element_url         |
| sysmap_shape               |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| tag_filter                 |
| task                       |
| task_acknowledge           |
| task_check_now             |
| task_close_problem         |
| task_data                  |
| task_remote_command        |
| task_remote_command_result |
| task_result                |
| timeperiods                |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
| widget                     |
| widget_field               |
+----------------------------+
166 rows in set (0.00 sec)
MariaDB [zbxproxydb]> 

4、配置proxy端

[root@zbproxy ~]# vim /etc/zabbix/zabbix_proxy.conf 
Server=192.168.200.60     # server 的IP
ServerPort=10051        # server 的端口
Hostname=zbxproxy.xybdiy.com  # 主机名
ListenPort=10051        # proxy自己的监听端口
EnableRemoteCommands=1      # 允许远程命令
LogRemoteCommands=1       # 记录远程命令的日志
DBHost=192.168.200.90
DBName=zbxproxydb
DBUser=zbxproxyuser
DBPassword=zbxproxypass
ConfigFrequency=30        # 意思是多长时间去服务端拖一次有自己监控的操作配置,为了实验更快的生效。这里设置30秒,默认3600s
DataSenderFrequency=1     # 每一秒向server 端发一次数据,发送频度

开启proxy服务

[root@zbxproxy zabbix]# systemctl start zabbix-proxy
[root@zbxproxy zabbix]# systemctl enable zabbix-proxy

5、配置Agent端允许proxy代理监控

[root@zabbix-agent-02 ~]# vim /etc/zabbix/zabbix_agentd.conf 
Server=192.168.200.60,192.168.200.90
ServerActive=192.168.200.60,192.168.200.90
[root@zabbix-agent-02 ~]# systemctl restart zabbix-agent

6、把代理加入监控server 创建配置agent代理

  • 创建agent代
  • e11d337d1cfcbf17069032dcbf023d2f.png
  • 配置

28fe4e0fae37ae9562f05a2798c8d5e6.png

524b9e29a1f59320b2f6143e155e98f1.png

  • 创建agent端主机并采用代理监控

9586759bf286407d4a1b9cbab808634b.png

497ef3408cf486a42e7daba88244d5da.png

f354000a7b0a7d452f972cdf17784fff.png

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
9天前
|
存储 缓存 监控
|
1月前
|
监控 Java 应用服务中间件
tomcat相关概念与部署tomcat多实例-zabbix监控(docker部署)
通过上述步骤,您可以在Ubuntu系统上成功编译并安装OpenCV 4.8。这种方法不仅使您能够定制OpenCV的功能,还可以优化性能以满足特定需求。确保按照每一步进行操作,以避免常见的编译问题。
61 23
|
1月前
|
监控 Java 应用服务中间件
tomcat相关概念与部署tomcat多实例-zabbix监控(docker部署)
通过上述步骤,您可以在Ubuntu系统上成功编译并安装OpenCV 4.8。这种方法不仅使您能够定制OpenCV的功能,还可以优化性能以满足特定需求。确保按照每一步进行操作,以避免常见的编译问题。
53 22
|
1月前
|
监控 Java 应用服务中间件
tomcat相关概念与部署tomcat多实例-zabbix监控(docker部署)
通过上述步骤,您可以在Ubuntu系统上成功编译并安装OpenCV 4.8。这种方法不仅使您能够定制OpenCV的功能,还可以优化性能以满足特定需求。确保按照每一步进行操作,以避免常见的编译问题。
70 25
|
2月前
|
监控 数据可视化 Java
zabbix全面的监控能力
zabbix全面的监控能力
134 7
|
8天前
|
NoSQL Java 中间件
【📕分布式锁通关指南 02】基于Redis实现的分布式锁
本文介绍了从单机锁到分布式锁的演变,重点探讨了使用Redis实现分布式锁的方法。分布式锁用于控制分布式系统中多个实例对共享资源的同步访问,需满足互斥性、可重入性、锁超时防死锁和锁释放正确防误删等特性。文章通过具体示例展示了如何利用Redis的`setnx`命令实现加锁,并分析了简化版分布式锁存在的问题,如锁超时和误删。为了解决这些问题,文中提出了设置锁过期时间和在解锁前验证持有锁的线程身份的优化方案。最后指出,尽管当前设计已解决部分问题,但仍存在进一步优化的空间,将在后续章节继续探讨。
432 131
【📕分布式锁通关指南 02】基于Redis实现的分布式锁
|
12天前
|
NoSQL Java Redis
Springboot使用Redis实现分布式锁
通过这些步骤和示例,您可以系统地了解如何在Spring Boot中使用Redis实现分布式锁,并在实际项目中应用。希望这些内容对您的学习和工作有所帮助。
137 83
|
4月前
|
NoSQL Java Redis
太惨痛: Redis 分布式锁 5个大坑,又大又深, 如何才能 避开 ?
Redis分布式锁在高并发场景下是重要的技术手段,但其实现过程中常遇到五大深坑:**原子性问题**、**连接耗尽问题**、**锁过期问题**、**锁失效问题**以及**锁分段问题**。这些问题不仅影响系统的稳定性和性能,还可能导致数据不一致。尼恩在实际项目中总结了这些坑,并提供了详细的解决方案,包括使用Lua脚本保证原子性、设置合理的锁过期时间和使用看门狗机制、以及通过锁分段提升性能。这些经验和技巧对面试和实际开发都有很大帮助,值得深入学习和实践。
太惨痛: Redis 分布式锁 5个大坑,又大又深, 如何才能 避开 ?
|
7天前
|
缓存 NoSQL 搜索推荐
【📕分布式锁通关指南 03】通过Lua脚本保证redis操作的原子性
本文介绍了如何通过Lua脚本在Redis中实现分布式锁的原子性操作,避免并发问题。首先讲解了Lua脚本的基本概念及其在Redis中的使用方法,包括通过`eval`指令执行Lua脚本和通过`script load`指令缓存脚本。接着详细展示了如何用Lua脚本实现加锁、解锁及可重入锁的功能,确保同一线程可以多次获取锁而不发生死锁。最后,通过代码示例演示了如何在实际业务中调用这些Lua脚本,确保锁操作的原子性和安全性。
35 6
【📕分布式锁通关指南 03】通过Lua脚本保证redis操作的原子性
|
20天前
|
缓存 NoSQL 中间件
Redis,分布式缓存演化之路
本文介绍了基于Redis的分布式缓存演化,探讨了分布式锁和缓存一致性问题及其解决方案。首先分析了本地缓存和分布式缓存的区别与优劣,接着深入讲解了分布式远程缓存带来的并发、缓存失效(穿透、雪崩、击穿)等问题及应对策略。文章还详细描述了如何使用Redis实现分布式锁,确保高并发场景下的数据一致性和系统稳定性。最后,通过双写模式和失效模式讨论了缓存一致性问题,并提出了多种解决方案,如引入Canal中间件等。希望这些内容能为读者在设计分布式缓存系统时提供有价值的参考。感谢您的阅读!
110 6
Redis,分布式缓存演化之路

热门文章

最新文章

推荐镜像

更多