Docker for Zabbix
Set up Zabbix server and Zabbix agent
Prerequisites
- Install Docker: https://docs.docker.com/get-docker/
- Install Docker-Compose: https://docs.docker.com/compose/install/
Zabbix Docker official images: https://github.com/zabbix/zabbix-docker
The instruction is for Ubuntu OS.
I. Installing Zabbix Server
On the server machine:
- Clone Zabbix docker compose source code:
git clone https://github.com/zabbix/zabbix-docker
- Go to the downloaded folder:
cd zabbix-docker
- Choose a compose file (I choose
docker-compose_v3_ubuntu_pgsql_latest.yaml
):
cp docker-compose_v3_ubuntu_pgsql_latest.yaml docker-compose.yml
- Start Zabbix server:
docker-compose up -d
Note: If you want to change the port of Zabbix server web, change these lines in docker-compose.yml
zabbix-web-nginx-pgsql:
image: zabbix/zabbix-web-nginx-pgsql:ubuntu-6.2-latest
ports:
- "80:8080"
- "443:8443"
# change to other ports we want. Eg: 800 for http, and 4430 for https
zabbix-web-nginx-pgsql:
image: zabbix/zabbix-web-nginx-pgsql:ubuntu-6.2-latest
ports:
- "800:8080"
- "4430:8443"
Open Zabbix dashboard @ localhost:80
or localhost:800
(if you change the default exposed port)
Default credential: Admin / zabbix
II. Installing Zabbix Agent on the same machine
Start Zabbix Agent on the server:
cd zabbix-docker
docker-compose up zabbix-agent -d
# or
docker-compose -f docker-compose_v3_ubuntu_pgsql_latest.yaml up zabbix-agent -d
Get the IP address of Zabbix Agent container
$ docker ps
# you will see a running container like "zabbix-docker-zabbix-agent-1"
# inspect that container to get its IP address
$ docker inspect zabbix-docker-zabbix-agent-1
...
"Networks": {
"zabbix-docker_zbx_net_backend": {
...
"Gateway": "172.16.239.1",
"IPAddress": "172.16.239.5", ## <--- GET THIS IP ADDRESS
"IPPrefixLen": 24,
...
}
}
...
Go to the Zabbix dashboard (localhost:800
) > Hosts > Zabbix server > Configuration > change 127.0.0.1 to Zabbix Agent IP address (eg. 172.16.239.5
).
Then wait a few minutes to have data in Latest data
sub-menu.
Latest data on Zabbix dashboard
III. Installing Zabbix Agent on other machine
On the agent machine:
- Clone Zabbix docker compose source code:
git clone https://github.com/zabbix/zabbix-docker
- Go to the downloaded folder:
cd zabbix-docker
- Create docker-compose file for zabbix-agent:
docker-compose.yml
version: '3.5'
services:
zabbix-agent:
image: zabbix/zabbix-agent:ubuntu-6.2-latest
ports:
- "10050:10050"
volumes:
- /etc/localtime:/etc/localtime:ro
- ./zbx_env/etc/zabbix/zabbix_agentd.d:/etc/zabbix/zabbix_agentd.d:ro
- ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
- ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
- ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
deploy:
resources:
limits:
cpus: '0.2'
memory: 128M
reservations:
cpus: '0.1'
memory: 64M
mode: global
env_file:
- ./env_vars/.env_agent
privileged: true
pid: "host"
network_mode: "host"
stop_grace_period: 5s
labels:
com.zabbix.description: "Zabbix agent"
com.zabbix.company: "Zabbix LLC"
com.zabbix.component: "zabbix-agentd"
com.zabbix.os: "ubuntu"
- Configure env zabbix agent:
nano env_vars/.env_agent
# uncomment and configure the appropriate values:
# ZBX_SOURCEIP: local IP of the agent machine
# ZBX_SERVER_HOST: IP of the Zabbix server
# ZBX_HOSTNAME, ZBX_HOSTNAMEITEM: name of this agent / machine => we will configure the same HOST NAME on Zabbix dashboard
ZBX_SOURCEIP=172.28.184.3
# ZBX_DEBUGLEVEL=3
# ZBX_ENABLEREMOTECOMMANDS=0 # Deprecated since 5.0.0
# ZBX_LOGREMOTECOMMANDS=0
# ZBX_HOSTINTERFACE= # Available since 4.4.0
# ZBX_HOSTINTERFACEITEM= # Available since 4.4.0
ZBX_SERVER_HOST=172.28.184.6
# ZBX_PASSIVE_ALLOW=true
# ZBX_PASSIVESERVERS=
# ZBX_ACTIVE_ALLOW=true
# ZBX_ACTIVESERVERS=
# ZBX_LISTENIP=
# ZBX_LISTENBACKLOG=
# ZBX_STARTAGENTS=3
ZBX_HOSTNAME=FABLAB-MCTT1
ZBX_HOSTNAMEITEM=FABLAB-MCTT1
# ZBX_METADATA=
# ZBX_METADATAITEM=
# ZBX_REFRESHACTIVECHECKS=120
# ZBX_BUFFERSEND=5
# ZBX_BUFFERSIZE=100
# ZBX_MAXLINESPERSECOND=20
# ZBX_ALIAS=""
# ZBX_TIMEOUT=3
# ZBX_UNSAFEUSERPARAMETERS=0
# ZBX_LOADMODULE="dummy1.so,dummy2.so,dummy10.so"
# ZBX_TLSCONNECT=unencrypted
# ZBX_TLSACCEPT=unencrypted
# ZBX_TLSCAFILE=
# ZBX_TLSCRLFILE=
# ZBX_TLSSERVERCERTISSUER=
# ZBX_TLSSERVERCERTSUBJECT=
# ZBX_TLSCERTFILE=
# ZBX_TLSKEYFILE=
# ZBX_TLSPSKIDENTITY=
# ZBX_TLSPSKFILE=
# ZBX_DENYKEY=system.run[*]
# ZBX_ALLOWKEY=
- On Zabbix web, add a new host on Zabbix Server Dashboard
- Host name: matched ZBX_HOSTNAME
- Interfaces / Agent IP Address: matched agent machine IP address
- On Zabbix agent machine, start Zabbix agent container:
docker-compose up -d
[+] Running 9/9
⠿ zabbix-agent Pulled 15.7s
⠿ e96e057aae67 Pull complete 9.3s
⠿ e352ec68827c Pull complete 9.5s
⠿ 73fea19538ba Pull complete 9.9s
⠿ facc5f160d09 Pull complete 10.1s
⠿ b65b207dfe53 Pull complete 10.3s
⠿ 42cdfc4ebd94 Pull complete 11.0s
⠿ 4f4fb700ef54 Pull complete 11.1s
⠿ 5b2e00f8d155 Pull complete 11.3s
[+] Running 1/1
⠿ Container zabbix-docker-zabbix-agent-1 Started 5.6s