Docker映像的Zabbix元件安裝

mi_zy發表於2021-03-12


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_<type of component> 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.


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7970627/viewspace-2762647/,如需轉載,請註明出處,否則將追究法律責任。

相關文章