Introduction to Zabbix
Zabbix is a powerful, enterprise-grade open-source solution designed for distributed system and network monitoring. It provides a web-based interface for comprehensive oversight of network parameters, ensuring the secure operation of server systems. Zabbix offers flexible notification mechanisms, enabling administrators to quickly identify and resolve issues.
The Zabbix architecture consists of several key components:
- Monitoring Server: The central component that receives availability and perforamnce data from agents. It stores all configuration, statistics, and operational data.
- Data Storage: All collected configuration and data are stored in a database.
- Web Interface: A web-based interfaec for easy access from any location or platform. This interface is typically part of the monitoring server.
- Proxy: An optional component that can collect performance and availability data on behalf of the server, useful for distributed environments.
- Agent: Deployed on monitored hosts to actively collect local resource and application data, reporting it to the server. Zabbix offers two agent types: the lightweight C-based agent and the flexible, plugin-extensible Go-based agent 2.
Zabbix features include automatic discovery of servers and network devices, distributed monitoring with centralized web management, agentless monitoring capabilities, user authentication, and a web interface for configuration and result viewing. It supports both active polling and passive trapping, making it suitable for organizations of all sizes.
Installation Guide
Environment Planning
| Component | IP Address | Monitored Item | Operating System |
|---|---|---|---|
| Monitoring Server | 10.0.0.5 | Server Resources | CentOS 7.9 |
| Monitoring Agent | 10.0.0.10 | MySQL 8.0 | CentOS 7.9 |
| Monitoring Agent | 10.0.0.11 | MySQL 8.0 | CentOS 7.9 |
Installing the Monitoring Server
This section details the installation on the server at 10.0.0.5.
1. Downloading the Source
Download the LTS (Long-Term Support) version from the official Zabbix website. Refer to the installation manual for detailed instructions.
2. Extracting the Archive
[root@monitoring-server ~]# cd /usr/src/
[root@monitoring-server src]# tar xf /tmp/zabbix-6.0.25.tar.gz
[root@monitoring-server src]# ln -s zabbix-6.0.25 monitoring_tool
[root@monitoring-server src]# ls
debug kernels monitoring_tool zabbix-6.0.25
3. Creating System User and Group
[root@monitoring-server src]# groupadd --system monitoring
[root@monitoring-server src]# useradd --system -g monitoring -d /usr/lib/monitoring -s /sbin/nologin -c "Monitoring System" monitoring
4. Setting Up the Database
Using MySQL 8.0 as the database backend. Create a database and user with appropriate privileges.
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.25 |
+-----------+
mysql>
create database monitoring character set utf8mb4 collate utf8mb4_bin;
create user 'monitoring'@'%' identified with mysql_native_password by 'SecurePass123.';
grant all privileges on monitoring.* to 'monitoring'@'localhost';
SET GLOBAL log_bin_trust_function_creators = 1;
5. Initializing the Database
Import the necessary SQL scripts located in the database directory.
[root@monitoring-server ~]$ cd /usr/src/monitoring_tool/database/mysql
[root@monitoring-server mysql]$ ls
data.sql double.sql history_pk_prepare.sql images.sql Makefile.am Makefile.in schema.sql
# Import database schema
[root@monitoring-server mysql]$ mysql -umonitoring -pSecurePass123. monitoring < schema.sql
[root@monitoring-server mysql]$ mysql -umonitoring -pSecurePass123. monitoring < images.sql
[root@monitoring-server mysql]$ mysql -umonitoring -pSecurePass123. monitoring < data.sql
6. Compiling and Installing the Server
Install required dependencies and compile the source.
[root@monitoring-server monitoring_tool]# yum install -y gcc mysql-devel libevent-devel libcurl-devel libxml2-devel net-snmp-devel
[root@monitoring-server monitoring_tool]# ./configure --prefix=/usr/local/monitoring_tool --enable-server --enable-agent --with-mysql=/usr/bin/mysql_config --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
[root@monitoring-server monitoring_tool]# make install
7. Configuring the Server and Agent
Edit the server configuration file to specify database connection details.
# /usr/local/monitoring_tool/etc/monitoring_tool_server.conf
LogFile=/tmp/monitoring_tool_server.log
DBHost=127.0.0.1
DBName=monitoring
DBUser=monitoring
DBPassword=SecurePass123.
DBPort=3306
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
Edit the agent configuration file.
# /usr/local/monitoring_tool/etc/monitoring_tool_agentd.conf
LogFile=/tmp/monitoring_tool_agentd.log
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Monitoring server
8. Service Management Scripts
Configure startup scripts for the server and agent.
# For monitoring_tool_server
[root@monitoring-server etc]# vim /usr/src/monitoring_tool/misc/init.d/fedora/core5/monitoring_tool_server
# Modify the following lines
MONITORING_BIN="/usr/local/monitoring_tool/sbin/monitoring_tool_server"
CONFIG_FILE="/usr/local/monitoring_tool/etc/monitoring_tool_server.conf"
daemon $MONITORING_BIN -c $CONFIG_FILE
# Copy to init.d directory
[root@monitoring-server etc]# cp /usr/src/monitoring_tool/misc/init.d/fedora/core5/monitoring_tool_server /etc/init.d/
# For monitoring_tool_agentd
[root@monitoring-server etc]# vim /usr/src/monitoring_tool/misc/init.d/fedora/core5/monitoring_tool_agentd
# Modify the following lines
MONITORING_BIN="/usr/local/monitoring_tool/sbin/monitoring_tool_agentd"
CONFIG_FILE="/usr/local/monitoring_tool/etc/monitoring_tool_agentd.conf"
daemon $MONITORING_BIN -c $CONFIG_FILE
# Copy to init.d directory
[root@monitoring-server etc]# cp /usr/src/monitoring_tool/misc/init.d/fedora/core5/monitoring_tool_agentd /etc/init.d/
9. Starting the Services
[root@monitoring-server ~]# service monitoring_tool_server start
[root@monitoring-server ~]# service monitoring_tool_agentd start
# Enable on boot
[root@monitoring-server ~]# chkconfig monitoring_tool_server on
[root@monitoring-server ~]# chkconfig monitoring_tool_agentd on
Installing the Web Interface
1. Installing Apache and PHP
Install Apache and a compatible PHP version (7.2.5 or higher).
[root@monitoring-server ~]# wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home%3A/matthewdva%3A/build%3A/EPEL%3A/el7/RHEL_7/noarch/epel-release-7-9.noarch.rpm
[root@monitoring-server ~]# wget ftp://ftp.pbone.net/mirror/repo.webtatic.com/yum/el7/webtatic-release.rpm
[root@monitoring-server ~]# rpm -ivh epel-release-7-9.noarch.rpm
[root@monitoring-server ~]# rpm -ivh webtatic-release.rpm
[root@monitoring-server ~]# php -v
PHP 7.2.34 (cli) (built: Oct 1 2020 13:37:37) ( NTS )
2. Copying Web Files
[root@monitoring-server ~]# mkdir -p /var/www/html/monitoring_ui
[root@monitoring-server ~]# cp -r /usr/src/monitoring_tool/ui/* /var/www/html/monitoring_ui/
[root@monitoring-server ~]# chown -R apache.apache /var/www/html/
3. Configuring PHP
Adjust PHP settings for optimal performance.
[root@monitoring-server ~]# vim /etc/php.ini
# Modify the following settings
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
date.timezone = Asia/Shanghai
4. Starting Apache
[root@monitoring-server ~]# systemctl start httpd
[root@monitoring-server ~]# systemctl enable httpd
Configuring the Web Interface
1. Accessing the Web Interface
Navigate to http://10.0.0.5/monitoring_ui in your browser and follow the setup wizard.
2. Database Connection
Configure the database connection details during the setup process.
3. Finalizing Setup
Complete the configuration by following the on-screen instructions and log in using the default credentials (Admin/zabbix).
Installing the Monitoring Agent
Deploy the agent on the target machines (e.g., 10.0.0.10).
1. Creating System User and Group
[root@target-host ~]# groupadd --system monitoring
[root@target-host ~]# useradd --system -g monitoring -d /usr/lib/monitoring -s /sbin/nologin -c "Monitoring System" monitoring
2. Extracting the Archive
[root@target-host ~]# cd /usr/src
[root@target-host src]# tar -xf /tmp/zabbix-6.0.25.tar.gz
[root@target-host src]# ln -s zabbix-6.0.25 monitoring_tool
3. Compiling and Installing the Agent
[root@target-host src]# yum install gcc pcre-devel -y
[root@target-host src]# cd monitoring_tool
[root@target-host monitoring_tool]# ./configure --prefix=/usr/local/monitoring_tool --enable-agent
[root@target-host monitoring_tool]# make install
4. Configuring the Agent
# /usr/local/monitoring_tool/etc/monitoring_tool_agentd.conf
LogFile=/tmp/monitoring_tool_agentd.log
Server=10.0.0.5
ServerActive=127.0.0.1
Hostname=target-host
5. Service Management Script
[root@target-host src]# cd monitoring_tool/misc/init.d/fedora/core5/
[root@target-host core5]# vim monitoring_tool_agentd
# Modify the following lines
MONITORING_BIN="/usr/local/monitoring_tool/sbin/monitoring_tool_agentd"
CONFIG_FILE="/usr/local/monitoring_tool/etc/monitoring_tool_agentd.conf"
daemon $MONITORING_BIN -c $CONFIG_FILE
# Copy to init.d directory
[root@target-host core5]# cp monitoring_tool_agentd /etc/init.d/
# Enable on boot
[root@target-host core5]# chkconfig monitoring_tool_agentd on
6. Starting the Agent
[root@target-host core5]# service monitoring_tool_agentd start
Repeat the agent installation process for additional target hosts.