Why Zabbix?
Zabbix is a powerful open-source monitoring solution capable of tracking servers, networks, applications, and cloud services. It provides real-time monitoring, alerting, and visualization for your entire infrastructure.
Prerequisites
Small/Lab
- • 1 vCPU
- • 2 GB RAM
- • 20 GB SSD
- • Up to 50 hosts
Medium
- • 2 vCPUs
- • 4 GB RAM
- • 50 GB SSD
- • 50-500 hosts
Large
- • 4+ vCPUs
- • 8+ GB RAM
- • 100+ GB SSD
- • 500+ hosts
Update Your System
Start by updating system packages and setting timezone:
# Update system packages
sudo apt update && sudo apt upgrade -y
# Set timezone for accurate monitoring timestamps
sudo timedatectl set-timezone America/New_YorkInstall Dependencies
Install Required Packages
Zabbix requires a web server, database, and PHP:
sudo apt install -y apache2 mysql-server php php-mysql php-gd php-xml \
php-bcmath php-mbstring php-ldap php-curl libapache2-mod-php wget gnupg2Add Zabbix Repository
Install Zabbix Repository
Download and install the official Zabbix repository:
# For Ubuntu 24.04
wget https://repo.zabbix.com/zabbix/7.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_latest_7.0+ubuntu24.04_all.deb
sudo dpkg -i zabbix-release_latest_7.0+ubuntu24.04_all.deb
sudo apt update# For Ubuntu 22.04
wget https://repo.zabbix.com/zabbix/7.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_latest_7.0+ubuntu22.04_all.deb
sudo dpkg -i zabbix-release_latest_7.0+ubuntu22.04_all.deb
sudo apt updateInstall Zabbix Components
Install Zabbix Server, Frontend, and Agent
Install the complete Zabbix stack:
sudo apt install -y zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf \
zabbix-sql-scripts zabbix-agent2Note: The zabbix-agent2 package is the newer Go-based agent with improved performance and plugin support.
Configure MySQL Database
Secure MySQL Installation
Run the security script:
sudo mysql_secure_installation
# Follow the prompts:
# - Set a root password
# - Answer Y to all security questionsCreate Zabbix Database
Create the database and user:
# Log into MySQL
sudo mysql -u root -pCREATE DATABASE zabbix CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'YourSecurePassword';
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost';
SET GLOBAL log_bin_trust_function_creators = 1;
FLUSH PRIVILEGES;
EXIT;Import Database Schema
Import the initial Zabbix schema (this may take a few minutes):
# Import schema and data
sudo zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix
# Enter the Zabbix database password when prompted
# After importing, disable log_bin_trust_function_creators
sudo mysql -u root -p -e "SET GLOBAL log_bin_trust_function_creators = 0;"Configuration
Configure Zabbix Server
Edit the server configuration:
sudo nano /etc/zabbix/zabbix_server.conf# Database password
DBPassword=YourSecurePassword
# Cache sizes (adjust based on your VPS RAM)
CacheSize=128M
HistoryCacheSize=64M
TrendCacheSize=32M
ValueCacheSize=64M
# Increase pollers for more hosts
StartPollers=10
StartPollersUnreachable=5
# Timeout settings
Timeout=30Configure PHP
Set timezone and optimize PHP:
sudo nano /etc/zabbix/apache.conf
# Uncomment and set your timezone:
php_value date.timezone America/New_Yorksudo nano /etc/php/8.3/apache2/php.ini
# Update these values:
memory_limit = 256M
upload_max_filesize = 16M
post_max_size = 16M
max_execution_time = 300
max_input_time = 300Configure Local Agent
Configure the local Zabbix agent:
sudo nano /etc/zabbix/zabbix_agent2.confServer=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix serverStart Services
Enable and start all services:
# Restart and enable services
sudo systemctl restart zabbix-server zabbix-agent2 apache2
sudo systemctl enable zabbix-server zabbix-agent2 apache2
# Verify services are running
sudo systemctl status zabbix-server
sudo systemctl status zabbix-agent2Configure Firewall
Open necessary ports:
sudo ufw allow 80/tcp # HTTP
sudo ufw allow 443/tcp # HTTPS
sudo ufw allow 10050/tcp # Zabbix Agent
sudo ufw allow 10051/tcp # Zabbix Server
sudo ufw reloadComplete Web Installation
Web Setup Wizard
Open your browser and navigate to:
http://your-server-ip/zabbix1. Welcome: Click "Next step"
2. Prerequisites: Ensure all requirements show "OK"
3. Database connection:
- • Database type: MySQL
- • Database host: localhost
- • Database port: 0 (default)
- • Database name: zabbix
- • User: zabbix
- • Password: YourSecurePassword
4. Settings: Configure server name and timezone
5. Summary: Review and click "Next step"
6. Install: Click "Finish"
Default Login
Log in with default credentials:
Username: Admin
Password: zabbixImportant: Change the default password immediately after logging in via Administration → Users → Admin.
SSL/TLS Setup
Enable SSL with Let's Encrypt
Secure your installation with a free SSL certificate:
# Install Certbot
sudo apt install -y certbot python3-certbot-apache
# Obtain and install certificate
sudo certbot --apache -d your-domain.com
# Follow the prompts to complete installation
# Enable automatic renewal
sudo systemctl enable certbot.timerSecurity Hardening
Restrict Web Access
Limit access to Zabbix frontend by IP:
sudo nano /etc/apache2/conf-available/zabbix.conf# Add within the <Directory> block:
<RequireAny>
Require ip 192.168.1.0/24
Require ip YOUR_OFFICE_IP
</RequireAny>Enable Two-Factor Authentication
Zabbix 7.0 supports TOTP-based 2FA:
Navigate to: Administration → Authentication → MFA settings
Enable TOTP and configure for administrator accounts.
Database Security
Create a read-only user for reporting:
CREATE USER 'zabbix_ro'@'localhost' IDENTIFIED BY 'ReadOnlyPassword';
GRANT SELECT ON zabbix.* TO 'zabbix_ro'@'localhost';
FLUSH PRIVILEGES;Performance Tuning
MySQL Optimization
Create optimized MySQL configuration:
sudo nano /etc/mysql/mysql.conf.d/zabbix.cnf[mysqld]
innodb_buffer_pool_size = 512M
innodb_log_file_size = 128M
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECTsudo systemctl restart mysqlHousekeeping Configuration
Configure data retention in Administration → General → Housekeeping:
• History retention: 7-30 days (depending on needs)
• Trend retention: 365 days
• Event retention: 365 days
Adding Remote Hosts
Install Agent on Remote Hosts
Install the Zabbix agent on remote VPS instances:
# On the remote host
wget https://repo.zabbix.com/zabbix/7.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_latest_7.0+ubuntu24.04_all.deb
sudo dpkg -i zabbix-release_latest_7.0+ubuntu24.04_all.deb
sudo apt update
sudo apt install -y zabbix-agent2Configure Remote Agent
Point the agent to your Zabbix server:
sudo nano /etc/zabbix/zabbix_agent2.confServer=ZABBIX_SERVER_IP
ServerActive=ZABBIX_SERVER_IP
Hostname=unique-hostname-for-this-host# Start and enable the agent
sudo systemctl enable zabbix-agent2
sudo systemctl start zabbix-agent2
# Open firewall
sudo ufw allow from ZABBIX_SERVER_IP to any port 10050Then add the host in the web interface: Data Collection → Hosts → Create Host
Useful Templates
Apply these built-in templates to your hosts:
Backup Strategy
Create Backup Script
Create an automated backup script:
#!/bin/bash
BACKUP_DIR="/backup/zabbix"
DATE=$(date +%Y%m%d)
mkdir -p $BACKUP_DIR
# Database backup
mysqldump -uzabbix -pYourSecurePassword zabbix | gzip > $BACKUP_DIR/zabbix_db_$DATE.sql.gz
# Configuration backup
tar -czf $BACKUP_DIR/zabbix_config_$DATE.tar.gz /etc/zabbix/
# Retain last 7 days
find $BACKUP_DIR -type f -mtime +7 -delete# Make executable
chmod +x /path/to/backup-zabbix.sh
# Add to cron for daily execution
sudo crontab -e
# Add this line:
0 2 * * * /path/to/backup-zabbix.shTroubleshooting
Check Logs
Review logs for issues:
# Check Zabbix server logs
sudo tail -f /var/log/zabbix/zabbix_server.log
# Check agent logs
sudo tail -f /var/log/zabbix/zabbix_agent2.logCommon Issues
Database connection errors
Verify credentials in /etc/zabbix/zabbix_server.conf match your MySQL user.
Agent not connecting
Check firewall rules and ensure agent hostname matches host configuration.
High CPU usage
Increase poller count or optimize item intervals in templates.
Web interface slow
Increase PHP memory limit and check MySQL performance.
Test Agent Connectivity
Test agent communication from the server:
# Test agent connectivity
zabbix_get -s 127.0.0.1 -k agent.ping
# A response of "1" indicates successful communication