使用方法实例
示例 1
该示例示范了如何使用内置 MySQL 数据库、Zabbix server、基于 Nginx Web 服务器的 Zabbix Web 界面和 Zabbix Java gateway 来运行 Zabbix 应用。
The example demonstrates how to run Zabbix appliance with built-in MySQL database, Zabbix server, Zabbix web interface based on the Nginx web server and Zabbix Java gateway.
# docker run --name zabbix-appliance -t \
-p 10051:10051 \
-p 80:80 \
-d zabbix/zabbix-appliance:latest
Zabbix 应用实例将 10051/TCP 端口(Zabbix trapper)和80/TCP 端口(HTTP)暴露给主机。
Zabbix appliance instance exposes 10051/TCP port (Zabbix trapper) and 80/TCP port (HTTP) to host machine.
示例 2
该示例示范了如何运行 MySQL 数据库支持、基于 Nginx Web 服务器的 Zabbix Web 界面和 Zabbix Java gateway。
The example demonstrates how to run Zabbix server with MySQL database support, Zabbix web interface based on the Nginx web server and Zabbix Java gateway.
1. 首先,启动空的 MySQL 服务器实例。
1. 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" \
-d mysql:5.7 \
--character-set-server=utf8 --collation-server=utf8_bin
2. 其次,启动 Zabbix Java gateway 实例
2. Start Zabbix Java gateway instance
# docker run --name zabbix-java-gateway -t \
-d zabbix/zabbix-java-gateway:latest
3. 然后,启动 Zabbix server 实例,并将其关联到已创建的 MySQL server 实例。
3. 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" \
--link mysql-server:mysql \
--link zabbix-java-gateway:zabbix-java-gateway \
-p 10051:10051 \
-d zabbix/zabbix-server-mysql:latest
Zabbix server 实例将 10051/TCP 端口(Zabbix trapper)暴露给主机。
Zabbix server instance exposes 10051/TCP port (Zabbix trapper) to host machine.
4. 最后,启动 Zabbix Web 界面,并将其关联到已创建的 MySQL server 和 Zabbix server 实例。
4. 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 DB_SERVER_HOST="mysql-server" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="zabbix_pwd" \
-e MYSQL_ROOT_PASSWORD="root_pwd" \
--link mysql-server:mysql \
--link zabbix-server-mysql:zabbix-server \
-p 80:80 \
-d zabbix/zabbix-web-nginx-mysql:latest
Zabbix web 界面实例将 80/TCP 端口(HTTP)暴露给主机。
Zabbix web interface instance exposes 80/TCP port (HTTP) to host machine.
示例 3
该示例示范了如何运行 PostgreSQL 数据库支持的 Zabbix server、基于 Nginx Web 服务器的 Zabbix Web 界面和 SNMP trap功能。
The example demonstrates how to run Zabbix server with PostgreSQL database support, Zabbix web interface based on the Nginx web server and SNMP trap feature.
1. 首先,启动空的 PostgreSQL server 实例。
1. Start empty PostgreSQL server instance
# docker run --name postgres-server -t \
-e POSTGRES_USER="zabbix" \
-e POSTGRES_PASSWORD="zabbix" \
-e POSTGRES_DB="zabbix_pwd" \
-d postgres:latest
2. 其次,启动 Zabbix snmptraps 实例。
2. 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 \
-p 162:162/udp \
-d zabbix/zabbix-snmptraps:latest
Zabbix snmptrap 实例将 162/UDP 端口(SNMP traps)暴露给主机。
Zabbix snmptrap instance exposes the 162/UDP port (SNMP traps) to host machine.
3.然后,启动 Zabbix server 实例,并将其关联到已创建的 PostgreSQL server 实例。
3. 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" \
-e POSTGRES_DB="zabbix_pwd" \
-e ZBX_ENABLE_SNMP_TRAPS="true" \
--link postgres-server:postgres \
-p 10051:10051 \
--volumes-from zabbix-snmptraps \
-d zabbix/zabbix-server-pgsql:latest
Zabbix server 实例将 10051/TCP 端口(Zabbix trapper)暴露给主机。
Zabbix server instance exposes the 10051/TCP port (Zabbix trapper) to host machine.
4.最后,启动 Zabbix Web 界面,并将其关联到已创建的 PostgreSQL server 和 Zabbix server 实例。
4. 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 DB_SERVER_HOST="postgres-server" \
-e POSTGRES_USER="zabbix" \
-e POSTGRES_PASSWORD="zabbix" \
-e POSTGRES_DB="zabbix_pwd" \
--link postgres-server:postgres \
--link zabbix-server-pgsql:zabbix-server \
-p 443:443 \
-v /etc/ssl/nginx:/etc/ssl/nginx:ro \
-d zabbix/zabbix-web-nginx-pgsql:latest
Zabbix web 界面实例将 443/TCP 端口(HTTPS)暴露给主机。
/etc/ssl/nginx 目录必须包含具有所需名称的证书。.
Zabbix web interface instance exposes the 443/TCP port (HTTPS) to host machine.
Directory /etc/ssl/nginx must contain certificate with required name.
Docker Compose
Zabbix 为 Docker 提供了定义和运行复杂 Zabbix 组件的 compose 文件。这些 compose 文件可以在 github.com: https://github.com/zabbix/zabbix-docker 上的 Zabbix docker 官方镜像仓库中找到。这些 compose 文件作为示例添加,并支持广泛。例如,Zabbix proxy 支持 MySQL和 SQLite3。
Zabbix provides compose files also for defining and running multi-container Zabbix components in Docker. These compose files are available in Zabbix docker official repository on github.com: https://github.com/zabbix/zabbix-docker. These compose files are added as examples, they are overloaded. For example, they contain proxies with MySQL and SQLite3 support.
以下为几个不同版本的 compose 文件:
There are a few different versions of compose files:
文件名 描述
docker-compose_v3_alpine_mysql_latest.yaml 该 compose 文件运行基于 Alpine Linux 的 Zabbix 4.0 最新版本的组件,支持 MySQL 数据库。
docker-compose_v3_alpine_mysql_local.yaml 该 compose 文件本地构建和运行基于 Alpine Linux 的 Zabbix 4.0 最新版本的组件,支持 MySQL数据库。
docker-compose_v3_alpine_pgsql_latest.yaml 该 compose 文件运行基于 Alpine Linux 的 Zabbix 4.0 最新版本的组件,支持 PostgreSQL 数据库。
docker-compose_v3_alpine_pgsql_local.yaml 该 compose 文件本地构建和运行基于 Apline Linux 的 Zabbix 4.0 最新版本的组件,支持 PostgreSQL 数据库。
docker-compose_v3_centos_mysql_latest.yaml 该 compose 文件运行基于 CentOS7 的 Zabbix 4.0 最新版本的组件,支持 MySQL 数据库。
docker-compose_v3_centos_mysql_local.yaml 该 compose 文件本地构建和运行基于 CentOS7 的 Zabbix 4.0 最新版本的组件,支持 MySQL 数据库。
docker-compose_v3_centos_pgsql_latest.yaml 该 compose 文件运行基于 CentOS7 的 Zabbix 4.0 最新版本的组件,支持 PostgreSQL 数据库。
docker-compose_v3_centos_pgsql_local.yaml 该 compose 文件本地构建和运行基于 CentOS7 的 Zabbix 4.0 最新版本的组件,支持 PostgreSQL 数据库。
docker-compose_v3_ubuntu_mysql_latest.yaml 该 compose 文件运行基于 Ubuntu 14.04 的 Zabbix 4.0 最新版本的组件,支持 MySQL 数据库。
docker-compose_v3_ubuntu_mysq l_local.yaml 该 compose 文件本地构建和运行基于 Ubuntu 14.04 的 Zabbix 4.0 最新版本的组件,支持 MySQL 数据库。
docker-compose_v3_ubuntu_pgsql_latest.yaml 该 compose 文件运行基于 Ubuntu 14.04 的 Zabbix 4.0 最新版本的组件,支持 PostgreSQL 数据库。
docker-compose_v3_ubuntu_pgsql_local.yaml 该 compose 文件本地构建和运行基于 Ubuntu 14.04 的 Zabbix 4.0 最新版本的组件,支持 PosegreSQL 数据库。
Docker compose 文件支持 Docker Compose 2 版本和 Docker Compose 3版本。
Available Docker compose files support both versions 2 and 3 of Docker Compose.
存储
Compose 文件已经配置支持主机上的存储。当你使用 Compose 文件运行 Zabbix 组件时,Docker Compose 将在其所在文件夹中创建一个 zbx_env 目录,该目录将包含于 Volumes 章节所述相同的结构,以用于数据库存储。
Compose files are configured to support local storage on a host machine. Docker Compose will create a zbx_env directory in the folder with the compose file when you run Zabbix components using the compose file. The directory will contain the same structure as described above in the Volumes section and directory for database storage.
此外,还有卷 /etc/localtime 和 /etc/timezone 下的文件为只读模式。
There are also volumes in read-only mode for /etc/localtime and /etc/timezone files.
环境变量文件
在 github.com 上与存放 compose 文件的同一目录中,您可以在 compose 文件中找到每个组件的默认环境变量文件,这些环境变量文件的命令与 .env_<type of component> 类似。
In the same directory with compose files on github.com you can find files with default environment variables for each component in compose file. These environment files are named like .env_<type of component>.
示例
示例 1
# docker-compose -f ./docker-compose_v3_alpine_mysql_latest.yaml up -d
这个命令将会为每个 Zabbix 组件下载最新的 Zabbix 4.0 镜像,并以 detach 模式运行。
The command will download latest Zabbix 4.0 images for each Zabbix component and run them in detach mode.
不要忘记从 github.com 的 Zabbix 官方镜像仓库下载 .env_<type of component> 文件和 compose 文件。
Do not forget to download .env_<type of component> files from github.com official Zabbix repository with compose files.
示例 2
# docker-compose -f ./docker-compose_v3_ubuntu_mysql_local.yaml up -d
这个命令将会下载基于 Ubuntu 14.04 的镜像,并在本地构建 Zabbix 4.0 组件,以 detach 模式运行。
The command will download base image Ubuntu 14.04, then build Zabbix 4.0 components locally and run them in detach mode.