Software & Configuration

Zabbix Monitoring Setup

Install and configure Zabbix 7.x enterprise monitoring platform with agents and alerting

What is Zabbix?

Zabbix is an enterprise-class open-source monitoring platform that collects metrics from servers, applications, and network devices. It supports both agentless monitoring (via SNMP, Ping, HTTP) and agent-based monitoring (Zabbix Agent) with advanced features like auto-discovery, custom triggers, and flexible alerting.

Installation on Ubuntu/Debian

Step 1: Add Zabbix Repository

# Ubuntu 22.04 LTS
wget https://repo.zabbix.com/zabbix/7.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_7.0-1+ubuntu22.04_all.deb
sudo dpkg -i zabbix-release_7.0-1+ubuntu22.04_all.deb
sudo apt update

# Debian 12
wget https://repo.zabbix.com/zabbix/7.0/debian/pool/main/z/zabbix-release/zabbix-release_7.0-1+debian12_all.deb
sudo dpkg -i zabbix-release_7.0-1+debian12_all.deb
sudo apt update

Step 2: Install Zabbix Components

Install server, frontend, and agent:

sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-agent2 zabbix-sql-scripts

Install PHP-FPM and Nginx (if not already installed):

sudo apt install php8.1-fpm php8.1-mysql php8.1-gd php8.1-bcmath php8.1-ldap
sudo apt install nginx

Step 3: Create Zabbix Database

Create database and user in MySQL:

sudo mysql -u root -p
CREATE DATABASE zabbix CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'zabbixtpass123!';
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 4: Import Zabbix Schema

sudo zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql -u zabbix -p zabbix

Enter the password for the zabbix database user when prompted.

Zabbix Server Configuration

Edit /etc/zabbix/zabbix_server.conf:

# Database settings
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbixtpass123!
DBPort=3306

# Server settings
Server=127.0.0.1
ListenPort=10051
StartAgents=0

# Logs
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=100

# Alert script path (for custom notifications)
AlertScriptsPath=/usr/lib/zabbix/alertscripts

# External scripts
ExternalScripts=/usr/lib/zabbix/externalscripts

# Enable SNMP traps
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
StartSNMPTrapper=0

# Performance tuning
CacheSize=32M
HistoryCacheSize=16M
HistoryIndexCacheSize=4M

Start and enable the service:

sudo systemctl start zabbix-server-mysql
sudo systemctl enable zabbix-server-mysql
sudo systemctl status zabbix-server-mysql

Nginx Configuration for Zabbix Frontend

Create /etc/nginx/sites-available/zabbix:

upstream php_fpm {
    server unix:/run/php/php8.1-fpm.sock;
}

server {
    listen 80;
    listen [::]:80;
    server_name monitor.example.com zabbix.example.com;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name monitor.example.com zabbix.example.com;

    root /usr/share/zabbix;
    index index.php;

    ssl_certificate /etc/letsencrypt/live/monitor.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/monitor.example.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

    client_max_body_size 50M;

    # Deny access to sensitive locations
    location ~ ^/conf/ {
        deny all;
    }

    location ~ ^/include/ {
        deny all;
    }

    location ~ ^/local/ {
        deny all;
    }

    # PHP handler
    location ~ \.php$ {
        fastcgi_pass php_fpm;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param PHP_VALUE "memory_limit=256M
            max_execution_time=300
            post_max_size=32M
            upload_max_filesize=32M";
    }

    # Static assets
    location ~* \.(js|css|png|jpg|gif|ico|svg|woff|woff2|ttf)$ {
        expires 30d;
        add_header Cache-Control "public, immutable";
    }

    # Security headers
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-XSS-Protection "1; mode=block" always;
}

Enable and reload:

sudo ln -s /etc/nginx/sites-available/zabbix /etc/nginx/sites-enabled/
sudo systemctl reload nginx

PHP Configuration

Edit /etc/php/8.1/fpm/pool.d/zabbix.conf:

[zabbix]
listen = /run/php/php8.1-fpm.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

; Zabbix-specific settings
php_value[memory_limit] = 256M
php_value[max_execution_time] = 300
php_value[post_max_size] = 32M
php_value[upload_max_filesize] = 32M
php_value[max_input_time] = 300
php_value[date.timezone] = UTC

Restart PHP-FPM:

sudo systemctl restart php8.1-fpm

First Login to Zabbix Frontend

  1. Open https://monitor.example.com in your browser
  2. Log in with default credentials:
    • Username: Admin
    • Password: zabbix
  3. Navigate to UsersAdmin and change the password immediately

Install Zabbix Agent on Monitored Hosts

On Ubuntu/Debian

