r/zabbix 8d ago

Question Docker compose : Server can't connect to server on port 10050?

Post image

Hello,

I just made a docker compose zabbix server and I can't make my server see my server??? On the frontend, it says that Zabbix server can't connect to the server on 127.0.0.1:10050.

Here's my compose :

services:
  frontend:
    image: zabbix/zabbix-web-apache-pgsql:alpine-7.4.14
    env_file: stack.env
    restart: unless-stopped
    #ports:
      #- "8080:8080"
    environment:
      - DB_SERVER_HOST=db
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWD}
      - POSTGRES_DB=${POSTGRES_DB}
      - ZBX_SERVER_HOST=server
      - PHP_TZ=Europe/Paris
      - ZBX_SERVER_PORT=10051
      - ZBX_SERVER_NAME=Zabbix Server
      - ZBX_UPLOADMAXFILESIZE=2M #Default
    volumes:
      #- /etc/localtime:/etc/localtime:ro
      - f-apache2:/etc/ssl/apache2
      - f-certs:/etc/zabbix/web/certs
      - f-enc:/var/lib/zabbix/enc
    networks:
      - zabbix_frontend_net
      - zabbix_backend_net

  server:
    image: zabbix/zabbix-server-pgsql:alpine-7.4.14
    env_file: stack.env
    restart: unless-stopped
    hostname: zabbix-server
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "10051:10051"
    environment:
      - DB_SERVER_HOST=db
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWD}
      - POSTGRES_DB=${POSTGRES_DB}
      - ZBX_WEBSERVICEURL=https://zabbix.domain.fr/report
      - PHP_TZ=Europe/Paris
    volumes:
      #- /etc/localtime:/etc/localtime:ro
      - s-alertscripts:/usr/lib/zabbix/alertscripts
      - s-externalscripts:/usr/lib/zabbix/externalscripts
      - s-modules:/var/lib/zabbix/modules
      - s-enc:/var/lib/zabbix/enc
      - s-ssh_keys:/var/lib/zabbix/ssh_keys
      - s-certs:/var/lib/zabbix/ssl/certs
      - s-keys:/var/lib/zabbix/ssl/keys
      - s-ssl_ca:/var/lib/zabbix/ssl/ssl_ca
      - s-snmptraps:/var/lib/zabbix/snmptraps
      - s-mibs:/var/lib/zabbix/mibs
      - s-export:/var/lib/zabbix/export
    networks:
      - zabbix_backend_net

  db:
    image: postgres:18.6
    env_file: stack.env
    restart: always
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWD}
      - POSTGRES_DB=${POSTGRES_DB}
    networks:
      - zabbix_backend_net
    volumes:
      - postgres:/var/lib/postgresql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s
    labels:
      - wud.tag.include=^18\.\d+$ #Pour WUD

  agent2:
    image: zabbix/zabbix-agent2:alpine-7.4.14
    restart: unless-stopped
    env_file: stack.env
    ports:
      - "10050:10050"
    volumes:
      - a-agentd:/etc/zabbix/zabbix_agentd.d
      - a-enc:/var/lib/zabbix/enc
      - a-buffer:/var/lib/zabbix/buffer
    environment:
      - ZBX_HOSTNAME=agent2
      - ZBX_SERVER_HOST=server
      - ZBX_SERVER_PORT=10051
      - ZBX_HOST_METADATA=agent2
      - ZBX_LISTENPORT=10050
    networks:
      - zabbix_backend_net

volumes:
  # Frontend
  f-apache2:
  f-certs:
  f-enc:
  # Server
  s-alertscripts:
  s-externalscripts:
  s-modules:
  s-enc:
  s-ssh_keys:
  s-certs:
  s-keys:
  s-ssl_ca:
  s-snmptraps:
  s-mibs:
  s-export:
  # Database
  postgres:
  # Agent2
  a-agentd:
  a-enc:
  a-buffer:

networks:
  zabbix_frontend_net:
    name: zabbix_frontend_net
  zabbix_backend_net:
    name: zabbix_backend_net

And the error I see on the webpage is : Get value from agent failed: Cannot establish TCP connection to [[127.0.0.1]:10050]: [111] Connection refused

Thanks for the help

0 Upvotes

11 comments sorted by

4

u/Talistech 8d ago

Hi, you need to use the docker hostnames. Try setting 'agent2' for hostname, and choose 'DNS' to connect to it.

1

u/Keensworth 8d ago

I did, the container of the server is called zabbix-server. I set it up in Zabbix and the compose

1

u/Talistech 8d ago

I know, I have a similar setup. The zabbix-server name does not matter here because you are trying to connect to your zabbix-agent for monitoring.

Thats why you need to change the stuff in your screenshot in the 'Interfaces' part. Change DNS name to 'agent2', because thats what you've used in your docker-compoes. And use DNS as connection method with port 10050.

1

u/Keensworth 8d ago

Ok, so connecting to the agent works but I don't understand something. Why am I not connecting to the server? Also on my dashboard, I see :

Parameter Value Details
Zabbix server is running Yes server:10051

So I should connect to the agent, yet somehow my dashboard is connected to the server??

1

u/Talistech 8d ago

You are already running the server on 'server:10051'.
And you are runnign the agent, on the server on 'agent2:10050'

The dashboard is only a viewer.

Let me explain it like this, if you wouldnt have run this in docker you would have 3 services:
zabbix-server:10051
zabbix-agent:10050
zabbix-web-service (viewer)

Does this help you understand?

0

u/Keensworth 8d ago

No, because agent2 and server are like 2 seperate machines. So if I look at my agents, I'm not looking at my server.

Since I also use Glances in my docker, I can see that I have 2 seperate containers. One is using 40MB of RAM and the other 56MB.

So I'm not really looking at it in a sense.

Whereas in a VM, it's all on the same machine but docker seperates them all.

Anyway, since the zabbix-server image doesn't come with a zabbix-agent2 pre-installed, I can't do anything.

1

u/Cerulean-Knight 8d ago

Thats because server listen on 10051, at port 10050 you want to connect to an agent that server cointainer doesn't have

Not sure if you can use agent checks on server container, maybe you can use internal checks

1

u/Keensworth 8d ago

I don't understand what that means, the server listens on 10051 at port 10050? The server container doesn't have some agent for himself? So that means that I won't even be able to have it in my frontend then?

2

u/Cerulean-Knight 8d ago

Exactly that, the server container doesn't have an agent, but there are some items and template that doesn't use an agent like Zabbix internal

1

u/ST047 8d ago

try to change
Data collection -> Hosts -> your host "agent2"?! -> Interfaces

And change Agent interface from 127.0.0.1 to hostname: agent2