Install and configure Zabbix 7 with PostgreSQL and advanced monitoring templates

Intermediate 45 min Apr 01, 2026 2,417 views
Ubuntu 24.04 Ubuntu 22.04 Debian 12 AlmaLinux 9 Rocky Linux 9 Fedora 41

Set up Zabbix 7 monitoring server with PostgreSQL backend, SSL-enabled web interface, auto-discovery, and advanced monitoring templates for comprehensive infrastructure monitoring.

Prerequisites

  • Root or sudo access
  • Minimum 2GB RAM
  • 10GB free disk space
  • Network access for package installation

What this solves

Zabbix 7 provides enterprise-grade network and infrastructure monitoring with auto-discovery, customizable dashboards, and advanced alerting. This tutorial shows you how to install Zabbix server with PostgreSQL database backend, configure SSL-enabled web interface, set up monitoring agents with auto-discovery, and implement advanced monitoring templates for comprehensive infrastructure visibility.

Step-by-step installation

Update system packages

Start by updating your package manager to ensure you get the latest versions and security patches.

sudo apt update && sudo apt upgrade -y
sudo apt install -y wget curl gnupg2 software-properties-common
sudo dnf update -y
sudo dnf install -y wget curl gnupg2 epel-release

Install PostgreSQL database

Zabbix 7 requires PostgreSQL 13 or newer for optimal performance. We'll install PostgreSQL and create the Zabbix database.

sudo apt install -y postgresql postgresql-contrib
sudo systemctl enable --now postgresql
sudo dnf install -y postgresql-server postgresql-contrib
sudo postgresql-setup --initdb
sudo systemctl enable --now postgresql

Configure PostgreSQL for Zabbix

Create a dedicated database and user for Zabbix with proper permissions and security settings.

sudo -u postgres createuser --pwprompt zabbix
sudo -u postgres createdb -O zabbix zabbix_db
Note: When prompted, set a strong password for the zabbix database user. You'll need this password during Zabbix configuration.

Add Zabbix 7 repository

Add the official Zabbix repository to get the latest version 7.x packages with all features and security updates.

wget https://repo.zabbix.com/zabbix/7.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_7.0-2+ubuntu24.04_all.deb
sudo dpkg -i zabbix-release_7.0-2+ubuntu24.04_all.deb
sudo apt update
sudo rpm -Uvh https://repo.zabbix.com/zabbix/7.0/alma/9/x86_64/zabbix-release-7.0-2.el9.noarch.rpm
sudo dnf clean all

Install Zabbix server and web frontend

Install Zabbix server with PostgreSQL support, web frontend, and required PHP extensions.

sudo apt install -y zabbix-server-pgsql zabbix-frontend-php php8.3-pgsql zabbix-apache-conf zabbix-sql-scripts
sudo dnf install -y zabbix-server-pgsql zabbix-web-pgsql zabbix-apache-conf zabbix-sql-scripts

Import Zabbix database schema

Import the initial database schema and data required for Zabbix server operation.

sudo -u zabbix psql -h localhost -d zabbix_db -f /usr/share/zabbix-sql-scripts/postgresql/server.sql.gz
Note: This process may take several minutes to complete as it creates all necessary tables and imports default monitoring templates.

Configure Zabbix server

Configure the Zabbix server to connect to PostgreSQL database with proper security settings.

LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=10
PidFile=/run/zabbix/zabbix_server.pid
SocketDir=/run/zabbix
DBName=zabbix_db
DBUser=zabbix
DBPassword=your_zabbix_db_password
DBHost=localhost
DBPort=5432
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
FpingLocation=/usr/bin/fping
Fping6Location=/usr/bin/fping6
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1

Install and configure Apache web server

Set up Apache with SSL support for secure access to Zabbix web interface.

sudo apt install -y apache2 openssl
sudo a2enmod ssl rewrite
sudo systemctl enable --now apache2
sudo dnf install -y httpd mod_ssl openssl
sudo systemctl enable --now httpd

Generate SSL certificate

Create a self-signed SSL certificate for secure HTTPS access to the Zabbix web interface.

sudo mkdir -p /etc/ssl/private /etc/ssl/certs
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
  -keyout /etc/ssl/private/zabbix.key \
  -out /etc/ssl/certs/zabbix.crt \
  -subj "/C=US/ST=State/L=City/O=Organization/CN=example.com"
sudo chmod 600 /etc/ssl/private/zabbix.key
sudo chmod 644 /etc/ssl/certs/zabbix.crt

Configure Apache virtual host

Set up Apache virtual host with SSL redirection and security headers for Zabbix web interface.



Enable SSL site and restart Apache

Enable the SSL virtual host and restart Apache to apply the new configuration.

sudo a2ensite zabbix-ssl
sudo a2dissite 000-default
sudo systemctl restart apache2
sudo cp /etc/apache2/sites-available/zabbix-ssl.conf /etc/httpd/conf.d/
sudo systemctl restart httpd

Start Zabbix server

Enable and start the Zabbix server service to begin monitoring operations.

sudo systemctl enable --now zabbix-server
sudo systemctl status zabbix-server

Install and configure Zabbix agent

Install Zabbix agent on the server to enable self-monitoring and serve as a template for other hosts.

sudo apt install -y zabbix-agent2
sudo dnf install -y zabbix-agent2

Configure Zabbix agent

Configure the Zabbix agent to communicate securely with the Zabbix server and enable additional monitoring plugins.

