Skip to main content

Zabbix v6 Docker-Compose Setup

Guangzhou, China

Github Repository

Installing Zabbix Server version 6 with an Zabbix Agent version 2 using Docker Compose

Preparation

Clone the repository:

git clone https://github.com/mpolinowski/zabbix-server-compose.git

Change the database login in ./env_vars/.POSTGRES_PASSWORD and ./env_vars/.POSTGRES_USER and take a look at the ./docker-compose.yml file:

zabbix-server

Zabbix version 6 is currently still in beta. And we can only get it from the trunk branch. Verify the latest version on Docker Hub - once version 6 was moved to stable adjust the image tag below.

zabbix-server:
image: zabbix/zabbix-server-pgsql:trunk-alpine
ports:
- "10051:10051"

Zabbix Server uses the port 10051. This is the port you need to add to your Zabbix Agent configuration so that it can communicate with your server. If you want to use a none-default port just change the first (left) 10051 seen above - e.g. :

    ports:
- "15001:10051"

In this case you will have to point your agents to port 15001 and also make sure that the port is set to open in your server firewall!

zabbix-web

Zabbix version 6 is currently still in beta. And we can only get it from the trunk branch. Verify the latest version on Docker Hub - once version 6 was moved to stable adjust the image tag below.

zabbix-web-nginx-pgsql:
container_name: zabbix-web
image: zabbix/zabbix-web-nginx-pgsql:trunk-alpine
ports:
- "8080:8080"
- "8443:8443"

The web frontend's default HTTP port is 8080. There is also an option to add an SSL certificate to the Zabbix frontend directly and access it via HTTPS on default port 8443. But I am not going to use this option. Instead I am adding a third virtual docker network that already contains an NGINX container that is configured as an Ingress:

networks:
zbx_net_backend:
ipv4_address: 172.16.239.102
aliases:
- zabbix-web-nginx-pgsql
- zabbix-web-nginx-alpine-pgsql
- zabbix-web-nginx-pgsql-alpine
zbx_net_frontend:
ipv4_address: 172.16.238.102
ingress_gateway:
aliases:
- zabbix-web

This network needs to be created first:

docker network create ingress_gateway

Delete the ingress_gateway network from the docker-compose.yml as well as it's instantiation below if you want to access Zabbix directly on port 8080:

networks:
zbx_net_frontend:
driver: bridge
driver_opts:
com.docker.network.enable_ipv6: "false"
ipam:
driver: default
config:
- subnet: 172.16.238.0/24
zbx_net_backend:
driver: bridge
driver_opts:
com.docker.network.enable_ipv6: "false"
internal: true
ipam:
driver: default
config:
- subnet: 172.16.239.0/24
ingress_gateway:
external: true
name: ingress_gateway

zabbix-agent

Zabbix version 6 is currently still in beta. And we can only get it from the trunk branch. Verify the latest version on Docker Hub - once version 6 was moved to stable adjust the image tag below.

  zabbix-agent:
container_name: zabbix-agent
image: zabbix/zabbix-agent2:trunk-alpine

Note that the agent is on the same virtual backend network as the Zabbix server and our Zabbix web frontend:

    networks:
zbx_net_backend:
ipv4_address: 172.16.239.103
aliases:
- zabbix-agent
- zabbix-agent-passive
- zabbix-agent-alpine

This means that you will be able to connect to your agent either by it's fixed IP 172.16.239.103 or via the DNS service that will resolve the alias zabbix-agent for you.

Docker Compose Up

Test Run

Run the docker-compose.yml file and check the log output - is everything starting up?

docker-compose up

If your server allows access to port 8080 use your web browser to access the web frontend and login with the default:

UsernamePassword
Adminzabbix

Configure the Server

Always the first step - changing the theme:

Zabbix v6 Docker-Compose Setup

Change the default administrator login:

Zabbix v6 Docker-Compose Setup

Now we need to connect our agent that is still MiA:

Zabbix v6 Docker-Compose Setup

Since the agent is running on the same Docker network we can simply add the fixed IP and/or the container alias the server configuration and both containers should be able to find each other:

Zabbix v6 Docker-Compose Setup

Since there are some limitations ... or at least complications ... to running your agent inside a docker container you might want to remove it from the docker-compose.yml file before starting the server and install the agent via your package manager. In this case you will have to use your server IP address here instead and, of course, make sure that the agent port 10050 is open in your firewall:

Zabbix v6 Docker-Compose Setup

Give it a few minutes and get yourself a coffee... the agent should be online shortly:

Zabbix v6 Docker-Compose Setup

Now shutdown the zabbix containers and restart them as daemons. The containers are configured to be automatically restarted if there is a problem or you restart your server:

docker-compose down
docker-compose up -d

NGINX Docker Ingress

I created the ingress_gateway Docker network in one of the steps above. I will now add an NGINX container to this network that will server as my ingress and handle the Certbot SSL certificate:

Github Repository

The docker-compose.yml file for it looks like this:

version: "3.8"

services:

ingress:
image: nginx:stable-alpine
container_name: ingress
networks:
ingress_gateway:
aliases:
- zabbix-ingress
ports:
- "80:80"
- "443:443"
restart: unless-stopped
volumes:
- /opt/docker-ingress/configuration/conf.d:/etc/nginx/conf.d
- /opt/docker-ingress/configuration/ssl/dhparam:/etc/nginx/ssl/dhparam
- /opt/docker-ingress/configuration/ssl/selfsigned:/etc/nginx/ssl/selfsigned
- /etc/letsencrypt:/etc/letsencrypt
- /opt/docker-ingress/configuration/nginx.conf:/etc/nginx/nginx.conf
- /opt/test-static/public:/opt/test-static/public



networks:
ingress_gateway:
external: true
name: ingress_gateway

And the configuration/conf.d/default.conf needs a server block with a proxy pass for the Zabbix frontend:

location /zabbix/ {
add_header Cache-Control "public, must-revalidate, proxy-revalidate, max-age=0";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto http;
proxy_hide_header X-Frame-Options;
proxy_set_header Accept-Encoding "";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_max_temp_file_size 0;
proxy_redirect off;
proxy_read_timeout 240s;
proxy_pass http://zabbix-web:8080/;
}

We gave the frontend the network alias zabbix-web and since both the frontend and our ingress are a member of the network ingress_gateway NGINX is now able to connect to http://zabbix-web:8080/ and proxy the service!

Troubleshooting

Zabbix server: More than 75% used in the configuration cache

Zabbix v6 Docker-Compose Setup

Open the Server environment file env_vars/.env_srv and un-comment the following line:

# ZBX_CACHESIZE=8M

Try out higher values e.g. :

ZBX_CACHESIZE=64M

Wait for a few minutes before increasing it further. See if the warning disappears. You might also want to take a look at the other cache options - but changing the main cache to 64 MB was already enough for my setup:

ZBX_CACHESIZE=128M
ZBX_HISTORYCACHESIZE=128M
ZBX_HISTORYINDEXCACHESIZE=128M
ZBX_TRENDCACHESIZE=128M
ZBX_VALUECACHESIZE=128M