Configure and work with Zabbix Monitoring tool version 6 in Docker Containers

Configure and work with Zabbix Monitoring tool version 6 in Docker Containers

Zabbix is an open-source monitoring software that provides tools for tracking, monitoring, and managing the health and performance of networks, servers, applications, and other IT resources. It is designed to gather and display a wide range of metrics in real-time, helping system administrators and IT professionals to detect issues, troubleshoot problems, and ensure the smooth operation of their infrastructure.

Key features of Zabbix include:

  1. Monitoring: Zabbix can monitor various aspects of IT infrastructure, such as server health, network performance, application availability, and more.
  2. Alerting: It provides flexible alerting mechanisms, allowing users to set up triggers and receive notifications when predefined thresholds are breached.
  3. Visualization: Zabbix offers a web-based interface with customizable dashboards and graphs, providing a visual representation of performance data.
  4. Automation: Zabbix supports automation through the use of templates, allowing for the streamlined configuration and management of monitoring tasks.
  5. Scalability: It is scalable and can handle large-scale environments, making it suitable for both small businesses and large enterprises.
  6. Extensibility: Zabbix supports a wide range of plugins and integrations, allowing users to extend its functionality and integrate it with other tools.
  7. Historical Data Storage: Zabbix stores historical data, enabling users to analyze trends, forecast future resource needs, and maintain a historical record of system performance.
  8. Security: It provides security features such as user authentication, access control, and encryption to ensure the confidentiality and integrity of monitoring data.

Zabbix uses a client-server architecture where agents are installed on monitored devices, and the Zabbix server collects and processes data from these agents. The collected data is then presented through the web interface, allowing users to analyze and manage their IT infrastructure effectively. Zabbix has gained popularity in the IT industry as a robust and feature-rich monitoring solution.

Now let’s dive into the nub and see how we can run the Zabbix Server 6.0 in Docker Containers.

Step 1: Install Docker Runtime on the System

For this guide, we need the Docker Engine installed. If you already have it installed, then you can skip this step. Otherwise, install docker Engine using the below commands that best work for your system.

The quickest way to install docker is by using the below commands:

curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh        

Alternatively, use the below methods as per the OS flavor:

On Debian:

sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io        

On Ubuntu:

sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io        

On RHEL/CentOS 8/Rocky Linux 8/Alma Linux 8:

sudo dnf install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf -y install docker-ce docker-ce-cli containerd.io        

Once Docker has been installed, you need to verify the installation using the command:

$ docker --version
Docker version 24.0.7, build afdd53b        

Start and enable the Docker service.

sudo systemctl enable --now docker        

Add your system user to the docker group.

sudo usermod -aG docker $USER
newgrp docker        

On macOS:

brew cask install docker        

On Rhel-based systems, Before proceeding to install, we need to disable SELinux or set it in permissive mode as below:

sudo setenforce 0
sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config        

Method 1:- Install Zabbix Server 6.0 in Docker Containers

In this Article, I am showing that how will we run Zabbix with MySQL database, although one can still run with PostgreSQL.

We will have the following containers:

  • MySQL server
  • Zabbix server – with MySQL database support
  • Zabbix web interface – based on Nginx web server with MySQL database support
  • Zabbix proxy – with MySQL database support
  • Zabbix Java Gateway

Using docker, you can just run the containers as below:

  1. Now create the MySQL database container for Zabbix:

root@ramesh-dev:~# docker run --name mysql-server -t \
      -e MYSQL_DATABASE="zabbixdb" \
      -e MYSQL_USER="zabbix" \
      -e MYSQL_PASSWORD="<give_any_password>" \
      -e MYSQL_ROOT_PASSWORD="<give_any_password>" \
      -d mysql:8.0 \
      --character-set-server=utf8 --collation-server=utf8_bin \
      --default-authentication-plugin=mysql_native_password ^C
root@ramesh-dev:~#         

2. The next container to be deployed is the Zabbix Java gateway.

root@ramesh-dev:~# docker run --name zabbix-java-gateway -t \
      --restart unless-stopped \
      -d zabbix/zabbix-java-gateway:alpine-6.0-latest 
root@ramesh-dev:~#         

3. Deploy the Zabbix server with MySQL database support and link it with the created MySQL instance. Remember to keep proper and the correct details:

