【Docker实战】云端监控新体验,打造强大的Zabbix主机监控解决方案

举报
wzsのcloud 发表于 2024/10/29 22:45:41 2024/10/29
【摘要】 华为云服务器Flexus X实例,以革命性柔性算力与卓越性能,重塑云端监控体验。携手Zabbix主机监控解决方案,为您打造前所未有的强大监控网络,不仅解决传统云服务固定规格、性能不稳等难题,更以超值价格助力企业轻松上云。

前言

华为云服务器Flexus X实例,以革命性柔性算力与卓越性能,重塑云端监控体验。携手Zabbix主机监控解决方案,为您打造前所未有的强大监控网络。Flexus X实例服务器携专属优惠震撼来袭,不仅解决传统云服务固定规格、性能不稳等难题,更以超值价格助力企业轻松上云。限时优惠,性能飞跃,体验跃级,让企业监控与管理更智能、更高效。立即行动,抓住上云好时机,与华为云Flexus X共创云端新未来!

链接直达:华为云Flexus云服务器X实例

image.png

Zabbix介绍

Zabbix是开源的监控解决方案,提供Web界面,监视分布式系统和网络。它具备强大的监控功能、灵活的报警机制、可视化报表,支持分布式监控和API接口。架构包括Zabbixserver、Zabbixagent和Zabbixfrontend。通过数据采集、传输、处理和展示,实现系统监控。配置简单,但需要一定学习成本。适合中小型企业和大型企业基础监控需求。

官方网站:https://www.zabbix.com/

官方文档:https://www.zabbix.com/manuals

image.png

环境规划

操作系统 mysql zabbix docker docker-compose 连接方式
Huawei Cloud EulerOS 2.0 mysql8.0 zabbix 6.2 27.1.1 2.29.1 本地==shell==

image.png

部署Zabbix流程

需要了解:

安装数据库

  • zabbix支持mysql 和 postgresql两种数据库,本次部署中使用mysql数据库
  • 拉取镜像,zabbix 6.x版本要求使用mysql:8.0
[root@flexusx-251f ~]# docker pull mysql8.0
8.0 Pulling from librarymysql
5e407bf3af90 Pull complete
bbcaa884ef4a Pull complete
c0ba5caab336 Pull complete
e1ac943225fe Pull complete
143875155e8f Pull complete
78accec1f909 Pull complete
0074132ff84a Pull complete
a92d978133e0 Pull complete
af33c7bb2ccb Pull complete
446b165975c9 Pull complete
e06f8455314d Pull complete
Digest sha25659ffecdae8d42a45fb9429d81524273e0e237f82f8335234bc4c65dfa3588975
Status Downloaded newer image for mysql8.0
docker.iolibrarymysql8.0

创建MySQL容器

[root@flexusx-251f ~]# mkdir /zabbix
[root@flexusx-251f ~]# cd /zabbix/
[root@flexusx-251f zabbix]# mkdir mysql
[root@flexusx-251f zabbix]# cd mysql/
[root@flexusx-251f mysql]# vim docker-compose.yaml
[root@flexusx-251f mysql]# cat docker-compose.yaml
version: '2'
services:
  mysql-server:
    image: mysql:8.0
    container_name: mysql-server
    volumes:
      - mysql_data:/var/lib/mysql
      - mysql_logs:/var/log/mysql
      - mysql_conf:/etc/mysql
    environment:
      - MYSQL_DATABASE=zabbix         # 创建数据库
      - MYSQL_USER=zabbix             # 数据用户名
      - MYSQL_PASSWORD=123456         # 配置密码
      - MYSQL_ROOT_PASSWORD=123456    # 创建root密码
    restart: always                   # 指定容器的重启策略为总是重启
    command: 
      - --character-set-server=utf8   # 设置 MySQL 服务器的字符集为utf8
      - --collation-server=utf8_bin   # 设置字符集的校对规则为utf8_bin
      - --default-authentication-plugin=mysql_native_password # 指定 MySQL 默认的身份验证插件为 mysql_native_password

volumes:
  mysql_data:        # 存放mysql数据
  mysql_logs:        # 存放mysql日志
  mysql_conf:        # 存放mysql配置文件
      
# 运行docker-compose
[root@flexusx-251f mysql]# docker-compose up -d
[+] Running 2/2
 ✔ Network mysql_default      Created                                                0.0s
 ✔ Container mysql-server  Started                                                0.2s

