zabbix / zabbix-docker

Official Zabbix Dockerfiles
https://www.zabbix.com
GNU Affero General Public License v3.0
2.36k stars 1.37k forks source link

zabbix-agent does not get exposed #526

Closed JustDevZero closed 4 years ago

JustDevZero commented 4 years ago

It looks like zabbix-agent does not get exposed, in the result of being unable to monitorize zabbix it self:

Here's my docker-compose.yml

version: '3.5'

services:

    zabbix-web-nginx-pgsql:
        image: zabbix/zabbix-web-nginx-pgsql:alpine-4.4-latest
        ports:
            - "80:80"
            - "443:443"
        links:
            # - postgres-server:postgres-server
            - zabbix-server:zabbix-server
        volumes:
            - /etc/localtime:/etc/localtime:ro
            - /etc/timezone:/etc/timezone:ro
            - ./zbx_env/etc/ssl/nginx:/etc/ssl/nginx:ro
            - ./nginx_ssl.conf:/etc/zabbix/nginx.conf
            - ./nginx/etc/ssl/dhparam.pem:/etc/ssl/dhparam.pem
            - ./letsencrypt:/etc/letsencrypt
        deploy:
            resources:
                limits:
                    cpus: '0.70'
                    memory: 512M
                reservations:
                    cpus: '0.5'
                    memory: 256M
        env_file:
            - .env_db_pgsql
            - .env_web
        secrets:
            - POSTGRES_USER
            - POSTGRES_PASSWORD
        user: root
        depends_on:
            # - postgres-server
            - zabbix-server
        healthcheck:
            test: ["CMD", "curl", "-f", "http://localhost"]
            interval: 10s
            timeout: 5s
            retries: 3
            start_period: 30s
        networks:
            zbx_net_backend:
                aliases:
                - zabbix-web-nginx-pgsql
                - zabbix-web-nginx-alpine-pgsql
                - zabbix-web-nginx-pgsql-alpine
            zbx_net_frontend:
        stop_grace_period: 10s
        sysctls:
            - net.core.somaxconn=65535
        labels:
            com.zabbix.description: "Zabbix frontend on Nginx web-server with PostgreSQL database support"
            com.zabbix.company: "Zabbix LLC"
            com.zabbix.component: "zabbix-frontend"
            com.zabbix.webserver: "nginx"
            com.zabbix.dbtype: "pgsql"
            com.zabbix.os: "alpine"

    zabbix-server:
        image: zabbix/zabbix-server-pgsql:alpine-4.4-latest
        ports:
            - "10051:10051"
        volumes:
            - /etc/localtime:/etc/localtime:ro
            - /etc/timezone:/etc/timezone:ro
            - ./zbx_env/usr/lib/zabbix/alertscripts:/usr/lib/zabbix/alertscripts:ro
            - ./zbx_env/usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:ro
            - ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
            - ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
            - ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
            - ./zbx_env/var/lib/zabbix/mibs:/var/lib/zabbix/mibs:ro
            - ./zbx_env/var/lib/zabbix/snmptraps:/var/lib/zabbix/snmptraps:ro
    #   links:
    #    - postgres-server:postgres-server
        ulimits:
            nproc: 65535
            nofile:
                soft: 20000
                hard: 40000
        deploy:
            resources:
                limits:
                    cpus: '0.70'
                    memory: 1G
                reservations:
                    cpus: '0.5'
                    memory: 512M
        env_file:
            - .env_db_pgsql
            - .env_srv
        secrets:
            - POSTGRES_USER
            - POSTGRES_PASSWORD
        user: root
        depends_on:
            # - postgres-server
            # - zabbix-java-gateway
            - zabbix-snmptraps
        networks:
            zbx_net_backend:
                aliases:
                    - zabbix-server
                    - zabbix-server-pgsql
                    - zabbix-server-alpine-pgsql
                    - zabbix-server-pgsql-alpine
            zbx_net_frontend:
            #  devices:
            #   - "/dev/ttyUSB0:/dev/ttyUSB0"
        stop_grace_period: 30s
        sysctls:
            - net.ipv4.ip_local_port_range=1024 65000
            - net.ipv4.conf.all.accept_redirects=0
            - net.ipv4.conf.all.secure_redirects=0
            - net.ipv4.conf.all.send_redirects=0
        labels:
            com.zabbix.description: "Zabbix server with PostgreSQL database support"
            com.zabbix.company: "Zabbix LLC"
            com.zabbix.component: "zabbix-server"
            com.zabbix.dbtype: "pgsql"
            com.zabbix.os: "alpine"

    zabbix-agent:
        image: zabbix/zabbix-agent:alpine-4.4-latest
        ports: "10050:10050"
        volumes:
            - /etc/localtime:/etc/localtime:ro
            - /etc/timezone:/etc/timezone:ro
            - ./zbx_env/etc/zabbix/zabbix_agentd.d:/etc/zabbix/zabbix_agentd.d:ro
            - ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
            - ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
            - ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
        links:
            - zabbix-server:zabbix-server
        deploy:
            resources:
                limits:
                    cpus: '0.2'
                    memory: 128M
                reservations:
                    cpus: '0.1'
                    memory: 64M
            mode: global
        env_file:
            - .env_agent
        user: root
        privileged: true
        pid: "host"
        networks:
            zbx_net_backend:
                aliases:
                    - zabbix-agent
                    - zabbix-agent-passive
                    - zabbix-agent-alpine
        stop_grace_period: 5s
        labels:
            com.zabbix.description: "Zabbix agent"
            com.zabbix.company: "Zabbix LLC"
            com.zabbix.component: "zabbix-agentd"
            com.zabbix.os: "alpine"

    zabbix-snmptraps:
        image: zabbix/zabbix-snmptraps:alpine-4.4-latest
        ports:
            - "162:162/udp"
        volumes:
            - ./zbx_env/var/lib/zabbix/snmptraps:/var/lib/zabbix/snmptraps:rw
        deploy:
            resources:
                limits:
                    cpus: '0.5'
                    memory: 256M
                reservations:
                    cpus: '0.25'
                    memory: 128M
        user: root
        networks:
            zbx_net_frontend:
                aliases:
                    - zabbix-snmptraps
            zbx_net_backend:
        stop_grace_period: 5s
        labels:
            com.zabbix.description: "Zabbix snmptraps"
            com.zabbix.company: "Zabbix LLC"
            com.zabbix.component: "snmptraps"
            com.zabbix.os: "ubuntu"

