Deploy Zabbix Monitoring with Docker and Docker‑Compose on CentOS
This guide walks through preparing a CentOS 7 host, installing Docker, configuring a Zabbix server and MySQL containers, and optionally using docker‑compose to set up Zabbix components, including the web UI and agent, with detailed commands and volume mappings for persistent monitoring.
Preparation
Server IP: 172.19.204.200 running CentOS Linux release 7.6.1810 (Core).
Install Docker
Disable the firewall and SELinux, install required packages, add the Docker repository, install
docker-ce, start and enable the Docker service, verify the version, configure a Docker image accelerator, and restart Docker.
<code>systemctl stop firewalld
systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install -y docker-ce
systemctl start docker
systemctl enable docker
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
systemctl restart docker</code>Zabbix Server Deployment
Two installation methods are provided; both use Docker images. Method 1 follows the official Zabbix Docker guide, pulling images directly.
1) Start a MySQL container for Zabbix data
<code>docker run --name zabbix-mysql -t \
-p 3306:3306 \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="zabbix" \
-e MYSQL_ROOT_PASSWORD="zabbix" \
-v /home/zabbix/data:/var/lib/mysql \
-d mysql:5.7 \
--character-set-server=utf8 \
--collation-server=utf8_bin</code>This creates a persistent MySQL instance with UTF‑8 settings to store Zabbix data.
2) Launch the Zabbix server container
Prepare a configuration file (
zabbix_server.conf) and mount it into the container along with directories for scripts, modules, TLS files, etc.
<code>docker run --name zabbix-server-mysql -t \
-e DB_SERVER_HOST="zabbix-mysql" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="zabbix" \
-e MYSQL_ROOT_PASSWORD="zabbix" \
--link zabbix-mysql:mysql \
-v /home/zabbix/zabbixconfig:/etc/zabbix \
-v /home/zabbix/alertscripts:/usr/lib/zabbix/alertscripts \
-v /home/zabbix/externalscripts:/usr/lib/zabbix/externalscripts \
-v /home/zabbix/modules:/var/lib/zabbix/modules \
-v /home/zabbix/enc:/var/lib/zabbix/enc \
-v /home/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys \
-v /home/zabbix/ssl/certs:/var/lib/zabbix/ssl/certs \
-v /home/zabbix/ssl/keys:/var/lib/zabbix/ssl/keys \
-v /home/zabbix/ssl/ssl_ca:/var/lib/zabbix/ssl/ssl_ca \
-v /home/zabbix/snmptraps:/var/lib/zabbix/snmptraps \
-v /home/zabbix/export:/var/lib/zabbix/export \
-v /home/zabbix/mibs:/var/lib/zabbix/mibs \
-p 10051:10051 \
-d zabbix/zabbix-server-mysql:centos-latest</code>Key volume mappings:
/usr/lib/zabbix/alertscripts – custom alert scripts (AlertScriptsPath)
/usr/lib/zabbix/externalscripts – external checks (ExternalScripts)
/etc/zabbix – server configuration files
/var/lib/zabbix/modules – loadable modules
/var/lib/zabbix/enc – TLS related files
/var/lib/zabbix/ssh_keys – SSH keys for checks
/var/lib/zabbix/ssl/certs – client SSL certificates
/var/lib/zabbix/ssl/keys – client SSL private keys
/var/lib/zabbix/ssl/ssl_ca – CA certificates for server verification
/var/lib/zabbix/snmptraps – SNMP trap log location
/var/lib/zabbix/mibs – MIB files (no sub‑directories)
3) Start the Zabbix web front‑end
<code>docker run --rm --name zabbix-web-nginx-mysql -t \
-e DB_SERVER_HOST="zabbix-mysql" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="zabbix" \
-e MYSQL_ROOT_PASSWORD="zabbix" \
-e PHP_TZ="Asia/Shanghai" \
--link zabbix-mysql:mysql \
--link zabbix-server-mysql:zabbix-server \
-p 8080:80 \
-d zabbix/zabbix-web-nginx-mysql:latest</code>Ensure the
--linknames match the container names created earlier.
4) Verify all three containers are running
<code>docker ps
# Example output shows zabbix-web-nginx-mysql, zabbix-server-mysql, and mysql containers up and listening on the expected ports.</code>5) Install Zabbix agent on the host (non‑container)
<code>rpm -ivh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-agent-4.4.5-1.el7.x86_64.rpm
yum install -y zabbix-agent
# Edit /etc/zabbix/zabbix_agentd.conf
Server=172.17.0.3
ServerActive=172.17.0.3:10050
Hostname=Zabbix server
systemctl restart zabbix-agent
systemctl enable zabbix-agent</code>If the host uses Docker’s default bridge network, adjust
Serverin the agent config to point to the Docker‑host IP.
6) Access the Zabbix web UI
Open
http://<em>host‑ip</em>:8080, log in with user
Adminand password
zabbix. The interface defaults to English with a white background; language and theme can be changed via the user menu.
Alternative: Deploy with docker‑compose
Install docker‑compose
<code># curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version</code>Prepare configuration files
Create
zabbix_server.confand place it under
/opt/docker-zabbix-server/zabbix/zabbixconfig/.
docker‑compose.yml
<code>version: '3'
services:
zabbix-mysql:
image: mariadb:latest
ports:
- "3309:3306"
volumes:
- ./zabbix/data/mysqllib:/var/lib/mysql
environment:
- MYSQL_USER=zabbix
- MYSQL_DATABASE=zabbix
- MYSQL_PASSWORD=zabbix
- MYSQL_ROOT_PASSWORD=123321
- character-set-server=utf8
- collation-server=utf8_bin
restart: always
zabbix-server:
image: zabbix/zabbix-server-mysql:centos-latest
ports:
- "10052:10051"
environment:
- DB_SERVER_HOST=zabbix-mysql
- MYSQL_USER=zabbix
- MYSQL_DATABASE=zabbix
- MYSQL_PASSWORD=zabbix
- DB_SERVER_ROOT_USER=root
- DB_SERVER_ROOT_PASS=123321
- TZ='Asia/Shanghai'
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zabbix/zabbixconfig/:/etc/zabbix/
- ./zabbix/alertscripts:/usr/lib/zabbix/alertscripts
- ./zabbix/externalscripts:/usr/lib/zabbix/externalscripts
- ./zabbix/modules:/var/lib/zabbix/modules
- ./zabbix/enc:/var/lib/zabbix/enc
- ./zabbix/ssh_keys:/var/lib/zabbix/ssh_keys
- ./zabbix/ssl/certs:/var/lib/zabbix/ssl/certs
- ./zabbix/ssl/keys:/var/lib/zabbix/ssl/keys
- ./zabbix/ssl/ssl_ca:/var/lib/zabbix/ssl/ssl_ca
- ./zabbix/snmptraps:/var/lib/zabbix/snmptraps
- ./zabbix/mibs:/var/lib/zabbix/mibs
depends_on:
- zabbix-mysql
zabbix-web-nginx:
image: zabbix/zabbix-web-nginx-mysql:latest
ports:
- "8088:80"
environment:
- DB_SERVER_HOST=zabbix-mysql
- MYSQL_DATABASE=zabbix
- MYSQL_USER=zabbix
- MYSQL_PASSWORD=zabbix
- MYSQL_ROOT_PASSWORD=123321
- ZBX_SERVER_HOST=zabbix-server
- PHP_TZ='Asia/Shanghai'
- TZ='Asia/Shanghai'
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
links:
- zabbix-mysql
- zabbix-server
zabbix-agent:
image: zabbix/zabbix-agent:latest
environment:
- ZBX_HOSTNAME=Zabbix server
- ZBX_SERVER_HOST=zabbix-server
- ZBX_SERVER_PORT=10051
- TZ='Asia/Shanghai'
ports:
- "10053:10050"
restart: always
privileged: true
</code>For host‑level monitoring, it is recommended to install the native Zabbix agent via yum or binary rather than the containerized agent.
Deploy with docker‑compose
<code>docker-compose -f docker-compose.yml up -d</code>Check the status with
docker-compose ps; all services should be up and listening on the mapped ports.
Access the web UI
Open the mapped port (e.g.,
http://<em>host‑ip</em>:8088) and log in with the default credentials.
Zabbix Agent on Another Host
If Docker is available on the target host, use a docker‑compose file similar to the one above to run the agent container, adjusting the IP address in the environment variables.
<code>docker run -d \
--name zabbix-agent \
-e ZBX_HOSTNAME=172.19.204.201 \
-e ZBX_SERVER_HOST=172.19.204.200 \
-e ZBX_SERVER_PORT=10051 \
-e TZ='Asia/Shanghai' \
-p 10050:10050 \
--privileged zabbix/zabbix-agent:latest</code>If Docker is not installed, install the Zabbix agent via the RPM package as described earlier.
Ops Development Stories
Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.