[root@flexusx-251f mysql]# docker-compose ps
NAME              IMAGE       COMMAND                  SERVICE        CREATED          STATUS          PORTS
mysql-server   mysql:8.0   "docker-entrypoint.s…"   mysql-server   23 seconds ago   Up 23 seconds   3306/tcp, 33060/tcp

安装zabbix-java-gateway

拉取镜像

[root@flexusx-251f ~]# docker pull zabbixzabbix-java-gatewayalpine-6.2-latest
alpine-6.2-latest Pulling from zabbixzabbix-java-gateway
4db1b89c0bd1 Pull complete
801245a95db6 Pull complete
ad95d76f2b34 Pull complete
e65ab8d56a50 Pull complete
4f4fb700ef54 Pull complete
8a40d64e57ad Pull complete
5a570aff53ef Pull complete
Digest sha256c44bee338bc1b989df67b59039d471d2f49621866fcd6a80b2e279e7fb73febe
Status Downloaded newer image for zabbixzabbix-java-gatewayalpine-6.2-latest
docker.iozabbixzabbix-java-gatewayalpine-6.2-latest

创建容器

[root@flexusx-251f ~]#  docker run -itd --name zabbix-java-gateway --restart=always zabbix/zabbix-java-gateway:alpine-6.2-latest
f191a940f6fcb9f56e46b5bcb752074aa669d4df7b8639ad7aed54d078778e73


[root@flexusx-251f ~]# docker ps | grep zabbix
f191a940f6fc   zabbix/zabbix-java-gateway:alpine-6.2-latest                               "docker-entrypoint.s…"   12 seconds ago   Up 11 seconds                   10052/tcp                                                                                        zabbix-java-gateway

安装zabbix-server

拉取镜像

[root@flexusx-251f ~]# docker pull zabbixzabbix-server-mysql6.2-alpine-latest
6.2-alpine-latest Pulling from zabbixzabbix-server-mysql
4db1b89c0bd1 Already exists
93b2dfbb63de Pull complete
b1f9e974b30d Pull complete
02002443a1f7 Pull complete
d08526b9c78a Pull complete
8f14959c4f68 Pull complete
31a8d6ba4322 Pull complete
4f4fb700ef54 Pull complete
6d1d7f9a139c Pull complete
Digest sha256854547f7b044c028aa7ff8ec9a96ad01e8b192ccc9b56f16c35eb13c57ca67f2
Status Downloaded newer image for zabbixzabbix-server-mysql6.2-alpine-latest
docker.iozabbixzabbix-server-mysql6.2-alpine-latest

创建数据卷,用于存储配置文件

[root@flexusx-251f ~]# docker volume create -d local zabbix_server
zabbix_server

[root@flexusx-251f ~]# docker volume ls | grep zabbix
local     zabbix_server

添加--link参数,实现mysqljava-gateway容器间的相互通信。

[root@flexusx-251f ~]# cd /zabbix/
[root@flexusx-251f zabbix]# mkdir zabbix-server
[root@flexusx-251f zabbix]# cd zabbix-server/
[root@flexusx-251f zabbix-server]# vim docker-compose.yaml
[root@flexusx-251f zabbix-server]# cat docker-compose.yaml
version: '2'
services:
  zabbix-server-mysql:
    image: zabbix/zabbix-server-mysql:6.2-alpine-latest
    container_name: zabbix-server-mysql
    volumes:
      - zabbix_server:/etc/zabbix
    environment:
      - DB_SERVER_HOST=mysql-server
      - MYSQL_DATABASE=zabbix
      - MYSQL_USER=zabbix
      - MYSQL_PASSWORD=123456
      - MYSQL_ROOT_PASSWORD=123456
      - ZBX_JAVAGATEWAY=zabbix-java-gateway
    links:
      - mysql-server:mysql
      - zabbix-java-gateway:zabbix-java-gateway
    restart: always
    ports:
      - 10051:10051

volumes:
  zabbix_server:
  

# 运行docker-compose
[root@flexusx-251f zabbix-server]# docker-compose up -d

# 查看容器(两种方式都可以)
[root@flexusx-251f zabbix-server]# docker-compose ps

[root@flexusx-251f ~]# docker ps | grep  zabbix-server
zabbix-server-mysql   zabbix/zabbix-server-mysql:6.2-alpine-latest                               "/sbin/tini -- /usr/…"   13 seconds ago   Up 12 seconds                   0.0.0.0:10051->10051/tcp, :::10051->10051/tcp    

安装zabbix-web界面

拉取镜像