#  postgres-server:
#   image: postgres:latest
#   volumes:
#    - ./zbx_env/var/lib/postgresql/data:/var/lib/postgresql/data:rw
#   env_file:
#    - .env_db_pgsql
#   secrets:
#    - POSTGRES_USER
#    - POSTGRES_PASSWORD
#   user: root
#   stop_grace_period: 1m
#   networks:
#    zbx_net_backend:
#     aliases:
#      - postgres-server
#      - pgsql-server
#      - pgsql-database

#  db_data_pgsql:
#   image: busybox
#   volumes:
#    - ./zbx_env/var/lib/postgresql/data:/var/lib/postgresql/data:rw

# elasticsearch:
#  image: elasticsearch
#  environment:
#   - transport.host=0.0.0.0
#   - discovery.zen.minimum_master_nodes=1
#  networks:
#   zbx_net_backend:
#    aliases:
#     - elasticsearch

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

secrets:
  POSTGRES_USER:
    file: ./.POSTGRES_USER
  POSTGRES_PASSWORD:
    file: ./.POSTGRES_PASSWORD

And the docker ps:

ubuntu@ip-172-30-24-157:~/zabbix$ docker ps
CONTAINER ID        IMAGE                                             COMMAND                  CREATED             STATUS                    PORTS                                      NAMES
9adf8c230816        zabbix/zabbix-agent:alpine-4.4-latest             "/sbin/tini -- /usr/…"   5 minutes ago       Up 2 seconds                                                         zabbix_zabbix-agent_1
b65ffc1c73c5        zabbix/zabbix-server-pgsql:alpine-4.4-latest      "/sbin/tini -- /usr/…"   6 minutes ago       Up 6 minutes              0.0.0.0:10051->10051/tcp                   zabbix_zabbix-server_1
101ed107de48        zabbix/zabbix-web-nginx-pgsql:alpine-4.4-latest   "docker-entrypoint.sh"   14 hours ago        Up 14 hours (unhealthy)   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   zabbix_zabbix-web-nginx-pgsql_1
9646b348fb66        zabbix/zabbix-snmptraps:alpine-4.4-latest         "/usr/bin/supervisor…"   16 hours ago        Up 16 hours               0.0.0.0:162->162/udp                       zabbix_zabbix-snmptraps_1

Is there something I'm missing?

JustDevZero commented 4 years ago

It looks like the network is not working properly for that image at all, which is weird...

ubuntu@ip-172-30-24-157:~/zabbix$ docker-compose exec zabbix-agent sh
WARNING: Some services (zabbix-agent, zabbix-server, zabbix-snmptraps, zabbix-web-nginx-pgsql) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use `docker stack deploy` to deploy to a swarm.
/var/lib/zabbix # ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
^C
--- 8.8.8.8 ping statistics ---
6 packets transmitted, 0 received, 100% packet loss, time 115ms

Can it be a IP collision? :/

subkhanave commented 4 years ago

As you can see on the yaml file, the service zabbix-agent use network zbx_net_backend which stated as internal network "internal = true"

To monitor the zabbix agent just change on the zabbix web from 127.0.0.1 to one of the aliases (eg. zabbix-agent), that should resolve the issue. But if you want to expose zabbix agent to external, you can add zbx_net_frontend: under zabbix-agent service, the port will be shown in docker container ls output. So in the end zabbix-agent will have 2 interface which you can check using ip addr show inside the container.

JustDevZero commented 4 years ago

Thanks! Didn't notice that... I was going nuts for being stubborn. As you said using the alias worked without any problem. :+1:

I think this can be closed.

alexxioup commented 4 years ago

Hi all. I don t have very clear Where i have to put the alias on the zabbix web. Thanks.

ezar commented 3 years ago

Same here! Where I need to put aliases?

morfozoid commented 1 year ago

Hey. You need to go to zabbix web console and change inventory of host zabbix-server. Interfaces>Agent>DNS name: "zabbix-agent".