Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Deploy Zabbix Through Docker

Zabbix is an open-source monitoring platform that might be thought of as an alternative to Nagios. I'm sure there are many online discussions comparing the two tools (such as this one), but that's beyond the scope of this tutorial.

Server Requirements

I would recommend deploying a server with at least 2 GB of RAM, preferably more.

Steps

You can run the following bash script to deploy Zabbix on your server. Just make sure to update the settings at the top of the file.

#!/bin/bash

# Change these settings
MYSQL_ROOT_PASSWORD="changeme123"
ZABBIX_DB_USER_PASSWORD="changeMeAgain123"
SERVER_IP="192.168.1.54"



# Deploy a mysql container for zabbix to use.
docker run -d \
  --name="zabbix-mysql-database" \
  --restart=always \
  -p 3306:3306 \
  -e MYSQL_DATABASE=zabbix \
  -e MYSQL_USER=zabbix \
  -e MYSQL_PASSWORD=$ZABBIX_DB_USER_PASSWORD \
  -e MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD \
  -v $HOME/volumes/mysql:/var/lib/mysql \
  mariadb:10.11-jammy

# Deploy the zabbix-server application container
docker run -d \
  --name zabbix-server \
  --restart=always \
  -e DB_SERVER_HOST=$SERVER_IP \
  -e MYSQL_USER="zabbix" \
  -e MYSQL_PASSWORD=$ZABBIX_DB_USER_PASSWORD \
  -v $HOME/volumes/zabbix/alertscripts:/usr/lib/zabbix/alertscripts \
  -v $HOME/volumes/zabbix/externalscripts:/usr/lib/zabbix/externalscripts \
  -v $HOME/volumes/zabbix/modules:/var/lib/zabbix/modules \
  -v $HOME/volumes/zabbix/enc:/var/lib/zabbix/enc \
  -v $HOME/volumes/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys \
  -v $HOME/volumes/zabbix/ssl/certs:/var/lib/zabbix/ssl/certs \
  -v $HOME/volumes/zabbix/ssl/keys:/var/lib/zabbix/ssl/keys \
  -v $HOME/volumes/zabbix/ssl_ca:/var/lib/zabbix/ssl/ssl_ca \
  -v $HOME/volumes/zabbix/snmptraps:/var/lib/zabbix/snmptraps \
  -v $HOME/volumes/zabbix/mibs:/var/lib/zabbix/mibs \
  -p 10050:10050 \
  -p 10051:10051 \
  zabbix/zabbix-server-mysql:ubuntu-6.2-latest

# Deploy the webserver frontend.
docker run -d \
  --name zabbix-web-nginx \
  --restart=always \
  -e DB_SERVER_HOST="$SERVER_IP" \
  -e MYSQL_USER="zabbix" \
  -e MYSQL_PASSWORD=$ZABBIX_DB_USER_PASSWORD \
  -e ZBX_SERVER_HOST=$SERVER_IP \
  -e PHP_TZ="UTC" \
  -p 80:80 \
  -p 443:443 \
  -p 8080:8080 \
  -p 8443:8443 \
  zabbix/zabbix-web-nginx-mysql:ubuntu-6.2-latest

If you use the MySQL 8.x Docker image instead of MariaDB, then you get an error to do with collation. It is easier just to use the MariaDB image.

After having run the script, wait rough 30 seconds to a minute before visiting your server's IP address or hostname if your browser. If you waited long enough, you will see a login screen, rather than an error message. If you see an error message, just wait longer.

The default credentials to log in are:

  • username: Admin
  • password: zabbix

Docker Compose Version

When I originally deployed Zabbix, I did it through the manual docker commands shown above. However, we now have Docker Compose which makes life a lot easier. Also, with this setup, the database is not exposed to the internet, for added security. You can always expose it to the internet again if you wish, by adding a port mapping for 3306.

version: "3"

services:
  db:
    container_name: zabbix-mysql-database
    image: mariadb:10.11-jammy
    restart: unless-stopped
    volumes:
      - ./volumes/mysql:/var/lib/mysql
    environment:
      - MYSQL_DATABASE=zabbix
      - MYSQL_USER=zabbix
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}

  zabbix-server:
    image: zabbix/zabbix-server-mysql:ubuntu-6.2-latest
    container_name: db
    restart: unless-stopped
    ports:
      - "10050:10050"
      - "10051:10051"
    volumes:
      - ./volumes/alertscripts:/usr/lib/zabbix/alertscripts
      - ./volumes/externalscripts:/usr/lib/zabbix/externalscripts
      - ./volumes/modules:/var/lib/zabbix/modules
      - ./volumes/enc:/var/lib/zabbix/enc
      - ./volumes/ssh_keys:/var/lib/zabbix/ssh_keys
      - ./volumes/ssl/certs:/var/lib/zabbix/ssl/certs
      - ./volumes/ssl/keys:/var/lib/zabbix/ssl/keys
      - ./volumes/ssl_ca:/var/lib/zabbix/ssl/ssl_ca
      - ./volumes/snmptraps:/var/lib/zabbix/snmptraps
      - ./volumes/mibs:/var/lib/zabbix/mibs
    environment:
      - DB_SERVER_HOST=db
      - MYSQL_USER=zabbix
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
    depends_on:
      - db

  zabbix-nginx:
    image: zabbix/zabbix-web-nginx-mysql:ubuntu-6.2-latest
    container_name: zabbix-web-nginx
    restart: unless-stopped
    ports:
      - "80:8080"
      - "443:8443"
    depends_on:
      - zabbix-server
    environment:
      - DB_SERVER_HOST=db
      - MYSQL_USER=zabbix
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - PHP_TZ=UTC
      - ZBX_SERVER_HOST=zabbix-server

References

Last updated: 12th July 2023
First published: 16th August 2018