[root@flexusx-251f ~]# docker pull zabbixzabbix-web-nginx-mysqlalpine-6.2-latest
alpine-6.2-latest Pulling from zabbixzabbix-web-nginx-mysql
4db1b89c0bd1 Already exists
d6f7f446ecd9 Pull complete
57e7f0986295 Pull complete
f7a7ad629618 Pull complete
4f4fb700ef54 Pull complete
09f1c858e155 Pull complete
Digest sha2562ecc13035b68b65650217ad55365a4677169fc9e09e27115de7af85c3dc8da2a
Status Downloaded newer image for zabbixzabbix-web-nginx-mysqlalpine-6.2-latest
docker.iozabbixzabbix-web-nginx-mysqlalpine-6.2-latest

创建web容器

[root@flexusx-251f ~]# cd /zabbix/
[root@flexusx-251f zabbix]# mkdir zabbix-web
[root@flexusx-251f zabbix]# cd zabbix-web/
[root@flexusx-251f zabbix-web]# vim docker-compose.yaml
[root@flexusx-251f zabbix-web]# cat docker-compose.yaml
version: '2'
services:
  zabbix-web-nginx-mysql:
    image: zabbix/zabbix-web-nginx-mysql:alpine-6.2-latest
    container_name: zabbix-web-nginx-mysql
    environment:
      - PHP_TZ=Asia/Shanghai
      - ZBX_SERVER_HOST=zabbix-server-mysql
      - DB_SERVER_HOST=mysql-server
      - MYSQL_DATABASE=zabbix
      - MYSQL_USER=zabbix
      - MYSQL_PASSWORD=123456
      - MYSQL_ROOT_PASSWORD=123456
    links:
      - mysql-server:mysql
      - zabbix-server-mysql:zabbix-server
    ports:
      - 8800:8080
    restart: always

# 查看容器
[root@flexusx-251f ~]# docker ps | grep  zabbix-web
eb577d1c9c52   zabbix/zabbix-web-nginx-mysql:alpine-6.2-latest                            "docker-entrypoint.sh"   6 seconds ago    Up 6 seconds                   8443/tcp, 0.0.0.0:80->8080/tcp, :::80->8080/tcp                                                  zabbix-web-nginx-mysql

登录Zabbix

配置安全组

放行端口号8800

image.png

测试访问

在浏览器导航栏输入地址:http://主机ip:8800

  • 账号:Admin
  • 密码:zabbix

image.png

登录成功,显示主界面

image.png

部署被监控端(Agent)

被监控端必须要安装Agent组件,这个组件是用来收集数据提交上监控端的.

因为本实例为华为公有云服务器,网络问题,所以我准备了一台本地虚拟机进行模拟测试,并不会真正被监管,不过所有操作和生产环境一致。

安装Agent

[root@docekr yum.repos.d]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   664  100   664    0     0   5773      0 --:--:-- --:--:-- --:--:--  5773

[root@docekr ~]# rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm
Retrieving https://mirrors.aliyun.com/zabbix/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:zabbix-release-3.4-1.el7.centos  ################################# [100%]


[root@docekr yum.repos.d]# sed -ie 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#g' /etc/yum.repos.d/zabbix.repo

[root@docekr yum.repos.d]# ls
bak  docker-ce.repo  epel.repo  os.repo  zabbix.repo  zabbix.repoe
[root@docekr yum.repos.d]#  yum makecache
Docker CE Stable - x86_64                                  27 kB/s | 3.5 kB     00:00
Extra Packages for Enterprise Linux 7 - x86_64             75 kB/s | 4.3 kB     00:00
AppStream                                                  31 kB/s | 4.3 kB     00:00
BaseOS                                                     29 kB/s | 3.9 kB     00:00
Zabbix Official Repository - x86_64                       306 kB/s | 141 kB     00:00
Zabbix Official Repository non-supported - x86_64         5.9 kB/s | 2.6 kB     00:00
Metadata cache created.

[root@docekr ~]# yum -y install zabbix-agent
Last metadata expiration check: 0:01:18 ago on Wed 11 Sep 2024 09:49:47 PM CST.
Dependencies resolved.
==========================================================================================
 Package                  Architecture   Version                  Repository         Size
==========================================================================================
Installing:
 zabbix-agent             x86_64         3.4.15-1.el7             zabbix            369 k
Installing dependencies:
 compat-openssl10         x86_64         1:1.0.2o-3.el8           AppStream         1.1 M
 make                     x86_64         1:4.2.1-10.el8           BaseOS            498 k

Transaction Summary
==========================================================================================
Install  3 Packages