root@ramesh-dev:~# docker run --name zabbix-server-mysql -t \
      -e DB_SERVER_HOST="mysql-server hostname or IP Address" \
      -e MYSQL_DATABASE="zabbixdb" \
      -e MYSQL_USER="zabbix" \
      -e MYSQL_PASSWORD="give_any_password>" \
      -e MYSQL_ROOT_PASSWORD="give_any_password>" \
      -e ZBX_JAVAGATEWAY="zabbix-java-gateway" \
      -p 10051:10051 \
      --restart unless-stopped \
      -d zabbix/zabbix-server-mysql:alpine-6.0-latest
root@ramesh-dev:~#        

4. Create the Zabbix web interface and link it to the created Zabbix server and MySQL.

root@ramesh-dev:~# docker run --name zabbix-web-nginx-mysql -t \
      -e ZBX_SERVER_HOST="zabbix-server-mysql hostname or IP" \
      -e DB_SERVER_HOST="mysql-server hostname or IP" \
      -e MYSQL_DATABASE="zabbixdb" \
      -e MYSQL_USER="zabbix" \
      -e MYSQL_PASSWORD="<give_any_password>" \
      -e MYSQL_ROOT_PASSWORD="<give_any_password>" \
      -p 80:8080 \
      --restart unless-stopped \
      -d zabbix/zabbix-web-nginx-mysql:alpine-6.0-latest ^C
root@ramesh-dev:~#        

Verify if the containers are running:

$ docker ps
CONTAINER ID   IMAGE                                             COMMAND                  CREATED          STATUS              PORTS                                             NAMES
81ce9d2dc99a   mysql:8.0                                        "docker-entrypoint.s…"   18 seconds ago   Up 17 seconds       3306/tcp                                          mysql-server
070f11ee0d29   zabbix/zabbix-web-nginx-mysql:alpine-6.0-latest   "docker-entrypoint.sh"   7 minutes ago    Up 7 minutes        8443/tcp, 0.0.0.0:80->8080/tcp, :::80->8080/tcp   zabbix-web-nginx-mysql
fb53558cb096   zabbix/zabbix-server-mysql:alpine-6.0-latest      "/sbin/tini -- /usr/…"   7 minutes ago    Up About a minute   0.0.0.0:10051->10051/tcp, :::10051->10051/tcp     zabbix-server-mysql
ba2f317cb29a   zabbix/zabbix-java-gateway:alpine-6.0-latest      "docker-entrypoint.s…"   7 minutes ago    Up 7 minutes        10052/tcp                                         zabbix-java-gateway        

This service is exposed on port 80/TCP to the host machine. You can now access the Zabbix web interface by navigating to port 80.

Method 2:- Install and setup Zabbix Server using Docker Compose

  1. First we need to have it Install Docker compose on your system using the below command.

root@ramesh-dev:~# curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url  | grep docker-compose-linux-x86_64 | cut -d '"' -f 4 | wget -qi -        

2. Give the execute permissions to the docker compose installed file and move to your local binary file path.

root@ramesh-dev:~# chmod +x docker-compose-linux-x86_64
root@ramesh-dev:~# sudo mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose
root@ramesh-dev:~#        

3. Now verify whether its installed or not

root@ramesh-dev:~# docker-compose version||docker compose version
Docker Compose version v2.21.0
root@ramesh-dev:~#        

4. Create a dedicated network for all the Zabbix components:

root@ramesh-dev:~# docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 zabbix-net        

5. Check whether the network is created by checking with below command

root@ramesh-dev:~# 
NETWORK ID     NAME         DRIVER    SCOPE
652e3aadefbc   bridge       bridge    local
6854c55d5ecb   host         host      local
7460cfbf8c6c   none         null      local
0f1961d58b8e   zabbix-net   bridge    local
root@ramesh-dev:~#         

6. Now, create a docker-compose file for the containers and its yml file.

