diff --git a/.env.pub b/.env.pub new file mode 100644 index 0000000..33878bb --- /dev/null +++ b/.env.pub @@ -0,0 +1,50 @@ +#VARIABLES PARA LAS CONFIGURACIONES DE RED net0 +SUBNET=10.50.50.0/24 +GATEWAY=10.50.50.1 +ZBX_DB_IP=10.50.50.2 +ZBX_SERVER_IP=10.50.50.3 +ZBX_TRAPS_IP=10.50.50.4 +ZBX_DASHBOARD_IP=10.50.50.5 +ZBX_AGENT2_IP=10.50.50.6 + +#PARA EL DASHBOARD +PHP_TZ=America/Costa_Rica +PORT_HTTP=8080 +PORT_HTTPS=8443 + +#VARIABLES PARA LA CONEXION A LA BASE DE DATOS +#CAMBIAR +POSTGRES_USER= +#CAMBIAR +POSTGRES_PASSWORD= +POSTGRES_DB=zabbix +DB_SERVER_HOST=zabbix-postgres-bd + +#SERVIDOR +ZBX_SERVER_HOST=zabbix-server-pgsql +ZBX_SERVER_PORT=10051 + +#SNMPTRAPS +ZBX_ENABLE_SNMP_TRAPS=true + +#AGENTE +ZBX_ACTIVE_ALLOW=true +ZBX_REFRESH_ACTIVE_CHECKS=60 +ZBX_HOSTNAME=docker_Host +# *** CLAVE IMPORTANTE *** +# Esto debe coincidir con lo configurado en tu regla +# "Configuration → Actions → Auto registration" +ZBX_METADATA=docker-autoreg + +#VARIABLES DE ENTORNO PARA REVISAR SE APLICAN EN EL SERVIDOR + +#ZBX_STARTPOLLERS=5 # 20 +#ZBX_STARTPOLLERSUNREACHABLE=1 # 10 +#ZBX_STARTTRAPPERS=5 # 15 +#ZBX_STARTPINGERS=1 # 10 +#ZBX_STARTDISCOVERERS=1 # 5 +#ZBX_CACHESIZE=8M # 128M +#ZBX_HISTORYCACHESIZE=16M # 64M +#ZBX_HISTORYINDEXCACHESIZE=4M # 32M +#ZBX_TRENDCACHESIZE=4M # 2M +#ZBX_VALUECACHESIZE=8M # 64M diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d26fae --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Docker +.env +#data/ +*.log + +# Editor +.vscode/ +.idea/ + +# Certificados para https +data/dashboard/certificados/* \ No newline at end of file diff --git a/README.md b/README.md index 85bac92..e8abbfe 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,243 @@ -# zabbix -Zabbix server +# **Zabbix Monitoring Stack – Docker Compose** + +![Docker](https://img.shields.io/badge/Docker-Compose-2496ED?style=for-the-badge&logo=docker) +![Zabbix](https://img.shields.io/badge/Zabbix-7.4.6-D50000?style=for-the-badge) +![PostgreSQL](https://img.shields.io/badge/PostgreSQL-17.6-336791?style=for-the-badge&logo=postgresql) + +Stack completo y modular para desplegar **Zabbix 7.4** en entornos de producción utilizando **Docker Compose**. +Incluye base de datos optimizada, servidor, interfaz web, SNMP traps y agente2 local. + +--- + +# 📦 **Arquitectura del Stack** + +| Componente | Versión | Descripción | +| ---------------------- | ------- | --------------------------------------- | +| **PostgreSQL** | 17.6 | Base de datos principal de Zabbix | +| **Zabbix Server** | 7.4.6 | Motor central de monitoreo | +| **Zabbix Web** | 7.4.6 | Interfaz gráfica (Nginx + PHP-FPM) | +| **Zabbix Agent2** | 7.4.3 | Agente avanzado para monitoreo del host | +| **SNMP Trap Receiver** | 7.4.6 | Receptor de traps SNMP puerto 162 | + +--- + +Diagrama Zabbix Docker + +--- + +# 🔌 **Mapa de Puertos** + +| Puerto | Protocolo | Uso | +| --------- | --------- | ------------------------ | +| **8080** | TCP | Interfaz Web (HTTP) | +| **4443** | TCP | Interfaz Web (HTTPS) | +| **10051** | TCP | Server ↔ Agentes activos | +| **162** | UDP | Recepción de SNMP traps | + +--- + +# 💾 **Volúmenes Persistentes** + +| Volumen | Contenedor | Uso | +| ------------------------- | ------------- | ---------------------------- | +| `zabbix-postgresdb` | PostgreSQL | Base de datos Zabbix | +| `zabbix-server` | Zabbix Server | Configuración y runtime | +| `zabbix-snmptraps` | Zabbix Server | Almacenamiento de traps SNMP | +| `zabbix_dashboard_config` | Zabbix Web | Configuración del frontend | +| `zabbix_certificados` | Zabbix Web | Certificados SSL/TLS | + +## Todos los volúmenes persisten automáticamente entre reinicios. + +# 💾 **Bind Mounts** + +| Bind Mounts | Contenedor | Uso | +| ---------------------------------- | ---------------- | ------------------------------ | +| `/backups` | PostgreSQL | Backups de la Base de Datos | +| `/usr/lib/zabbix/externalscripts` | Zabbix Server | Script externos | +| `/usr/lib/zabbix/alertscripts` | Zabbix Server | Script para Alertas | +| `/usr/share/snmp/mibs` | Zabbix snmptraps | Mibs externas | +| `/var/lib/zabbix/snmptrapd_config` | Zabbix snmptraps | Configuración de snmptraps | +| `/sys` | Zabbix Agent2 | Acceso para reporte a Servidor | +| `/proc` | Zabbix Agent2 | Acceso para reporte a Servidor | +| `/var/run/docker.sock` | Zabbix Agent2 | Acceso para reporte a Servidor | + +--- + +# 🚀 **Implementación Rápida** + +### **1. Prerrequisitos** + +- **Docker Engine 20.10+** +- **Docker Compose 2.0+** +- **Puertos 8080/4443/10051/162 disponibles** + +--- + +## **2. Se crea el usuario zabbix** + +Se debe crear un usuario en el host y luego agregarlo al grupo Docker para que el agente pueda leer las métricas y no tener que correrlo como root + +```bash +useradd -r -s /bin/false -M -u 1001 zabbix-agente +usermod -aG docker zabbix-agente +``` + +Se verifica: + +```bash +id zabbix-agente +groups zabbix-agente +``` + +Probamos que el usuario tena acceso al socket + +```bash +sudo -u zabbix-agente docker version +sudo -u zabbix-agente curl --unix-socket /var/run/docker.sock http://localhost/version +``` + +Debemos iniciar el contenedor del zabbix agente como usuario zabbix-agente=1001 y grupo Docker=996, 1001:996 + +## **3. Descargar o Clonar el repositorio** + +```bash +wget https://github.com/rsol9000/zabbix-docker/archive/main.zip -O zabbix-stack.zip +cd zabbix-stack +``` + +```bash +git clone +cd zabbix-stack +``` + +--- + +## **4. Configurar variables de entorno** + +```bash +cp .env.pub .env +nano .env +``` + +### **Variables críticas** + +```env +POSTGRES_USER=zabbix_admin +POSTGRES_PASSWORD=super_secure_password +``` + +### **Variables opcionales** + +```env +ZBX_SERVER_HOST=zabbix-server +ZBX_SERVER_NAME=Zabbix Monitoring +ZBX_TIMEZONE=America/Costa_Rica +``` + +--- + +# ▶️ **Despliegue** + +```bash +docker-compose up -d +``` + +Comprobar estado: + +```bash +docker-compose ps +``` + +Logs del servidor: + +```bash +docker-compose logs -f zabbix-server +``` + +--- + +# 🌐 **Acceso a la Interfaz Web** + +| Protocolo | URL | +| --------- | ---------------------------- | +| **HTTP** | `http://:8080` | +| **HTTPS** | `https://:4443` | + +--- + +# 🔐 **Habilitar HTTPS** + +```bash +cp ssl/cert.pem ssl/key.pem ./certificates/ +docker-compose restart zabbix-web +``` + +Requiere certificados válidos (Let’s Encrypt, ACME u otros). + +--- + +# 🖥️ **Agentes Zabbix** + +El stack incluye **Zabbix Agent2 local**. +Para agentes remotos: + +```bash +ZabbixServer= +ZabbixServerActive= +``` + +Ideal para servidores Linux, contenedores o equipos remotos. + +--- + +# 📡 **Monitoreo por SNMP Traps** + +El receptor escucha en **UDP 162**. + +Ejemplo para routers/switches: + +``` +snmp-server host traps version 2c public +``` + +--- + +# 🛠️ **Comandos Útiles de Administración** + +```bash +# Estado del stack +docker-compose ps + +# Logs globales +docker-compose logs -f + +# Backup de la base de datos +docker-compose exec postgres pg_dump -U $POSTGRES_USER zabbix > backup.sql + +# Reinicio de servicios +docker-compose restart zabbix-server + +# Bajar el stack completo +docker-compose down +``` + +--- + +# 🔒 **Recomendaciones de Seguridad** + +- Cambiar todas las contraseñas por defecto +- Restringir puertos con firewall (ufw, nftables) +- Usar HTTPS en producción +- Implementar políticas de backup automático +- Revisar logs de acceso y traps regularmente +- Mantener las imágenes de Docker actualizadas + +--- + +# 📝 **Notas de Versión** + +- **Zabbix 7.4.6** — Versión LTS estable +- **PostgreSQL 17.6** — Óptimo para cargas intensivas +- **Agent2** — Mejor capacidad para contenedores, plugins modernos + +--- diff --git a/config/zabbix-server.conf b/config/zabbix-server.conf new file mode 100644 index 0000000..e69de29 diff --git a/config/zabbix_agent2.conf b/config/zabbix_agent2.conf new file mode 100644 index 0000000..e69de29 diff --git a/data/server/server.conf b/data/server/server.conf new file mode 100644 index 0000000..2c3fe93 --- /dev/null +++ b/data/server/server.conf @@ -0,0 +1 @@ +#Configuracion del servidor \ No newline at end of file diff --git a/diagramas/zabbix-docker.drawio b/diagramas/zabbix-docker.drawio new file mode 100644 index 0000000..670cbfc --- /dev/null +++ b/diagramas/zabbix-docker.drawio @@ -0,0 +1,531 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/diagramas/zabbix-docker.png b/diagramas/zabbix-docker.png new file mode 100644 index 0000000..7201a56 Binary files /dev/null and b/diagramas/zabbix-docker.png differ diff --git a/diagramas/zabbix-docker.svg b/diagramas/zabbix-docker.svg new file mode 100644 index 0000000..89dadea --- /dev/null +++ b/diagramas/zabbix-docker.svg @@ -0,0 +1,4 @@ + + + +Z
WEB BROWSER
WEB BROWSER
Z
Name: Zabbix-server-pgsql
IP: 10.50.50.4
S.O:Alpine
Name: Zabbix-server-pgsql...
10051/TCP
10051/TCP
Name: Zabbix-snmptraps
IP: 10.50.50.5
S.O:Alpine
Name: Zabbix-snmptraps...
1162/TCP
1162/TCP
5432/TCP
5432/TCP
Name: Zabbix-postgres-bd
IP: 10.50.50.3
S.O:Alpine
Name: Zabbix-postgres-bd...
Name: Zabbix-dashboard
IP: 10.50.50.2
S.O:Alpine
Name: Zabbix-dashboar...
8080/TCP
8080/TCP
8443/TCP
8443/TCP
4443/TCP
4443/TCP
8080/TCP
8080/TCP
10051/TCP
10051/TCP
162/TCP
162/TCP
Virtual CPUs:
RAM:
Almacenamiento:
S.O: Linux-debian 12
Virtual CPUs:...
ZABBIX HOST
ZABBIX HOST
Name: Zabbix-agent2
IP: 10.50.50.6
S.O:Ubuntu
Name: Zabbix-agent2...
10050/TCP
10050/TCP
FQDN: docker.siua.ac.cr
FQDN: docker.siua.ac.cr
ephimeral port
ephimeral port
ephimeral port
ephimeral port
/etc/ssl/nginx
/etc/ssl/nginx
/usr/share/zabbix
/usr/share/zabbix
/var/lib/zabbix/snmptraps
/var/lib/zabbix/snmptra...
/var/lib/postgresql/data
/var/lib/postgresql/data
/backups
/backups
/proc
/proc
/sys
/sys
/var/run/docker.sock
/var/run/docker.sock
/usr/lib/zabbix/alertscripts
/usr/lib/zabbix/alertscri...
/var/lib/zabbix
/var/lib/zabbix
/usr/lib/zabbix/externalscripts
/usr/lib/zabbix/externalscri...
/usr/share/snmp/mibs
/usr/share/snmp/...
/var/lib/zabbix/snmptrapd_config
/var/lib/zabbix/...
161/TCP
161/TCP
ephimeral port
ephimeral p...
Equipos Monitoreados via SNMP
Equipos Monitoreados via SNMP
ZABBIX AGENT2 ACTIVO
ZABBIX AGENT2 ACTIVO
10050/TCP
10050/TCP
ephimeral port
ephimeral port
\ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..038707d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,157 @@ +version: "3.9" + +############################ +# VOLUMENES +############################ +volumes: + zabbix-postgresdb: + zabbix-server: + zabbix-snmptraps: + zabbix_dashboard_config: + zabbix_certificados: + +############################ +# RED +############################ +networks: + net0: + driver: bridge + ipam: + config: + - subnet: ${SUBNET} + gateway: ${GATEWAY} + +############################ +# SERVICIOS +############################ +services: + ########################### + # POSTGRES + ########################### + zabbix-postgres-bd: + image: postgres:17.6 + container_name: zabbix-postgres-bd + restart: unless-stopped + networks: + net0: + ipv4_address: ${ZBX_DB_IP} + environment: + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB} + volumes: + - zabbix-postgresdb:/var/lib/postgresql/data + - ./backups:/backups + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"] + interval: 30s + timeout: 10s + retries: 3 + + ########################### + # SNMP TRAPS + ########################### + zabbix-snmptraps: + image: zabbix/zabbix-snmptraps:latest + container_name: zabbix-snmptraps + restart: unless-stopped + networks: + net0: + ipv4_address: ${ZBX_TRAPS_IP} + ports: + - "162:1162/udp" + volumes: + - zabbix-snmptraps:/var/lib/zabbix/snmptraps:rw + - ./mibs:/usr/share/snmp/mibs:ro + #security_opt: + # - seccomp=unconfined + + ########################### + # ZABBIX SERVER + ########################### + zabbix-server-pgsql: + image: zabbix/zabbix-server-pgsql:latest + container_name: zabbix-server-pgsql + restart: unless-stopped + networks: + net0: + ipv4_address: ${ZBX_SERVER_IP} + depends_on: + zabbix-postgres-bd: + condition: service_healthy + environment: + - DB_SERVER_HOST=${ZBX_DB_IP} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB} + - ZBX_ENABLE_SNMP_TRAPS=${ZBX_ENABLE_SNMP_TRAPS} + ports: + - "10051:10051" + volumes: + - zabbix-server:/var/lib/zabbix + - ./alertscripts:/usr/lib/zabbix/alertscripts:ro + - ./externalscripts:/usr/lib/zabbix/externalscripts:ro + - zabbix-snmptraps:/var/lib/zabbix/snmptraps + #security_opt: + # - seccomp=unconfined + healthcheck: + test: + [ + "CMD-SHELL", + "timeout 5 bash -c 'cat < /dev/null > /dev/tcp/localhost/10051' || exit 1", + ] + interval: 30s + timeout: 10s + retries: 3 + + ########################### + # ZABBIX WEB (NGINX) + ########################### + zabbix-dashboard: + image: zabbix/zabbix-web-nginx-pgsql:latest + container_name: zabbix-dashboard + restart: unless-stopped + networks: + net0: + ipv4_address: ${ZBX_DASHBOARD_IP} + depends_on: + zabbix-postgres-bd: + condition: service_healthy + zabbix-server-pgsql: + condition: service_healthy + environment: + - ZBX_SERVER_HOST=${ZBX_SERVER_IP} + - DB_SERVER_HOST=${ZBX_DB_IP} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB} + - PHP_TZ=${PHP_TZ} + ports: + - "${PORT_HTTPS}:8443" + - "${PORT_HTTP}:8080" + volumes: + - zabbix_certificados:/etc/ssl/nginx:ro + - zabbix_dashboard_config:/usr/share/zabbix + #security_opt: + # - seccomp=unconfined + + ########################## + # ZABBIX AGENT 2 + ########################### + zabbix-agent2: + image: zabbix/zabbix-agent2:ubuntu-7.4.3 + container_name: zabbix-agent2 + restart: unless-stopped + networks: + net0: + ipv4_address: ${ZBX_AGENT2_IP} + user: "1001:996" + environment: + - ZBX_SERVER_HOST=${ZBX_SERVER_IP} + - ZBX_ACTIVE_ALLOW=${ZBX_ACTIVE_ALLOW} + - ZBX_HOSTNAME=${ZBX_HOSTNAME} + - ZBX_METADATA=${ZBX_METADATA} + volumes: + - /proc:/proc + - /sys:/sys:ro + - /var/run/docker.sock:/var/run/docker.sock