Total download size: 2.0 M
Installed size: 5.9 M
Downloading Packages:
(1/3): make-4.2.1-10.el8.x86_64.rpm                       1.5 MB/s | 498 kB     00:00
(2/3): zabbix-agent-3.4.15-1.el7.x86_64.rpm               1.1 MB/s | 369 kB     00:00
(3/3): compat-openssl10-1.0.2o-3.el8.x86_64.rpm           2.9 MB/s | 1.1 MB     00:00
------------------------------------------------------------------------------------------
Total                                                     5.0 MB/s | 2.0 MB     00:00
warning: /var/cache/dnf/zabbix-bf7253d92810e84d/packages/zabbix-agent-3.4.15-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Zabbix Official Repository - x86_64                       1.6 MB/s | 1.7 kB     00:00
Importing GPG key 0xA14FE591:
 Userid     : "Zabbix LLC <packager@zabbix.com>"
 Fingerprint: A184 8F53 52D0 22B9 471D 83D0 082A B56B A14F E591
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                  1/1
  Installing       : make-1:4.2.1-10.el8.x86_64                                       1/3
  Running scriptlet: make-1:4.2.1-10.el8.x86_64                                       1/3
  Installing       : compat-openssl10-1:1.0.2o-3.el8.x86_64                           2/3
  Running scriptlet: compat-openssl10-1:1.0.2o-3.el8.x86_64                           2/3
  Running scriptlet: zabbix-agent-3.4.15-1.el7.x86_64                                 3/3
  Installing       : zabbix-agent-3.4.15-1.el7.x86_64                                 3/3
  Running scriptlet: zabbix-agent-3.4.15-1.el7.x86_64                                 3/3
  Verifying        : compat-openssl10-1:1.0.2o-3.el8.x86_64                           1/3
  Verifying        : make-1:4.2.1-10.el8.x86_64                                       2/3
  Verifying        : zabbix-agent-3.4.15-1.el7.x86_64                                 3/3

Installed:
  compat-openssl10-1:1.0.2o-3.el8.x86_64            make-1:4.2.1-10.el8.x86_64
  zabbix-agent-3.4.15-1.el7.x86_64

Complete!

编辑Zabbix Agent配置文件

[root@docekr ~]# vim /etc/zabbix/zabbix_agentd.conf
# 默认97行,指定server的IP,开启被动模式
 97 #Server=127.0.0.1
 98 Server=123.249.27.118

# 默认138行,指定server的IP,开启主动模式
139 #ServerActive=127.0.0.1
140 ServerActive=192.168.93.101

# 默认149行,此名称需要与等会server端的web界面监控的名称一致,这个名称是可以自定义的,但是等会web端如果监控这个主机,那么就需要是使用agent名称进行监控
149 # Hostname=
150 Hostname=docker

启动Zabbix Agent服务

[root@docekr ~]# systemctl start zabbix-agent.service
[root@docekr ~]# 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@docekr ~]# systemctl status zabbix-agent.service
● zabbix-agent.service - Zabbix Agent
   Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; enabled; vendor preset: >
   Active: active (running) since Wed 2024-09-11 21:54:50 CST; 8s ago
 Main PID: 14129 (zabbix_agentd)
    Tasks: 6 (limit: 12176)
   Memory: 4.2M
   CGroup: /system.slice/zabbix-agent.service
           ├─14129 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
           ├─14130 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
           ├─14131 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
           ├─14132 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
           ├─14133 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
           └─14134 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]

Sep 11 21:54:50 docekr systemd[1]: Starting Zabbix Agent...
Sep 11 21:54:50 docekr systemd[1]: zabbix-agent.service: Can't open PID file /run/zabbix/>
Sep 11 21:54:50 docekr systemd[1]: Started Zabbix Agent.

Zabbix Web前端监控Agent主机

添加主机

在Web界面左侧导航栏点击 Configuration,点击二级菜单选项Hosts,弹出页面,点击右上角Create Host

image.png

输入主机名,别名自定义,选择主机组Linux Server,添加agent IP地址,点击添加

image.png

状态过一会如果变成绿色证明监控成功

image.png

体验和感受

在数字化转型的浪潮中,云端监控已成为企业保障业务连续性与优化运营效率的关键。华为云服务器Flexus X实例,以其创新的柔性算力技术与卓越性能,携手Zabbix主机监控解决方案,共同开启云端监控新体验。

华为云服务器Flexus X实例以其灵活的资源配置、智能调度与加速技术,为Zabbix监控平台提供了坚实的底层支撑。无论是高并发数据处理,还是复杂监控场景下的实时响应,Flexus X实例都能游刃有余,确保监控数据的准确性与时效性。

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。