Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .env.pub
Original file line number Diff line number Diff line change
@@ -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=<USUARIO BD>
#CAMBIAR
POSTGRES_PASSWORD=<CONTRASEÑA BD>
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
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Docker
.env
#data/
*.log

# Editor
.vscode/
.idea/

# Certificados para https
data/dashboard/certificados/*
245 changes: 243 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 |

---

<img src="./diagramas/zabbix-docker.png" alt="Diagrama Zabbix Docker" width=80%>

---

# 🔌 **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 <repository-url>
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://<IP-SERVIDOR>:8080` |
| **HTTPS** | `https://<IP-SERVIDOR>: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=<SERVER_IP>
ZabbixServerActive=<SERVER_IP>
```

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 <ZABBIX_SERVER_IP> 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

---
Empty file added config/zabbix-server.conf
Empty file.
Empty file added config/zabbix_agent2.conf
Empty file.
1 change: 1 addition & 0 deletions data/server/server.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#Configuracion del servidor
531 changes: 531 additions & 0 deletions diagramas/zabbix-docker.drawio

Large diffs are not rendered by default.

Binary file added diagramas/zabbix-docker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions diagramas/zabbix-docker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading