Docker离线部署zabbix6.0

简介

由于离线环境安装zabbix服务端涉及的包比较多,较为繁琐,加上离线环境中可能有冲突的服务,故采用docker进行容器化部署较为方便

官方文档
https://www.zabbix.com/documentation/current/en/manual/installation/containers

docker hub
https://registry.hub.docker.com/r/zabbix/zabbix-agent

1.docker部署

先从在线环境获取相关安装包后,复制到离线环境安装

在线环境获取安装包

下载后的包会放在/var/cache/apt/archives下面,注意是以container和docker开头
apt-get install --download-only docker-ce docker-ce-cli containerd.io

离线环境安装docker

dpkg -i *.deb

启动docker并允许开机自启

systemctl start docker
systemctl enable docker

2.zabbix服务端部署

在线环境:Ubuntu18.04 离线环境:Ubuntu18.04
涉及到的主要镜像有mysql8,zabbix-java-gateway,zabbix-server-mysql,zabbix-web-nginx-mysql,zabbix-agent

在线服务器下载镜像

docker pull mysql:8.0
docker save -o ./mysql8.zip mysql:8.0

docker pull zabbix/zabbix-java-gateway:6.0-ubuntu-latest
docker save -o ./zabbix-java-gateway.zip zabbix/zabbix-java-gateway:6.0-ubuntu-latest

docker pull zabbix/zabbix-server-mysql:6.0-ubuntu-latest
docker save -o ./zabbix-server-mysql.zip zabbix/zabbix-server-mysql:6.0-ubuntu-latest

docker pull zabbix/zabbix-web-nginx-mysql:6.0-ubuntu-latest
docker save -o ./zabbix-web-nginx-mysql.zip zabbix/zabbix-web-nginx-mysql:6.0-ubuntu-latest

docker pull zabbix/zabbix-agent:6.0-ubuntu-latest
docker save -o ./zabbix-agent.zip zabbix/zabbix-agent:6.0-ubuntu-latest

离线服务器创建专用于Zabbix组件容器的网络

docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 zabbix-net

加载全部镜像

docker load -i ./mysql8.zip
docker load -i ./zabbix-java-gateway.zip
docker load -i ./zabbix-server-mysql.zip
docker load -i ./zabbix-web-nginx-mysql.zip
docker load -i ./zabbix-agent.zip

启动mysql

docker run --name mysql-server -t -p 3307:3306 -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="密码" -e MYSQL_ROOT_PASSWORD="密码" --network=zabbix-net --privileged=true -d mysql:8.0 --character-set-server=utf8 --collation-server=utf8_bin --default-authentication-plugin=mysql_native_password

启动zabbix-java-gateway

docker run --name zabbix-java-gateway -t --network=zabbix-net --restart unless-stopped --privileged=true -d zabbix/zabbix-java-gateway:6.0-ubuntu-latest
  

启动zabbix-server-mysql

docker run --name zabbix-server-mysql -e DB_SERVER_HOST="mysql-server" -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="密码" -e MYSQL_ROOT_PASSWORD="密码" -e ZBX_JAVAGATEWAY="zabbix-java-gateway" -v /opt/zabbix/zabbix_server.conf:/etc/zabbix/zabbix_server.conf --network=zabbix-net --ip 172.20.240.100 --privileged=true -p 10051:10051 --restart unless-stopped -d zabbix/zabbix-server-mysql:6.0-ubuntu-latest

启动zabbix-web-nginx-mysql

docker run --name zabbix-web-nginx-mysql -t -e ZBX_SERVER_HOST="zabbix-server-mysql" -e DB_SERVER_HOST="mysql-server" -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="密码" -e MYSQL_ROOT_PASSWORD="密码" --network=zabbix-net --privileged=true -p 8100:8080 --restart unless-stopped -d zabbix/zabbix-web-nginx-mysql:6.0-ubuntu-latest

启动zabbix-java-agent

docker inspect zabbix-server-mysql | grep "IPAddress"

docker run --name some-zabbix-agent -t -e ZBX_SERVER_HOST="172.20.240.100" -e ZBX_HOSTNAME="Zabbix server" --privileged=true --network=zabbix-net --ip 172.20.240.101 -d zabbix/zabbix-agent:6.0-ubuntu-latest

访问zabbix配置本地agent

登录网页配置zabbix server,其中IP为下面命令行查询的值,需要重新enable生效
docker inspect some-zabbix-agent | grep "IPAddress"

3.客户端离线安装(非docker部署)

先在对应有网系统下获取安装包,再放入离线服务器安装客户端

Ubuntu18.04

wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4+ubuntu18.04_all.deb
dpkg -i zabbix-release_6.0-4+ubuntu18.04_all.deb
apt update
apt-get install --print-uris zabbix-agent
根据链接下载所有相关包,放入离线服务器后
dpkg -i *.deb
vi /etc/zabbix/zabbix_agentd.conf
systemctl restart zabbix-agent
systemctl enable zabbix-agent

Ubuntu20.04

wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4+ubuntu20.04_all.deb
dpkg -i zabbix-release_6.0-4+ubuntu20.04_all.deb
apt update
apt-get install --print-uris zabbix-agent
根据链接下载所有相关包,放入离线服务器后
dpkg -i *.deb
vi /etc/zabbix/zabbix_agentd.conf
systemctl restart zabbix-agent
systemctl enable zabbix-agent

