Docker映像的Zabbix组件安装


1、Zabbix为每个Zabbix组件提供Docker映像,作为可移植和自给自足的容器,以加快部署和更新过程。 Zabbix组件附带MySQL和PostgreSQL数据库支持、Apache2和nginxweb服务器支持。 这些  images被分成不同的  images

2、 Zabbix components are provided on Ubuntu, Alpine Linux and CentOS base images:

Image Version

alpine 3.12

ubuntu 20.04 (focal)

centos 8

All images are configured to rebuild latest images if base images are updated.

3、以下Dockerv repositories中提供了所有Zabbix组件:

Zabbix agent - 
Zabbix server
  • Zabbix server with MySQL database support - 
  • Zabbix server with PostgreSQL database support - 
Zabbix web-interface
  • Zabbix web-interface based on Apache2 web server with MySQL database support - 
  • Zabbix web-interface based on Apache2 web server with PostgreSQL database support - 
  • Zabbix web-interface based on Nginx web server with MySQL database support - 
  • Zabbix web-interface based on Nginx web server with PostgreSQL database support - 
Zabbix proxy
  • Zabbix proxy with SQLite3 database support - 
  • Zabbix proxy with MySQL database support - 

Zabbix Java Gateway - 

4、用法:

    所有Zabbix组件映像都提供环境变量来控制配置。 这些环境变量列在每个组件存储库中。 这些环境变量是Zabbix配置文件中的选项,但命名方法不同。 例如, ZBX_LOGSLOWQUERIES等价于来自Zabbix服务器和Zabbix代理配置文件的 LogSlowQueries

 Some of configuration options are not allowed to change. For example,  PIDFile and  LogType.
VOLUMES

images 允许使用一些挂载点。 这些 挂载点不同,取决于Zabbix组件类型。

5、示例1

示例演示了如何使用MySQL数据库支持运行Zabbix服务器、基于nginxweb服务器的Zabbix web界面和Zabbix Java网关。

1. Create network dedicated for Zabbix component containers:

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

2. Start empty MySQL server instance

# docker run --name mysql-server -t \
      -e MYSQL_DATABASE="zabbix" \
      -e MYSQL_USER="zabbix" \
      -e MYSQL_PASSWORD="zabbix_pwd" \
      -e MYSQL_ROOT_PASSWORD="root_pwd" \
      --network=zabbix-net \
      -d mysql:8.0 \
      --restart unless-stopped \              ()
      --character-set-server=utf8 --collation-server=utf8_bin \
      --default-authentication-plugin=mysql_native_password

3. Start Zabbix Java gateway instance

# docker run --name zabbix-java-gateway -t \
      --network=zabbix-net \
      --restart unless-stopped \
      -d zabbix/zabbix-java-gateway:alpine-5.2-latest

4. Start Zabbix server instance and link the instance with created MySQL server instance

# docker run --name zabbix-server-mysql -t \
      -e DB_SERVER_HOST="mysql-server" \
      -e MYSQL_DATABASE="zabbix" \
      -e MYSQL_USER="zabbix" \
      -e MYSQL_PASSWORD="zabbix_pwd" \
      -e MYSQL_ROOT_PASSWORD="root_pwd" \
      -e ZBX_JAVAGATEWAY="zabbix-java-gateway" \
      --network=zabbix-net \
      -p 10051:10051 \
      --restart unless-stopped \
      -d zabbix/zabbix-server-mysql:alpine-5.2-latest

Zabbix server instance exposes 10051/TCP port (Zabbix trapper) to host machine.

5. Start Zabbix web interface and link the instance with created MySQL server and Zabbix server instances

# 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="zabbix_pwd" \
      -e MYSQL_ROOT_PASSWORD="root_pwd" \
      --network=zabbix-net \
      -p 80:8080 \
      --restart unless-stopped \
      -d zabbix/zabbix-web-nginx-mysql:alpine-5.2-latest

Zabbix web interface instance exposes 80/TCP port (HTTP) to host machine.

5、示例2

该示例演示了如何使用PostgreSQL数据库支持运行Zabbix服务器,以及基于nginxweb服务器和SNMP陷阱特性的Zabbix web界面。

1. Create network dedicated for Zabbix component containers:

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

2. Start empty PostgreSQL server instance

# docker run --name postgres-server -t \
      -e POSTGRES_USER="zabbix" \
      -e POSTGRES_PASSWORD="zabbix_pwd" \
      -e POSTGRES_DB="zabbix" \
      --network=zabbix-net \
      --restart unless-stopped \
      -d postgres:latest

3. Start Zabbix snmptraps instance

# docker run --name zabbix-snmptraps -t \
      -v /zbx_instance/snmptraps:/var/lib/zabbix/snmptraps:rw \
      -v /var/lib/zabbix/mibs:/usr/share/snmp/mibs:ro \
      --network=zabbix-net \
      -p 162:1162/udp \
      --restart unless-stopped \
      -d zabbix/zabbix-snmptraps:alpine-5.2-latest

Zabbix snmptrap instance exposes the 162/UDP port (SNMP traps) to host machine.

4. Start Zabbix server instance and link the instance with created PostgreSQL server instance

