Zabbix Instalación y Configuración
Zabbix is a mature, enterprise-grade monitoreo platform offering real-time monitoreo and alerting capabilities. It provides agentless monitoreo through SNMP, JMX, and agent-based monitoreo for deep host visibility. This comprehensive guide covers server installation, frontend setup, agent despliegue, template configuration, trigger creation, and notifications.
Tabla de Contenidos
- Introducción
- Requisitos del Sistema
- Base de Datos Configuración
- Zabbix Servidor Instalación
- Zabbix Frontend Instalación
- Initial Configuración
- Instalando Zabbix Agents
- Host and Template Management
- Creating Custom Items and Disparadores
- Notificaciones and Alerting
- Auto-Discovery
- [Solución de Problemas](#solución de problemas)
- Conclusión
Introducción
Zabbix excels at handling complex monitoreo scenarios with multiple monitoreo types, custom metrics, and detailed alerting rules. Its agent-based architecture provides comprehensive system insights Mientras supporting agentless monitoreo for network devices and services.
Requisitos del Sistema
Before installation, Verifique su system meets requirements:
- Linux kernel 2.6.32 or later
- At least 2GB RAM (4GB Recomendado)
- 10GB storage for database (scale based on history retention)
- Supported databases: MySQL, PostgreSQL, Oracle
- Supported web servers: Nginx, Apache
- PHP 7.2.5 or later (for frontend)
- GCC compiler (for agent compilation)
Base de Datos Configuración
PostgreSQL Base de Datos Configuración
# Install PostgreSQL
sudo apt-get update
sudo apt-get install -y postgresql postgresql-contrib
# Start and enable service
sudo systemctl enable postgresql
sudo systemctl start postgresql
# Create Zabbix database and user
sudo -u postgres psql << EOF
CREATE USER zabbix WITH PASSWORD 'zabbix_password';
CREATE DATABASE zabbix OWNER zabbix;
GRANT ALL PRIVILEGES ON DATABASE zabbix TO zabbix;
\q
EOF
# Verify connection
psql -h localhost -U zabbix -d zabbix -c "SELECT VERSION();"
MySQL Base de Datos Configuración
# Install MySQL
sudo apt-get install -y mysql-server
# Secure installation
sudo mysql_secure_installation
# Create Zabbix database
sudo mysql << EOF
CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'zabbix_password';
CREATE DATABASE zabbix CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost';
FLUSH PRIVILEGES;
\q
EOF
Zabbix Servidor Instalación
Paso 1: Agregar Repository and Install
# Add Zabbix repository (for Ubuntu)
wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4+ubuntu$(lsb_release -rs)_all.deb
sudo dpkg -i zabbix-release_6.0-4+ubuntu$(lsb_release -rs)_all.deb
sudo apt-get update
# Install Zabbix server and agent
sudo apt-get install -y zabbix-server-pgsql zabbix-frontend-php zabbix-agent zabbix-sql-scripts
Paso 2: Import Base de Datos Schema
# Import Zabbix schema (PostgreSQL)
cd /usr/share/zabbix-sql-scripts/postgresql
sudo -u zabbix psql zabbix < server.sql
# Verify import
psql -h localhost -U zabbix -d zabbix -c "SELECT COUNT(*) FROM hosts;"
Paso 3: Configurar Zabbix Servidor
Edit /etc/zabbix/zabbix_server.conf:
sudo tee /etc/zabbix/zabbix_server.conf > /dev/null << 'EOF'
# Database connection
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix_password
DBPort=5432
# Server settings
ListenPort=10051
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
# Performance tuning
StartPollers=4
StartPollersUnreachable=1
StartTrappers=2
StartHTTPPollers=1
StartDBSyncers=1
StartLookups=1
CacheSize=8M
HistoryCacheSize=16M
HistoryIndexCacheSize=4M
TrendCacheSize=4M
ValueCacheSize=8M
# Data retention
HousekeepingFrequency=1
MaxHousekeeperDelete=5000
MaxHousekeeperDeleteHistory=100000
# Timeout settings
Timeout=3
UnreachablePeriod=45
UnavailableDelay=60
# External scripts
ExternalScripts=/usr/lib/zabbix/externalscripts
# SNMP community strings
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
# Alerting
AlertScriptsPath=/usr/lib/zabbix/alertscripts
EOF
# Set permissions
sudo chown zabbix:zabbix /etc/zabbix/zabbix_server.conf
sudo chmod 644 /etc/zabbix/zabbix_server.conf
Paso 4: Habilitar and Iniciar Servidor
sudo systemctl enable zabbix-server
sudo systemctl start zabbix-server
sudo systemctl status zabbix-server
# Check logs
sudo tail -f /var/log/zabbix/zabbix_server.log
Zabbix Frontend Instalación
Paso 1: Configurar PHP
# Install Nginx and PHP
sudo apt-get install -y nginx php-fpm php-gd php-mysql php-bcmath php-mbstring php-xml
# Configure PHP for Zabbix
sudo tee /etc/php/8.1/fpm/php.ini.d/zabbix.ini > /dev/null << 'EOF'
max_execution_time = 300
memory_limit = 256M
post_max_size = 32M
upload_max_filesize = 32M
max_input_time = 300
always_populate_raw_post_data = -1
date.timezone = UTC
EOF
sudo systemctl restart php-fpm
Paso 2: Configurar Nginx
sudo tee /etc/nginx/sites-available/zabbix > /dev/null << 'EOF'
server {
listen 80;
server_name zabbix.example.com;
access_log /var/log/nginx/zabbix_access.log;
error_log /var/log/nginx/zabbix_error.log;
location / {
root /usr/share/zabbix;
index index.php index.html;
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/zabbix$fastcgi_script_name;
include fastcgi_params;
}
}
EOF
# Enable site
sudo ln -s /etc/nginx/sites-available/zabbix /etc/nginx/sites-enabled/
# Test and restart
sudo nginx -t
sudo systemctl restart nginx
Paso 3: Complete Web Configuración
Access http://your-server/zabbix and complete La instalación wizard. The wizard will:
- Verificar PHP settings
- Verificar database connection
- Enter database configuration
- Set server details
- Verificar all settings
- Complete installation
Default credentials: Admin / zabbix
Initial Configuración
Change Admin Password
- Registro in as Admin
- Usuario settings > Change password
- Set a strong password
Configurar Global Configuraciones
Navigate to Administration > General > Other:
Server name: Infrastructure Monitoring
Server timezone: Your timezone
Authentication: Internal
Hashing algorithm: bcrypt
Set Host Grupos and Usuarios
# Via API - Create host group
curl -X POST -H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "hostgroup.create",
"params": {
"name": "Linux Servers"
},
"auth": "YOUR_AUTH_TOKEN",
"id": 1
}' \
http://localhost/api_jsonrpc.php
Instalando Zabbix Agents
En Ubuntu/Debian Hosts
# Install agent
sudo apt-get update
sudo apt-get install -y zabbix-agent
# Configure agent
sudo tee /etc/zabbix/zabbix_agentd.conf > /dev/null << 'EOF'
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.1.10
ServerActive=192.168.1.10:10051
Hostname=server-name
HostnameItem=system.hostname
RefreshActiveChecks=120
BufferSend=5
BufferSize=100
Timeout=30
ListenPort=10050
Include=/etc/zabbix/zabbix_agentd.d/*.conf
EOF
# Start service
sudo systemctl enable zabbix-agent
sudo systemctl start zabbix-agent
sudo systemctl status zabbix-agent
En CentOS/RHEL Hosts
# Add repository
sudo rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-1.el8.noarch.rpm
# Install agent
sudo yum install -y zabbix-agent
# Configure and start
sudo systemctl enable zabbix-agent
sudo systemctl start zabbix-agent
Verificar Agent Communication
# From Zabbix server, test agent
zabbix_get -s 192.168.1.20 -p 10050 -k "system.hostname"
# Check agent log
tail -f /var/log/zabbix/zabbix_agentd.log
Host and Template Management
Agregar Host via Web Interface
- Configuración > Hosts > Crear Host
- Enter hostname and select host group
- Agregar network interface (IP:port)
- Select templates
- Habilitar host
- Save
Crear Custom Template
# Via API
curl -X POST -H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "template.create",
"params": {
"host": "Custom Linux Template",
"groups": [{"groupid": "10"}]
},
"auth": "YOUR_AUTH_TOKEN",
"id": 1
}' \
http://localhost/api_jsonrpc.php
Apply Built-in Templates
Common templates to apply:
- Template OS Linux
- Template App MySQL
- Template App PostgreSQL
- Template App Nginx
- Template Net SNMP
Creating Custom Items and Disparadores
Crear Custom Item
Via web interface: Configuración > Templates > Items > Crear Item
Ejemplo - Monitor custom log file:
Name: Application Error Count
Type: Zabbix agent (active)
Key: log[/var/log/app/error.log,"error",]
Type of information: Text
Update interval: 1m
Value preprocessing: Regular expression matching
Crear Items via CLI
# Create item for custom metric
sudo tee /etc/zabbix/zabbix_agentd.d/custom.conf > /dev/null << 'EOF'
UserParameter=app.errors,grep -c "error" /var/log/app/error.log
UserParameter=system.diskfree[*],df -B1 $1 | tail -1 | awk '{print $$4}'
EOF
sudo systemctl restart zabbix-agent
Crear Disparador
Ejemplo: Alerta if CPU usage exceeds 80%
Name: High CPU Usage
Expression: {Template OS Linux:system.cpu.load[percpu,avg1].last()}>2.0
Severity: Warning
Recovery message: CPU usage returned to normal
Notificaciones and Alerting
Configurar Email Notificaciones
Administration > Media types > Email:
SMTP server: smtp.gmail.com
SMTP server port: 587
SMTP helo: zabbix.example.com
SMTP email: [email protected]
Connection security: STARTTLS
Username: [email protected]
Password: app-password
Configurar Notificación Recipients
- Administration > Usuarios
- Select user
- Media tab
- Agregar media (Email)
- Enter email address
- Set severity level
Crear Acción
Configuración > Acciones > Crear action
Name: Alert on High CPU
Trigger: High CPU Usage
Operations:
- Send message to user groups
- Default operation step duration: 10m
- Custom message: CPU usage is high on {HOST.NAME}
Recovery operations:
- Send message to user groups
- Default message: CPU usage normalized
Prueba Notificaciones
# Send test notification
curl -X POST -H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "user.get",
"params": {"selectMedias": "extend"},
"auth": "YOUR_AUTH_TOKEN",
"id": 1
}' \
http://localhost/api_jsonrpc.php
Auto-Discovery
Habilitar Red Discovery
Configuración > Discovery:
Name: Network Discovery
IP range: 192.168.1.0-192.168.1.255
Delay: 3600
Checks: Zabbix agent
Crear Discovery Rule
Configuración > Discovery rules:
Name: Service Discovery
IP range: 192.168.1.0/24
Checks: Zabbix agent, SNMP
Port range: 10050
Auto-Registration
Cuando discovered agents auto-register:
Configuración > Acciones > Evento source: Auto-registration
Operations:
- Add host to groups: Linux Servers
- Link template: Template OS Linux
- Enable host
Solución de Problemas
Verificar Servidor Connectivity
# Test server is running
zabbix_server -c /etc/zabbix/zabbix_server.conf -R config_cache_reload
# Check server ports
netstat -tlnp | grep zabbix
# Verify database
psql -h localhost -U zabbix -d zabbix -c "SELECT COUNT(*) FROM hosts;"
Debug Agent Issues
# Test agent manually
/usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf -t system.hostname
# Enable debug logging
sudo sed -i 's/^# DebugLevel=.*/DebugLevel=5/' /etc/zabbix/zabbix_agentd.conf
sudo systemctl restart zabbix-agent
sudo tail -f /var/log/zabbix/zabbix_agentd.log
Verificar Item History
# Query recent values
psql -U zabbix -d zabbix << EOF
SELECT itemid, MAX(clock) FROM history WHERE itemid = 12345 GROUP BY itemid;
EOF
Conclusión
Zabbix provides enterprise-grade monitoreo with flexible item and trigger configuration. By following Esta guía, you've established comprehensive host monitoreo with automated discovery and alerting. Focus on building templates for your specific applications, setting appropriate trigger thresholds based En su infrastructure, and continuously refining alert routing to reduce noise. Regular maintenance of discovered hosts, periodic template updates, and ongoing dashboard improvements Asegúrese de que su monitoreo remains effective and relevant.