PidFile=/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=10
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=zabbix-server
RefreshActiveChecks=120
BufferSend=5
BufferSize=100
MaxLinesPerSecond=20
AllowRoot=0
User=zabbix
Include=/etc/zabbix/zabbix_agent2.d/*.conf
Plugins.SystemRun.LogRemoteCommands=1
ControlSocket=/tmp/agent.sock

Start Zabbix agent

Enable and start the Zabbix agent service to begin collecting system metrics.

sudo systemctl enable --now zabbix-agent2
sudo systemctl status zabbix-agent2

Configure firewall

Open necessary ports for Zabbix server, web interface, and agent communication.

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 10050/tcp
sudo ufw allow 10051/tcp
sudo ufw reload
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --permanent --add-port=443/tcp
sudo firewall-cmd --permanent --add-port=10050/tcp
sudo firewall-cmd --permanent --add-port=10051/tcp
sudo firewall-cmd --reload

Complete web interface setup

Access the Zabbix web interface to complete the installation wizard and configure monitoring templates.

curl -k https://localhost/zabbix/
Note: Open https://your-server-ip/zabbix in your browser and follow the setup wizard. Use database name 'zabbix_db', user 'zabbix', and the password you set earlier.

Configure email notifications

Set up email alerts by configuring a media type for SMTP notifications in the Zabbix web interface.

Note: Navigate to Administration → Media types → Create media type. Configure SMTP server settings, authentication, and test the email delivery before enabling alerts.

Enable auto-discovery

Configure network auto-discovery to automatically detect and monitor new devices on your network.

Note: Go to Configuration → Discovery → Create discovery rule. Set IP ranges, check types (ICMP ping, SNMP, Zabbix agent), and define actions for discovered hosts.

Import advanced monitoring templates

Import additional monitoring templates for comprehensive infrastructure monitoring including databases, web servers, and network devices.

Note: Navigate to Configuration → Templates → Import. Upload template files from /usr/share/zabbix/templates/ or download additional templates from Zabbix template gallery.

Configure maintenance windows

Set up scheduled maintenance windows to prevent false alerts during planned maintenance activities.

Note: Go to Configuration → Maintenance → Create maintenance period. Define time periods, affected hosts, and maintenance type (with or without data collection).

Optimize PostgreSQL for Zabbix

Tune PostgreSQL settings for optimal Zabbix performance with larger deployments.

shared_buffers = 256MB
effective_cache_size = 1GB
work_mem = 4MB
maintenance_work_mem = 64MB
max_connections = 200
checkpoint_completion_target = 0.9
wal_buffers = 16MB
default_statistics_target = 100
sudo systemctl restart postgresql

Set up automated backups

Create automated backup script for Zabbix configuration and database to ensure data protection.

#!/bin/bash
BACKUP_DIR="/backup/zabbix"
DATE=$(date +%Y%m%d_%H%M%S)

mkdir -p $BACKUP_DIR

# Backup Zabbix database
pg_dump -U zabbix -h localhost zabbix_db | gzip > $BACKUP_DIR/zabbix_db_$DATE.sql.gz

# Backup configuration files
tar -czf $BACKUP_DIR/zabbix_config_$DATE.tar.gz /etc/zabbix/ /usr/share/zabbix/conf/

# Keep only 7 days of backups
find $BACKUP_DIR -type f -mtime +7 -delete

echo "Backup completed: $DATE" >> $BACKUP_DIR/backup.log
sudo chmod 755 /opt/zabbix-backup.sh
(crontab -l 2>/dev/null; echo "0 2 * * * /opt/zabbix-backup.sh") | crontab -

Verify your setup

Check that all Zabbix components are running correctly and the web interface is accessible.

sudo systemctl status zabbix-server
sudo systemctl status zabbix-agent2
sudo systemctl status apache2
sudo systemctl status postgresql
ss -tlnp | grep -E ':(80|443|10050|10051)\s'
curl -k -I https://localhost/zabbix/
sudo tail -f /var/log/zabbix/zabbix_server.log

Access the web interface and verify monitoring data collection:

# Check database connectivity
sudo -u zabbix psql -h localhost -d zabbix_db -c "SELECT COUNT(*) FROM hosts;"

# Verify agent connectivity
zabbix_get -s 127.0.0.1 -k system.uptime

Common issues

SymptomCauseFix
Zabbix server won't startDatabase connection failureCheck PostgreSQL service and credentials in /etc/zabbix/zabbix_server.conf
Web interface shows database errorPHP configuration or permissionsVerify PHP PostgreSQL extension: php -m | grep pgsql
Agent data not appearingFirewall blocking portsOpen ports 10050/10051: sudo ufw allow 10050:10051/tcp
SSL certificate warningsSelf-signed certificateImport certificate or use Let's Encrypt: sudo certbot --apache
Auto-discovery not workingNetwork permissions or SNMPCheck network connectivity and SNMP community strings
Email alerts not sendingSMTP configurationTest media type configuration and check mail server logs
High database loadInsufficient PostgreSQL tuningIncrease shared_buffers and optimize queries in maintenance

Next steps

Automated install script

Run this to automate the entire setup

不想自己管理这些吗?

我们为依赖稳定运行时间的企业管理基础设施。全托管服务,配备一位熟悉您系统架构的固定联系人。

您将拥有一位了解您整体架构的固定联系人

在鹿特丹的办公桌前 10:30 · 一条消息即可联系我们,无需填写工单表单