# docker run --name zabbix-server-pgsql -t \
      -e DB_SERVER_HOST="postgres-server" \
      -e POSTGRES_USER="zabbix" \
      -e POSTGRES_PASSWORD="zabbix_pwd" \
      -e POSTGRES_DB="zabbix" \
      -e ZBX_ENABLE_SNMP_TRAPS="true" \
      --network=zabbix-net \
      -p 10051:10051 \
      --volumes-from zabbix-snmptraps \
      --restart unless-stopped \
      -d zabbix/zabbix-server-pgsql:alpine-5.2-latest

Zabbix server instance exposes the 10051/TCP port (Zabbix trapper) to host machine.

5. Start Zabbix web interface and link the instance with created PostgreSQL server and Zabbix server instances

# docker run --name zabbix-web-nginx-pgsql -t \
      -e ZBX_SERVER_HOST="zabbix-server-pgsql" \
      -e DB_SERVER_HOST="postgres-server" \
      -e POSTGRES_USER="zabbix" \
      -e POSTGRES_PASSWORD="zabbix_pwd" \
      -e POSTGRES_DB="zabbix" \
      --network=zabbix-net \
      -p 443:8443 \
      -p 80:8080 \
      -v /etc/ssl/nginx:/etc/ssl/nginx:ro \
      --restart unless-stopped \
      -d zabbix/zabbix-web-nginx-pgsql:alpine-5.2-latest

Zabbix web interface instance exposes the 443/TCP port (HTTPS) to host machine.
Directory  /etc/ssl/nginx must contain certificate with required name.

6、示例3( CentOS8 以上的版本默认已经安装一个等同于 Docker的容器解决方案,这个就是Podman

该示例演示了如何使用MySQL数据库支持运行Zabbix服务器、基于nginxweb服务器的Zabbix web界面以及使用redhat8上的podman运行Zabbix Java网关。

1. Create new pod with name  zabbix and exposed ports (web-interface, Zabbix server trapper):

podman pod create --name zabbix -p 80:8080 -p 10051:10051

2. (optional) Start Zabbix agent container in  zabbix pod location:

podman run --name zabbix-agent \
    -eZBX_SERVER_HOST="127.0.0.1,localhost" \
    --restart=always \
    --pod=zabbix \
    -d registry.connect.redhat.com/zabbix/zabbix-agent-50:latest

3. Create  ./mysql/ directory on host and start Oracle MySQL server 8.0:

podman run --name mysql-server -t \
      -e MYSQL_DATABASE="zabbix" \
      -e MYSQL_USER="zabbix" \
      -e MYSQL_PASSWORD="zabbix_pwd" \
      -e MYSQL_ROOT_PASSWORD="root_pwd" \
      -v ./mysql/:/var/lib/mysql/:Z \
      --restart=always \
      --pod=zabbix \
      -d mysql:8.0 \
      --character-set-server=utf8 --collation-server=utf8_bin \
      --default-authentication-plugin=mysql_native_password

3. Start Zabbix server container:

podman run --name zabbix-server-mysql -t \
                  -e DB_SERVER_HOST="127.0.0.1" \
                  -e MYSQL_DATABASE="zabbix" \
                  -e MYSQL_USER="zabbix" \
                  -e MYSQL_PASSWORD="zabbix_pwd" \
                  -e MYSQL_ROOT_PASSWORD="root_pwd" \
                  -e ZBX_JAVAGATEWAY="127.0.0.1" \
                  --restart=always \
                  --pod=zabbix \
                  -d registry.connect.redhat.com/zabbix/zabbix-server-mysql-50

4. Start Zabbix Java Gateway container:

podman run --name zabbix-java-gateway -t \
      --restart=always \
      --pod=zabbix \
      -d registry.connect.redhat.com/zabbix/zabbix-java-gateway-50

5. Start Zabbix web-interface container:

podman run --name zabbix-web-mysql -t \
                  -e ZBX_SERVER_HOST="127.0.0.1" \
                  -e DB_SERVER_HOST="127.0.0.1" \
                  -e MYSQL_DATABASE="zabbix" \
                  -e MYSQL_USER="zabbix" \
                  -e MYSQL_PASSWORD="zabbix_pwd" \
                  -e MYSQL_ROOT_PASSWORD="root_pwd" \
                  --restart=always \
                  --pod=zabbix \
                  -d registry.connect.redhat.com/zabbix/zabbix-web-mysql-50

Pod  zabbix exposes 80/TCP port (HTTP) to host machine from 8080/TCP of  zabbix-web-mysql container.

7、DOCKER COMPOSE( Available Docker compose files support version 3 of Docker Compose.

    Zabbix还提供用于在Docker中定义和运行多容器Zabbix组件的compose文件。这些 compose文件可以在Zabbix docker官方存储库中找到github.com网站: 。这些 compose文件是作为示例添加的,它们是重载的。例如,它们包含支持MySQL和SQLite3的代理。

8、

EXAMPLES

Example 1

# git checkout 5.2
# docker-compose -f ./docker-compose_v3_alpine_mysql_latest.yaml up -d

The command will download latest Zabbix 5.2 images for each Zabbix component and run them in detach mode.

Do not forget to download  .env_ files from github.com official Zabbix repository with compose files.

Example 2

# git checkout 5.2    (切换到新分支5.2)
# docker-compose -f ./docker-compose_v3_ubuntu_mysql_local.yaml up -d

The command will download base image Ubuntu 20.04 (focal), then build Zabbix 5.2 components locally and run them in detach mode.


请使用浏览器的分享功能分享到微信等