Zabbix Installation and Configuration
Zabbix is a mature, enterprise-grade monitoring platform offering real-time monitoring and alerting capabilities. It provides agentless monitoring through SNMP, JMX, and agent-based monitoring for deep host visibility. This comprehensive guide covers server installation, frontend setup, agent deployment, template configuration, trigger creation, and notifications.
Table of Contents
- Introduction
- System Requirements
- Database Setup
- Zabbix Server Installation
- Zabbix Frontend Installation
- Initial Configuration
- Installing Zabbix Agents
- Host and Template Management
- Creating Custom Items and Triggers
- Notifications and Alerting
- Auto-Discovery
- Troubleshooting
- Conclusion
Introduction
Zabbix excels at handling complex monitoring scenarios with multiple monitoring types, custom metrics, and detailed alerting rules. Its agent-based architecture provides comprehensive system insights while supporting agentless monitoring for network devices and services.
System Requirements
Before installation, verify your system meets requirements:
- Linux kernel 2.6.32 or later
- At least 2GB RAM (4GB recommended)
- 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)
Database Setup
PostgreSQL Database Setup
# 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 Database Setup
# 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 Server Installation
Step 1: Add 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
Step 2: Import Database 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;"
Step 3: Configure Zabbix Server
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
Step 4: Enable and Start Server
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 Installation
Step 1: Configure 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
Step 2: Configure 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
Step 3: Complete Web Setup
Access http://your-server/zabbix and complete the installation wizard. The wizard will:
- Check PHP settings
- Verify database connection
- Enter database configuration
- Set server details
- Verify all settings
- Complete installation
Default credentials: Admin / zabbix
Initial Configuration
Change Admin Password
- Log in as Admin
- User settings > Change password
- Set a strong password
Configure Global Settings
Navigate to Administration > General > Other:
Server name: Infrastructure Monitoring
Server timezone: Your timezone
Authentication: Internal
Hashing algorithm: bcrypt
Set Host Groups and Users
# 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
Installing Zabbix Agents
On 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
On 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
Verify 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
Add Host via Web Interface
- Configuration > Hosts > Create Host
- Enter hostname and select host group
- Add network interface (IP:port)
- Select templates
- Enable host
- Save
Create 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 Triggers
Create Custom Item
Via web interface: Configuration > Templates > Items > Create Item
Example - 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
Create 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
Create Trigger
Example: Alert 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
Notifications and Alerting
Configure Email Notifications
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
Configure Notification Recipients
- Administration > Users
- Select user
- Media tab
- Add media (Email)
- Enter email address
- Set severity level
Create Action
Configuration > Actions > Create 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
Test Notifications
# 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
Enable Network Discovery
Configuration > Discovery:
Name: Network Discovery
IP range: 192.168.1.0-192.168.1.255
Delay: 3600
Checks: Zabbix agent
Create Discovery Rule
Configuration > Discovery rules:
Name: Service Discovery
IP range: 192.168.1.0/24
Checks: Zabbix agent, SNMP
Port range: 10050
Auto-Registration
When discovered agents auto-register:
Configuration > Actions > Event source: Auto-registration
Operations:
- Add host to groups: Linux Servers
- Link template: Template OS Linux
- Enable host
Troubleshooting
Verify Server 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
Check Item History
# Query recent values
psql -U zabbix -d zabbix << EOF
SELECT itemid, MAX(clock) FROM history WHERE itemid = 12345 GROUP BY itemid;
EOF
Conclusion
Zabbix provides enterprise-grade monitoring with flexible item and trigger configuration. By following this guide, you've established comprehensive host monitoring with automated discovery and alerting. Focus on building templates for your specific applications, setting appropriate trigger thresholds based on your infrastructure, and continuously refining alert routing to reduce noise. Regular maintenance of discovered hosts, periodic template updates, and ongoing dashboard improvements ensure your monitoring remains effective and relevant.