root@ramesh-dev:~# vim docker-compose.yml        
version: '3.5'
services:
 mysql-server:
  image: mysql:8.0
  networks:
   - zabbix-net
  command:
   - mysqld
   - --character-set-server=utf8
   - --collation-server=utf8_bin
   - --default-authentication-plugin=mysql_native_password
  environment:
   - MYSQL_USER=zabbix
   - MYSQL_DATABASE=zabbixdb
   - MYSQL_PASSWORD=<Create_your_own_password>
   - MYSQL_ROOT_PASSWORD=<Create_your_own_password>
   - ZBX_JAVAGATEWAY=zabbix-java-gateway
  volumes:
   - /zabbix-mysql:/var/lib/mysql:rw
 zabbix-server-mysql:
  image: zabbix/zabbix-server-mysql:alpine-latest
  networks:
   - zabbix-net
  ports:
   - 10051:10051
  volumes:
   - /etc/localtime:/etc/localtime:ro
   - /etc/timezone:/etc/timezone:ro 
   - /zabbix-data/alertscripts:/usr/lib/zabbix/alertscripts:ro
   - /zabbix-data/externalscripts:/usr/lib/zabbix/externalscripts:ro
   - /zabbix-data/export:/var/lib/zabbix/export:rw
   - /zabbix-data/modules:/var/lib/zabbix/modules:ro
   - /zabbix-data/enc:/var/lib/zabbix/enc:ro
   - /zabbix-data/ssh_keys:/var/lib/zabbix/ssh_keys:ro
   - /zabbix-data/mibs:/var/lib/zabbix/mibs:ro
   - /zabbix-data/snmptraps:/var/lib/zabbix/snmptraps:rw
  environment:
   - DB_SERVER_HOST=mysql-server host or IP
   - MYSQL_DATABASE=zabbixdb
   - MYSQL_USER=zabbix
   - MYSQL_PASSWORD=<Create_your_own_password>
   - MYSQL_ROOT_PASSWORD=<Create_your_own_password>
   - ZBX_JAVAGATEWAY=zabbix-java-gateway

  depends_on:
   - mysql-server

 zabbix-web-nginx-mysql:
  image: zabbix/zabbix-web-nginx-mysql:alpine-6.0-latest
  networks:
   - zabbix-net
  ports:
   - 80:8080
   - 443:8443
  volumes:
   - /etc/localtime:/etc/localtime:ro
   - /etc/timezone:/etc/timezone:ro
   - /zabbix-nginx/nginx:/etc/ssl/nginx:ro
   - /zabbix-nginx/modules/:/usr/share/zabbix/modules/:ro
  environment:
   - ZBX_SERVER_HOST=zabbix-server-mysql host or IP
   - DB_SERVER_HOST=mysql-server host or IP
   - MYSQL_DATABASE=zabbixdb
   - MYSQL_USER=zabbix
   - MYSQL_PASSWORD=<Create_your_own_password>
   - MYSQL_ROOT_PASSWORD=<Create_your_own_password>
  depends_on:
   - mysql-server
   - zabbix-server-mysql
 zabbix-java-gateway:
  image: zabbix/zabbix-java-gateway:alpine-6.0-latest
  networks:
   - zabbix-net
  ports:
   - 10052:10052
networks:
 zabbix-net:
   driver: bridge        

Note: Remove current containers if you already have it installed in the method 1. With this command it stops the container and delete it

root@ramesh-dev:~# for i in mysql-server zabbix-java-gateway zabbix-server-mysql zabbix-web-nginx-mysql; do
  docker rm -f $i
done        

7. Once check the docker containers and start composing it for creating the containers

root@ramesh-dev:~# docker-compose up -d
[+] Running 1/1
 ? zabbix-server-mysql Pulled                                                                                                                                                                    1.3s
[+] Running 5/5
 ? Network rocky_zabbix-net                     Created                                                                                                                                             0.1s
 ? Container rocky-zabbix-java-gateway-1     Started                                                                                                                                             0.6s
 ? Container rocky-mysql-server-1            Started                                                                                                                                             0.5s
 ? Container rocky-zabbix-server-mysql-1     Started                                                                                                                                             1.1s
 ? Container rocky-zabbix-web-nginx-mysql-1  Started                                                                                                                                             1.4s
root@ramesh-dev:~#        

8. Verify if the containers are running or not:

root@ramesh-dev:~# docker-compose ps
NAME                             COMMAND                  SERVICE                  STATUS              PORTS
rocky-mysql-server-1             "docker-entrypoint.s…"   mysql-server             running             33060/tcp
rocky-zabbix-java-gateway-1      "docker-entrypoint.s…"   zabbix-java-gateway      running             0.0.0.0:10052->10052/tcp, :::10052->10052/tcp
rocky-zabbix-server-mysql-1      "/sbin/tini -- /usr/…"   zabbix-server-mysql      running             0.0.0.0:10051->10051/tcp, :::10051->10051/tcp
rocky-zabbix-web-nginx-mysql-1   "docker-entrypoint.sh"   zabbix-web-nginx-mysql   running             0.0.0.0:80->8080/tcp, 0.0.0.0:443->8443/tcp, :::80->8080/tcp, :::443->8443/tcp
root@ramesh-dev:~#        

