Zabbix Monitoring Setup

Zabbix is a mature and enterprise-level open source monitoring solution for network monitoring and application monitoring. It is designed to monitor and track the status of various network services, servers, and other network hardware.

Prerequisites

  • Ubuntu Server 20.04 LTS or newer
  • Minimum 4GB RAM (8GB recommended for production)
  • 20GB+ of disk space
  • Root or sudo privileges
  • Static IP address configured
  • LAMP stack (Linux, Apache, MySQL/MariaDB, PHP)

1 System Preparation

Update your system and install required dependencies:

sudo apt update && sudo apt upgrade -y
sudo apt install -y software-properties-common curl wget vim

Set the hostname for your Zabbix server:

sudo hostnamectl set-hostname zabbix-server
exec bash

2 Install LAMP Stack

Install Apache web server, MySQL database, and PHP with required extensions:

sudo apt install -y apache2 mysql-server mysql-client \
php php-mysql php-ldap php-bcmath php-mbstring php-gd php-xml \
php-curl php-zip libapache2-mod-php

Verify that Apache is running:

sudo systemctl status apache2

Secure your MySQL installation:

sudo mysql_secure_installation
Note: Follow the prompts to set a root password and secure your database installation.

3 Install Zabbix Repository

Download and install the Zabbix repository:

wget https://repo.zabbix.com/zabbix/6.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.4-1+ubuntu20.04_all.deb
sudo dpkg -i zabbix-release_6.4-1+ubuntu20.04_all.deb
sudo apt update

For Ubuntu 22.04, use this repository instead:

wget https://repo.zabbix.com/zabbix/6.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.4-1+ubuntu22.04_all.deb
sudo dpkg -i zabbix-release_6.4-1+ubuntu22.04_all.deb
sudo apt update

4 Install Zabbix Server and Frontend

Install Zabbix server, frontend, and agent:

sudo apt install -y zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf \
zabbix-sql-scripts zabbix-agent

Verify the installations:

zabbix_server --version
zabbix_agentd --version

5 Create Zabbix Database

Log into MySQL and create a dedicated database for Zabbix:

sudo mysql -u root -p

Within the MySQL prompt, execute these commands (replace 'password' with a strong password):

CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Import the initial Zabbix database schema:

sudo zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql -u zabbix -p zabbix
Warning: You will be prompted for the zabbix user password. Use the password you set in the previous step.

6 Configure Zabbix Server

Edit the Zabbix server configuration file:

sudo nano /etc/zabbix/zabbix_server.conf

Update the database configuration with your credentials:

DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=your_strong_password

Also adjust these performance settings based on your environment:

StartPollers=20
StartPollersUnreachable=5
StartTrappers=15
StartPingers=15
StartDiscoverers=10
StartHTTPPollers=5
StartPreprocessors=10
StartAlerters=5
CacheSize=512M
HistoryCacheSize=256M
HistoryIndexCacheSize=128M
TrendCacheSize=256M
ValueCacheSize=512M

7 Configure PHP for Zabbix

Edit the PHP configuration file for Zabbix:

sudo nano /etc/zabbix/apache.conf

Make sure these settings are configured:

php_value max_execution_time 300
php_value memory_limit 256M
php_value post_max_size 32M
php_value upload_max_filesize 16M
php_value max_input_time 300
php_value max_input_vars 10000
php_value always_populate_raw_post_data -1
php_value date.timezone America/New_York  # Set to your timezone

Restart Apache to apply the changes:

sudo systemctl restart apache2

8 Start Zabbix Services

Start Zabbix server and agent services and enable them to start on boot:

sudo systemctl restart zabbix-server zabbix-agent apache2
sudo systemctl enable zabbix-server zabbix-agent

Check the status of Zabbix services:

sudo systemctl status zabbix-server
sudo systemctl status zabbix-agent

9 Configure Firewall

Allow necessary ports through the firewall:

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 enable

Verify the firewall status:

sudo ufw status

10 Complete Web Installation

Open your web browser and navigate to your Zabbix installation:

http://your_server_ip/zabbix

Follow the web-based installation wizard:

  1. Click "Next step" on the welcome screen
  2. Verify all pre-requisites are marked as "OK"
  3. Configure database connection:
    • Database type: MySQL
    • Database host: localhost
    • Database port: 0
    • Database name: zabbix
    • User: zabbix
    • Password: your_strong_password
  4. Set Zabbix server details (name is optional)
  5. Review the summary and click "Next step"
  6. Download the configuration file and save it to /etc/zabbix/web/zabbix.conf.php
  7. Click "Finish" to complete the installation
Note: The default login credentials are:
  • Username: Admin
  • Password: zabbix
You should change the password immediately after first login.

11 Configure Zabbix Agent

Edit the Zabbix agent configuration file:

sudo nano /etc/zabbix/zabbix_agentd.conf

Update the following settings:

Server=127.0.0.1,your_zabbix_server_ip
ServerActive=127.0.0.1,your_zabbix_server_ip
Hostname=Zabbix server
HostMetadata=linux

Restart the Zabbix agent:

sudo systemctl restart zabbix-agent

12 Add Linux Host for Monitoring

In the Zabbix web interface:

  1. Go to "Configuration" → "Hosts"
  2. Click "Create host"
  3. Fill in the host details:
    • Host name: Your server hostname
    • Visible name: Descriptive name
    • Groups: Select "Linux servers" or create a new group
    • Agent interfaces: Add IP address and port 10050
  4. Go to the "Templates" tab
  5. Click "Select" and add "Template OS Linux"
  6. Click "Add" to complete

Wait a few minutes for Zabbix to start collecting data from the host.

13 Configure Email Notifications

Install and configure Postfix for email notifications:

sudo apt install -y postfix mailutils

During installation, select "Internet Site" and enter your domain name.

Configure email media type in Zabbix:

  1. Go to "Administration" → "Media types"
  2. Click on "Email"
  3. Configure SMTP settings:
    • SMTP server: localhost
    • SMTP server port: 25
    • SMTP helo: your domain
  4. Click "Update"

Configure a user to receive email notifications:

  1. Go to "Administration" → "Users"
  2. Click on "Admin" (or create a new user)
  3. Go to the "Media" tab
  4. Click "Add" and configure email address
  5. Set appropriate severity levels
  6. Click "Add" then "Update"

14 Advanced Configuration

Set up Zabbix proxy for distributed monitoring (optional):

sudo apt install -y zabbix-proxy-mysql

Configure custom monitoring items:

  1. Go to "Configuration" → "Hosts"
  2. Select your host
  3. Go to "Items" and click "Create item"
  4. Configure key, type, and other parameters

Create custom dashboards:

  1. Go to "Monitoring" → "Dashboards"
  2. Click "Create dashboard"
  3. Add widgets and configure as needed

15 Troubleshooting Common Issues

Check Zabbix server log for errors:

sudo tail -f /var/log/zabbix/zabbix_server.log

Check Zabbix agent log:

sudo tail -f /var/log/zabbix/zabbix_agentd.log

Test agent communication:

zabbix_get -s 127.0.0.1 -k system.cpu.util[,idle]

Common issues and solutions:

Issue Solution
Zabbix server not starting Check database connection in zabbix_server.conf
Agent not communicating Verify Server setting in zabbix_agentd.conf
Web interface errors Check PHP and Apache error logs
No data collection Verify host interface and firewall settings
Command copied to clipboard!