Overview of Zabbix Monitoring
Zabbix is an open-source monitoring solution that collects data from servers, network devices, and applications. The server component gathers metrics via SNMP or agent-based polling and stores them in a database (MySQL, Oracle, PostgreSQL). A PHP frontend (Apache/Nginx) provides visualization and configuration.
Data collection methods:
- Agent: Installed on hosts to collect system-level metrics.
- SNMP: Used for network devices (switches, routers) and other SNMP-capable hardware.
Key Features
- Monitoring of hosts, network devices, databases, and applications
- Multiple alerting mechanisms (email, SMS, scripts)
- Real-time graphing and historical data
- Automatic discovery of network devices and servers
- Distributed monitoring with centralized management
- Extensible via custom scripts and API integrations
Installation
Configure YUM repositories:
cat /etc/yum.repos.d/zabbix.repo
[os]
name=aliyun
baseurl=https://mirrors.aliyun.com/centos/6/os/x86_64/
enabled=1
gpgcheck=0
[zabbix]
name=zabbix
baseurl=http://mirrors.ustc.edu.cn/epel/6/x86_64/
enabled=1
gpgcheck=0
Server-side Installation
# Install packages
yum -y install zabbix22-server zabbix22-web zabbix22-web-mysql zabbix22-dbfiles-mysql zabbix22-agent mysql-server mysql php php-devel php-mysql
# Start MySQL and create database
service mysqld start
mysql
CREATE DATABASE zabbix CHARACTER SET utf8;
GRANT ALL ON zabbix.* TO 'zabbix'@'192.168.4.%' IDENTIFIED BY 'zabbix';
FLUSH PRIVILEGES;
# Import schema and data
mysql -u root -p zabbix < schema.sql
mysql -u root -p zabbix < images.sql
mysql -u root -p zabbix < data.sql
# Verify tables
mysql -e 'USE zabbix; SHOW TABLES;'
Edit server configuration /etc/zabbix_server.conf:
LogFile=/var/log/zabbixsrv/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbixsrv/zabbix_server.pid
DBHost=192.168.4.19
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/lib/mysql/mysql.sock
AlertScriptsPath=/var/lib/zabbixsrv/alertscripts
ExternalScripts=/var/lib/zabbixsrv/externalscripts
TmpDir=/var/lib/zabbixsrv/tmp
Agent-side Installation
yum -y install zabbix22-agent
Edit /etc/zabbix_agentd.conf:
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.4.19
ServerActive=127.0.0.1
Hostname=Zabbix server
Web Frontend Configuration
Access http://192.168.4.19/zabbix and follow the installation wizard. After setup, adjust PHP settings:
vim /etc/php.ini
date.timezone = Asia/Shanghai
max_execution_time = 300
post_max_size = 32M
max_input_time = 300
memory_limit = 128M
Restart Apache: service httpd restart
Default admin credentials: admin / zabbix
Configuration file generated: /etc/zabbix/web/zabbix.conf.php
Fix Chinese Character Rendering (if using Chinese language)
Copy a Chinese font (e.g., SimSun or Microsoft YaHei) to the font directory:
cp /path/to/your/font.ttf /usr/share/fonts/dejavu/DejaVuSans.ttf
Adding a Host
- Navigate to Configuration → Hosts → Create host
- Set Host name:
test2, Visible name:test2 - Add to group:
demo - Interface: IP
192.168.4.19, Port10050 - Status:
Monitored
Configuring Alerting
Alerts are delivered via users and user groups. For production, combine email with SMS or other channels.
Create a User
Go to Administration → Users → Create user
- Alias:
demo, Name:demo, Groups:Zabbix administrators, Password:demo, Auto-login enabled - Media tab: Add email
user@domain.comwith TypeEmail - Permissions tab: User type
Zabbix Super Admin
Logout and login as demo to test.
Monitoring MySQL
Create an Item
Configuration → Hosts (test2) → Items → Create item
- Name:
mysql_check - Key:
mysql_alive - Update interval:
60 - Flexible interval:
300 - New application:
MySQL - Description:
MySQL Check
On the agent host, define the user parameter:
vim /etc/zabbix/zabbix_agentd.conf
UserParameter=mysql_alive,mysqladmin ping | grep -c alive
service zabbix-agentd restart
Create a Trigger
Configuration → Hosts (test2) → Triggers → Create trigger
- Name:
MySQL down - Expression: Select item
mysql_check, functionLast (most recent) T value is NOT N,N=1 - Severity: Disaster
- Dependencies: Add
Zabbix agent on {HOST.NAME} is unreachable for 5 minutes
Create a Graph
Configuration → Hosts (test2) → Graphs → Create graph
- Name:
mysql status - Graph type: Normal
- Items: Add
mysql_check - Preview and save
Enable Action
Configuration → Actions: Enable Report problems to Zabbix administrators.
- Action tab: Keep message short (e.g., 70 chars for SMS)
- Conditions: Set defaults
- Operations: Add operation (e.g., from 1 to 3 notifications) and select
Send message
Setting Up Email Alerts
Configure mail client
vim /etc/mail.rc
set from=your_email@163.com smtp=smtp.163.com
set smtp-auth-user=your_user smtp-auth-password=your_password smtp-auth=login
Create Alert Script
Scripts must accept three parameters: recipient, subject, body.
vim /var/lib/zabbixsrv/alertscripts/mail.sh
#!/bin/sh
MAIL_TITLE=$2
MAIL_CON=$3
echo "$MAIL_CON" | /bin/mail -s "$MAIL_TITLE" $1
echo "$1 $2 $3" >> /tmp/alert
chmod 755 mail.sh
Configure Media Type
Administration → Media types → Create media type
- Name:
send_mail - Type: Script
- Script name:
mail.sh - Enabled: checked
Assign Media to Users
Edit user demo and admin → Media tab → Add send_mail with email address.
Link Action to Script
Configuration → Actions → Report problems to Zabbix administrators → Operations → Edit → Operation details:
- User group:
Zabbix administrators - Send only to:
send_mail
Enable Frontend Messaging (for sound alerts)
User profile → Messaging → Check Frontend messaging
Testing
- Stop MySQL on the monitored host:
service mysqld stop - Observe alerts in Monitoring → Dashboard (System status, Host status, Last 20 issues)
- Check logs:
/var/log/zabbixsrv/zabbix_server.logandtail -f /var/log/maillog