Deploy Zabbix Monitoring with Docker Compose: A Complete Step‑by‑Step Guide
This tutorial walks you through installing Zabbix server and agent using Docker Compose, configuring MySQL, setting up automatic agent registration, creating custom dashboards, and optionally integrating LDAP authentication, providing all commands and configuration details for a production‑ready monitoring stack.
Introduction
Zabbix is an enterprise‑grade, distributed, open‑source monitoring solution that can monitor applications, databases, networks, and operating systems, and since version 6.x also supports Kubernetes monitoring. This article explains how to implement host monitoring with Zabbix.
Install Zabbix Server with Docker Compose
We use Docker Compose to set up a Zabbix monitoring stack.
# Pull images
docker pull zabbix/zabbix-server-mysql:6.4.1-centos
docker pull zabbix/zabbix-web-nginx-mysql:6.4.1-centos
# Create data directories
mkdir -p zabbix/{data,alertscripts}
mkdir -p zabbix/mysql/{data,conf}
cd zabbix/
# MySQL configuration
cat > mysql/conf/my.cnf <<eof
[client]
default-character-set = utf8
[mysqld]
character-set-server = utf8
collation-server = utf8_bin
default_storage_engine = InnoDB
port = 3306
datadir = /var/lib/mysql
max_connections=1000
expire_logs_days = 15
relay_log_purge = 1
slow_query_log_file = /var/log/mysql/slow.log
log-error = /var/log/mysql/error.log
log-bin = /var/log/mysql/mysql-bin.log
default_authentication_plugin = mysql_native_password
socket = /tmp/mysql.sock
lower_case_table_names = 1
sql_mode = NO_ENGINE_SUBSTITUTION
default-time_zone='+8:00'
eof
chmod 644 mysql/conf/my.cnf
# Docker‑compose file
cat > docker-compose.yml <<eof
version: '3.9'
networks:
zbx:
driver: bridge
services:
zabbix-mysql:
image: mysql:8.0.30
hostname: mysql
container_name: mysql
volumes:
- /etc/localtime:/etc/localtime:ro
- ./mysql/conf/my.cnf:/etc/my.cnf
- ./mysql/data:/var/lib/mysql
restart: always
privileged: true
command: --character-set-server=utf8 --collation-server=utf8_bin
environment:
- MYSQL_ROOT_PASSWORD=Egfi9Jnn9BzJf3Q6
- MYSQL_DATABASE=zabbix
- MYSQL_USER=zabbix
- MYSQL_PASSWORD=zabbix
- TZ=Asia/Shanghai
- LANG=en_US.UTF-8
ports:
- 3306:3306
networks:
- zbx
zabbix-server:
image: zabbix/zabbix-server-mysql:6.4.1-centos
container_name: zabbix-server
volumes:
- /etc/localtime:/etc/localtime:ro
- ./data:/var/lib/zabbix/
- ./alertscripts:/usr/lib/zabbix/alertscripts:ro
restart: always
privileged: true
environment:
- DB_SERVER_HOST=zabbix-mysql
- DB_SERVER_PORT=3306
- MYSQL_ROOT_PASSWORD=Egfi9Jnn9BzJf3Q6
- MYSQL_DATABASE=zabbix
- MYSQL_USER=zabbix
- MYSQL_PASSWORD=zabbix
- ZBX_CACHESIZE=1G
- ZBX_HISTORYCACHESIZE=512M
- ZBX_HISTORYINDEXCACHESIZE=32M
- ZBX_TRENDCACHESIZE=256M
- ZBX_VALUECACHESIZE=256M
- ZBX_STARTPINGERS=64
- ZBX_IPMIPOLLERS=1
- ZBX_ENABLE_SNMP_TRAPS=true
- ZBX_STARTTRAPPERS=1
ports:
- 10051:10051
networks:
- zbx
zabbix-web:
image: zabbix/zabbix-web-nginx-mysql:6.4.1-centos
container_name: zabbix-web
volumes:
- /etc/localtime:/etc/localtime:ro
restart: always
privileged: true
environment:
- ZBX_SERVER_NAME=Zabbix 6.0
- ZBX_SERVER_HOST=zabbix-server
- ZBX_SERVER_PORT=10051
- DB_SERVER_HOST=zabbix-mysql
- DB_SERVER_PORT=3306
- MYSQL_ROOT_PASSWORD=Egfi9Jnn9BzJf3Q6
- MYSQL_DATABASE=zabbix
- MYSQL_USER=zabbix
- MYSQL_PASSWORD=zabbix
- PHP_TZ=Asia/Shanghai
ports:
- 80:8080
networks:
- zbx
eof
# Start services
docker compose up zabbix-mysql -d && sleep 5
docker compose up -dAfter the services start, you can log in to the web UI with the default credentials Admin / zabbix .
Install Zabbix Agent
The Zabbix agent collects host metrics. The guide uses the binary package method; for many hosts, Ansible is recommended.
# Download binary package
wget -c https://cdn.zabbix.com/zabbix/binaries/stable/6.4/6.4.1/zabbix_agent-6.4.1-linux-3.0-amd64-static.tar.gz
mkdir -p /usr/local/zabbix
tar xf zabbix_agent-6.4.1-linux-3.0-amd64-static.tar.gz -C /usr/local/zabbix
# Create zabbix user
useradd -s /sbin/nologin -M zabbix
chown -R zabbix.root /usr/local/zabbix
# Create configuration file
rm -rf /usr/local/zabbix/conf/zabbix_agentd/*
cat > /usr/local/zabbix/conf/zabbix_agentd.conf <<eof
PidFile=/usr/local/zabbix/logs/zabbix_agentd.pid
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
LogFileSize=100
ListenPort=10050
StartAgents=2
Server=172.16.110.169
ServerActive=172.16.110.169
HostMetadata=basic
Include=/usr/local/zabbix/conf/zabbix_agentd/*.conf
eofCreate a systemd service for the agent:
# Service unit file
cat > /usr/lib/systemd/system/zabbix-agent.service <<eof
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target
[Service]
Type=simple
Restart=on-failure
PIDFile=/usr/local/zabbix/logs/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/conf/zabbix_agentd.conf
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix
[Install]
WantedBy=multi-user.target
eof
# Enable and start
systemctl daemon-reload
systemctl enable zabbix-agent --nowAutomatic Registration
The agent can automatically register itself with the Zabbix server, reducing server load. After adding matching conditions and registration actions in the Zabbix UI, newly added agents appear automatically.
Custom Dashboard
Zabbix’s default dashboard does not show host metrics. Create a new host panel, select the desired host group and items, and add it to the dashboard to visualize host performance.
Optional LDAP Integration
Zabbix supports LDAP authentication for unified account management. Configure the LDAP settings in the Zabbix UI, create users belonging to appropriate groups and roles, and enable LDAP as the authentication method.
End of tutorial.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