9. Now install the firewalld service and allow the required ports

root@ramesh-dev:~# yum install firewalld
root@ramesh-dev:~# sudo firewall-cmd --permanent --add-port=10051/tcp
root@ramesh-dev:~# sudo firewall-cmd --permanent --add-port=80/tcp
root@ramesh-dev:~# sudo firewall-cmd --reload
root@ramesh-dev:~# sudo ufw allow 80/tcp
root@ramesh-dev:~# sudo ufw allow 10051/tcp         

10. The Zabbix 6.0 web UI is now accessible through port 80 and can be reached using the URL https://IP_address or https://domain_name

Provide the default credentials for logging into the Zabbix web interface.

username: Admin & Password: zabbix

Upon successful login, you should be able to view the following dashboard.

Proceed to change the admin password by navigating to Administration > Users > Admin > Password > Change Password.

After setting your preferred password, click on the "Update" button to confirm the changes.

Step 2 – Configure the Zabbix Monitoring Target host or clients

Now, let's configure this server for monitoring by installing the Zabbix agent package on a client machine. The Zabbix agent package can be installed using the following steps:

## Redhat / CentOS
sudo rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-1.el8.noarch.rpm
sudo yum install zabbix-agent -y

## Ubuntu
wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4+ubuntu22.04_all.deb  
sudo dpkg -i zabbix-release_6.0-4+ubuntu22.04_all.deb
sudo apt update
sudo apt install zabbix-agent

#On Debian
wget https://repo.zabbix.com/zabbix/6.0/debian/pool/main/z/zabbix-release/zabbix-release_6.0-1+debian11_all.deb
sudo dpkg -i zabbix-release_6.0-1+debian11_all.deb
sudo apt update
sudo apt install zabbix-agent        

After installing the Zabbix agent on the host you wish to monitor, edit the configuration file to include the Zabbix server details.

root@ramesh-delete:~# sudo vim /etc/zabbix/zabbix_agentd.conf        

Edit the file as below:

# On line 117 - Specify Zabbix server IP Address
Server=<give the zabbix server IP>

# On line 158 - Specify Zabbix server ( For active checks)
ServerActive=<Zabbix server IP>

# On line 169 - Set hostname of the Zabbix agent
Hostname=<zabbix server hostname>        

Now, Start and enable the zabbix-agent service:

root@ramesh-delete:~# sudo systemctl start zabbix-agent
root@ramesh-delete:~# sudo systemctl enable zabbix-agent        

Additionally, you need to allow the port through the firewall:

Install the firewalld service and start it if it requires

root@ramesh-delete:~# sudo firewall-cmd --permanent --add-port=10050/tcp
root@ramesh-delete:~# sudo firewall-cmd --reload
root@ramesh-delete:~#        

Step 3: Add the Zabbix Agent (client host) to the Zabbix Server

The Zabbix agent can now be added to the server by navigating to Configuration > Hosts > Create host.

You need to provide the following details:

  1. The hostname of the Zabbix agent to be monitored, which should match the one entered in the agent config file.
  2. A visible name for the Zabbix agent.
  3. Select the group or add a new group from the “Groups” field.
  4. The IP address of the Zabbix agent.
  5. Zabbix agent service port, where the default port is 10050.

Fill in the details as shown below:

Don't forget to add the monitoring templates depending on what you want to monitor on the agent. Then click "Add" to add the agent. Once added, the agent will be available as shown below:

After adding the agent, go to Monitoring > Hosts, and choose the desired host for monitoring. Then, select graphs to view the data.

Explore the various options available in Zabbix for monitoring purposes. This concludes the guide on installing and running Zabbix Server 6.0 in Docker Containers. Additionally, we've covered the process of adding Zabbix agents to the server. I trust this information is valuable.

Taimo Soy

Student At Beltei International University

11 个月

can you lab , How to deploy zabbix and grafana using docker swarm on ubuntu and HA database uisng PostgreSQL for zabbix install on RedHat?

回复

要查看或添加评论,请登录

Ramesh Ramineni的更多文章

社区洞察

其他会员也浏览了