wget https://repo.zabbix.com/zabbix/7.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_7.0-1+ubuntu22.04_all.deb
sudo dpkg -i zabbix-release_7.0-1+ubuntu22.04_all.deb
sudo apt update
sudo apt install zabbix-agent2

On RedHat/CentOS

sudo rpm -Uvh https://repo.zabbix.com/zabbix/7.0/rhel/9/x86_64/zabbix-release-7.0-1.el9.noarch.rpm
sudo yum install zabbix-agent2

Configure Zabbix Agent

Edit /etc/zabbix/zabbix_agent2.conf on monitored hosts:

# Server address (Zabbix server IP)
Server=192.168.1.100

# Passive mode - agent waits for server to poll
ServerActive=192.168.1.100:10051

# Agent hostname (must match in Zabbix web UI)
Hostname=webserver-01.example.com

# Listen settings
ListenIP=0.0.0.0
ListenPort=10050

# Logging
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=100

# Buffer settings
BufferSize=10

# User agent runs as
User=zabbix

Start and enable agent:

sudo systemctl start zabbix-agent2
sudo systemctl enable zabbix-agent2
sudo systemctl status zabbix-agent2

Verify connectivity from Zabbix server:

zabbix_get -s 192.168.1.50 -p 10050 -k system.uptime

Add Host in Zabbix Web UI

  1. Go to ConfigurationHosts
  2. Click Create host
  3. Configure:
    • Host name: webserver-01 (must match agent Hostname)
    • Visible name: WebServer 01
    • Agent interfaces: Add IP address and port (10050)
    • Groups: Select or create host group
  4. Go to Templates → Link Linux by Zabbix agent template
  5. Save host

Monitor metrics in real-time:

  • MonitoringHosts → Select host → Latest data

Create Custom Item, Trigger, and Action

Custom Item (Monitor Disk Usage)

  1. Go to ConfigurationHosts
  2. Select host → ItemsCreate item
  3. Configure:
    • Name: Disk space used /
    • Type: Zabbix agent
    • Key: vfs.fs.used[/]
    • Unit: B
  4. Save and check Latest data for results

Trigger (Alert on High Disk Usage)

  1. Select host → TriggersCreate trigger
  2. Configure:
    • Name: Disk /: Free space less than 10%
    • Expression: {webserver-01:vfs.fs.used[/].last()} > {webserver-01:vfs.fs.total[/].last()} * 0.9
    • Severity: Warning or High
  3. Save trigger

Action (Send Email Alert)

  1. Go to ConfigurationActionsCreate action
  2. Configure:
    • Name: Send email on high disk usage
    • Conditions: Add trigger name match
    • Operations: Add operation → Send message → Select media type (Email)
    • Default message body:
      Alert: {TRIGGER.NAME}
      Host: {HOST.NAME}
      Status: {TRIGGER.STATUS}
      Severity: {TRIGGER.SEVERITY}
  3. Save action

Auto-Discovery

Automatically discover hosts on your network:

  1. Go to ConfigurationDiscovery
  2. Click Create discovery rule
  3. Configure:
    • Name: LAN Discovery
    • IP range: 192.168.1.0-192.168.1.255
    • Check type: Zabbix agent or SNMP
    • Interval: 1h
  4. Save rule

Zabbix will automatically find hosts and create them (optionally).

Zabbix Agent2 vs Classic Agent

FeatureAgent2 (Go)Classic Agent (C)
PluginsYesNo
Better performanceYesStandard
Native Windows supportYesLimited
ModulesNoYes
Memory usageLowerHigher
DependenciesNonelibcurl, OpenSSL

Recommendation: Use Zabbix Agent2 for new installations.

Backup and Maintenance

Backup Zabbix database regularly:

mysqldump -u zabbix -p zabbix > zabbix_backup_$(date +%Y%m%d).sql

Clean up old data:

# In Zabbix UI: Administration → Maintenance → Database maintenance
# Or configure automatic housekeeping in zabbix_server.conf

Security Best Practices

  • Change default Admin password immediately after installation
  • Use firewall to restrict Zabbix server port (10051) to trusted agents only
  • Enable TLS encryption for agent-server communication
  • Keep Zabbix updated for security patches
  • Use strong passwords for database credentials
  • Back up encryption keys if using TLS certificates

Troubleshooting

Agent not connecting

Check firewall and network connectivity:

telnet 192.168.1.100 10050
netstat -tlnp | grep 10050

Check agent logs:

tail -f /var/log/zabbix/zabbix_agent2.log

High CPU usage in frontend

Optimize PHP-FPM settings and increase Zabbix cache sizes in zabbix_server.conf.

Database growing too large

Configure housekeeping to delete old data:

# In zabbix_server.conf
HousekeepingFrequency=1
MaxHousekeeperDelete=5000

Or manually from UI: AdministrationMaintenanceDatabase maintenance

On this page