2

I want to use Zabbix to monitor my server (just one so far). In order to keep things neat, I've decided to run it in Docker containers. I just have doubts about the usage of the agent in a container. As far as I understand it should be able to monitor the host itself. But containers are usually isolated. So what's the point to run the agent in the container?

And if there is a reason to do so, should the network mode for agent's container be "host"?

Andrzej Sydor
  • 1,373
  • 4
  • 13
  • 28
Ralfeus
  • 845
  • 9
  • 31
  • 1
    The documentation and the docker hub page explains everything you need: https://www.zabbix.com/documentation/current/manual/installation/containers and https://hub.docker.com/r/zabbix/zabbix-agent/ – Simone Zabberoni Dec 18 '20 at 10:46
  • @Andrej Sydor , ok, it seems starting agent in container is proper thing to do. Thank you – Ralfeus Dec 20 '20 at 10:01
  • Ok, in this case zabbix-server container should be configured to be accessible from another container (zabbix-agent). According to documentation (https://docs.docker.com/compose/compose-file/compose-file-v3/#expose) this should be done by ```expose``` option, which isn't in provided Docker Compose file. So, how agent can communicate to the server? Via host? It's stated in the agent's container manual the default Zabbix server name is zabbix-server, which implies inter-container communication. So I'm confused.... – Ralfeus Dec 21 '20 at 22:05

1 Answers1

0

Intro:

I've just done a fully Dockerized Zabbix 6.2 installation using Zabbix's GitHub Docker-Compose repo. My experience was that the Docker install was the better path, but other's might of course have different views.

Although it looks really daunting- there's a lot of components in it- Zabbix's Docker-Compose repo is the quickest and least painful way to fire-up a Zabbix installation; much easier to setup than a manual config.

I used their repo to configure an all-singing-all-dancing Zabbix infrastructure on a Raspberry Pi4 with 8GB RAM using a 64bit ARM version of Ubuntu 20.04 LTS. It would have taken ages to get the same results with a manual config.

There was one issue regarding connectivity problems I note at the end however. But once you get past that it's plug-n-chug.

Configuration:

Below is a very general outline of the process of configuring Zabbix using their Docker-Compose repo.

Server Infrastructure

The basic form of raising the components is:

docker-compose -f docker-compose_v3_ubuntu_pgsql_latest.yaml --profile all up -d

NOTE: 172.16.238.3 is the default IP of the Zabbix Server in my testing- it should be yours as well- but validate the IP.

Agents:

Starting an Agent is as simple as:

docker run --add-host=zabbix-server:172.16.238.3 -p 10050:10050 -d --privileged --name myHost-zabbix-agent -e ZBX_SERVER_HOST="zabbix-server" -e ZBX_PASSIVE_ALLOW="true" zabbix/zabbix-agent:ubuntu-6.0-latest

Just change "myHost-zabbix-agent" and add the new Zabbix Agent in the Web interface.

To get the IP of a new Zabbix agent raised with the above command:

docker ps

Then get the random id for it and:

docker exec -u root -it (random ID for agent from docker ps) bash

Once inside the container, reveal it's IP with:

hostname -I

Use this IP for the Agent's interface in the Zabbix server's web interface. As you've rightly remarked, since the agent runs in a container, it's isolated and the default IP pf 127.0.0.1 won't work: you need a routable IP for the Zabbix Server to reach the Agent on.

Then move on to the next host, changing the hostname in the docker run command above, get the Ip and add it in the Zabbix Server's web interface.

Conclusion:

Nothing stopping you from tailoring the configuration- Zabbix has made it very tweakable- but using Zabbix's Docker-Compose GitHub repo enables you to get some decent monitoring in place quickly with little effort and reduces the grunt work to the bare minimum; important if you have a lot of hosts.

There was one issue with configuring Agents' connectivity- Docker inserted an iptables rule which broke connectivity by NAT'ing the traffic, but I documented how to get around the problem here:

Dockerized Zabbix: Server Can't Connect to the Agents by IP

Hope this saves you some cycles-

F1Linux
  • 3,580
  • 3
  • 25
  • 24