Centos6.8

直接安装
rpm -Uvh zabbix-agent-6.0.23-release1.el6.x86_64.rpm
允许修改文件
chattr -i /etc/group
chattr -i /etc/passwd
chattr -i /etc/shadow
添加用户和组
groupadd zabbix
useradd zabbix -g zabbix -s /bin/false
还原命令
chattr +i /etc/group
chattr +i /etc/passwd
chattr +i /etc/shadow
权限不足问题处理
mkdir -p /var/log/zabbix
chmod 755 /var/log/zabbix
cd /var/run
chown -R zabbix:zabbix zabbix
chown zabbix:zabbix /var/log/zabbix
修改配置文件
vi /etc/zabbix/zabbix_agentd.conf
启动服务
service zabbix-agent restart

Centos7

服务器架构如下:
[root@node1 zabbix]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
[root@node1 zabbix]# uname -m
x86_64
需保持一致

curl -o zabbix-release-6.0-4.el7.noarch.rpm https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpm
rpm -Uvh zabbix-release-6.0-4.el7.noarch.rpm
yum install yum-utils
yumdownloader --resolve zabbix-agent
根据链接下载所有相关包,放入离线服务器后
rpm -Uvh *.rpm
再安装zabbix-agent

vi /etc/zabbix/zabbix_agentd.conf
systemctl restart zabbix-agent
systemctl enable zabbix-agent

防火墙允许
firewall-cmd --permanent --zone=public --add-source=192.168.1.1
firewall-cmd --permanent --zone=public --add-port=10050/tcp
firewall-cmd --reload
firewall-cmd --zone=public --list-all

针对使用root用户启动的情况:
User=root
AllowRoot=1 

vi /usr/lib/systemd/system/zabbix-agent.service
User=root
Group=root

systemctl daemon-reload
systemctl restart zabbix-agent
systemctl enable zabbix-agent

SUSE Linux Enterprise Server 12

服务器架构如下:
Esightserver:~ # lsb-release -a
LSB Version:    n/a
Distributor ID: SUSE
Description:    SUSE Linux Enterprise Server 12 SP4
Release:        12.4
Codename:       n/a
[root@node1 zabbix]# uname -m
x86_64

使用有网服务器的docker拉取类似的镜像
docker run -it --name my_sles_container barebuild/sles:12 /bin/bash
下载相关包
rpm -Uvh --nosignature https://repo.zabbix.com/zabbix/6.0/sles/12/x86_64/zabbix-release-6.0-3.sles12.noarch.rpm
zypper --gpg-auto-import-keys refresh 'Zabbix Official Repository'
网上下载libpcre2-8-0并安装
rpm -Uvh libpcre2-8-0-10.39-150400.4.6.1.x86_64.rpm
获取zabbix-agent相关包
zypper install --download-only zabbix-agent
三个包放入离线服务器(/var/cache/zypp/packages)
rpm -Uvh libpcre2-8-0-10.39-150400.4.6.1.x86_64.rpm
rpm -Uvh logrotate-3.11.0-2.14.1.x86_64.rpm
rpm -Uvh zabbix-agent-6.0.33-release2.sles12.x86_64.rpm

vi /etc/zabbix/zabbix_agentd.conf
systemctl restart zabbix-agent
systemctl enable zabbix-agent

4.zabbix代理部署

解决客户端和服务端无法直接通信的问题
在线环境:Ubuntu18.04 离线环境:Ubuntu18.04

在线服务器下载镜像

docker pull mysql:8.0
docker save -o ./mysql8.zip mysql:8.0

docker pull zabbix/zabbix-proxy-mysql:6.0-ubuntu-latest
docker save -o ./zabbix-proxy-mysql.zip zabbix/zabbix-proxy-mysql:6.0-ubuntu-latest

离线服务器创建专用于Zabbix组件容器的网络

docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 zabbix-net

加载全部镜像

docker load -i ./mysql8.zip
docker load -i ./zabbix-proxy-mysql.zip

启动mysql

docker run --name mysql-server -t -p 3306:3306 -e MYSQL_DATABASE="zabbix_proxy" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="密码" -e MYSQL_ROOT_PASSWORD="密码" --network=zabbix-net --privileged=true -d mysql:8.0 --character-set-server=utf8 --collation-server=utf8_bin --default-authentication-plugin=mysql_native_password

启动proxy

docker run --name zabbix-proxy-mysql -t -e DB_SERVER_HOST="mysql-server" -e MYSQL_DATABASE="zabbix_proxy" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="密码" -e ZBX_HOSTNAME="Zabbix Proxy" -e ZBX_SERVER_HOST="192.168.0.237" -e ZBX_TIMEOUT="30" -e ZBX_CONFIGFREQUENCY="300" -e ZBX_DATASENDERFREQUENCY=3 --network=zabbix-net --link mysql-server:mysql -p 10051:10051 -d zabbix/zabbix-proxy-mysql:6.0-ubuntu-latest

Docker离线部署zabbix6.0
http://example.com/2024/09/30/docker-zabbix/
作者
WLK
发布于
2024年9月30日
许可协议