How to Compile and Install Zabbix Server on CentOS 7

zabbix servercentos 7compile zabbixzabbix installationsystem monitoring
Published·Modified·

Zabbix is an enterprise-grade open-source solution for distributed system and network monitoring with a web interface. It is ideal for managing multiple servers. Zabbix consists of two parts: Zabbix Server and the optional Zabbix Agent.

Zabbix Server requires PHP and MySQL support (SQLite, PostgreSQL, etc. are also supported). Since the server already has the OneinStack environment (Linux + Nginx + MySQL + PHP) installed, we choose to install Zabbix Server via source code compilation to avoid affecting the current environment.

1. Compile Zabbix Server & Agent

# Install dependencies
yum -y install gcc gcc-c++ curl-devel mysql-devel curl-devel net-snmp net-snmp-devel

# Create user and group
groupadd zabbix
useradd -g zabbix zabbix

# Download source code (latest version from official site)
wget http://soft.xiaoz.org/linux/zabbix-3.4.4.tar.gz

# Extract and enter directory
tar -zxvf zabbix-3.4.4.tar.gz && cd zabbix-3.4.4

# Compile and install
./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
make install

Notes:

At the time of writing, the latest stable version of Zabbix is 3.4. You can find the latest source package on the official website: https://www.zabbix.com/download.

If you encounter the error "checking for mysql_config... configure: error: MySQL library not found" during compilation, specify the mysql_config path manually:

# Find mysql_config location
find / -name 'mysql_config'

# Specify the path
--with-mysql=/usr/local/mysql/bin/mysql_config

If errors persist, search for solutions based on the specific error message. After compiling and installing Zabbix Server on CentOS 7, the configuration files are located at:

/usr/local/etc/zabbix_server.conf
/usr/local/etc/zabbix_agentd.conf

2. Import Database

Create a database manually (steps omitted) and import the three database files located in zabbix-3.4.4/database/mysql in the following order:

├─ zabbix-3.4.4/database/mysql
 ├─ schema.sql
 ├─ images.sql
 └─ data.sql

Modify the configuration file /usr/local/etc/zabbix_server.conf to fill in the correct database username, password, and other information. Then start Zabbix Server and Zabbix Agent:

zabbix_server && zabbix_agentd

3. Install Web Interface

The web interface is developed using PHP. You need to create a new site and copy all source code from zabbix-3.4.4/frontends/php to your site directory. Visit your domain (e.g., http://domain.com/) and enter the basic Zabbix Server information to complete the installation. After successful installation, you will see the following interface. The default username is Admin and the password is zabbix. Please change them after logging in.\n Zabbix Login Interface

Set Language to Chinese

Zabbix defaults to English. You can set the language to Chinese in the user profile for easier management.

Language Settings

Fix Chinese Garbled Text?

Drag a Chinese font file (e.g., simkai.ttf) from C:\Windows\Fonts on your computer and upload it to the fonts directory of your site to replace the default font.

# Backup the original font
mv DejaVuSans.ttf DejaVuSans.ttf.bak
# Rename the new font
mv simkai.ttf DejaVuSans.ttf

Garbled Text Example

4. Enable Automatic Startup on Boot

Register Zabbix as a service, assign permissions, and set it to start automatically on boot:

cd zabbix-3.4.4
cp misc/init.d/tru64/zabbix_server  /etc/init.d/zabbix_server
cp misc/init.d/tru64/zabbix_agentd  /etc/init.d/zabbix_agentd

# Assign permissions
chmod 755 /etc/init.d/zabbix_*

Edit the zabbix_server and zabbix_agentd files and add the following lines at the top:

#chkconfig: 35 95 95
#description:zabbix Agent server

Register the services and enable automatic startup:

chkconfig --add zabbix_server
chkconfig --add zabbix_agentd
chkconfig zabbix_server on
chkconfig zabbix_agentd on

The installation is now complete. If you need to monitor other servers, you can install the client using the official RPM package. The client does not require PHP or database support. The official RPM package method is recommended for the client as it is more convenient.

5. Further Reading

6. Summary

Most hosting providers include server monitoring features by default. However, if you manage multiple servers from different providers, management becomes inconvenient, and you may not be notified of issues in time. Zabbix solves this problem perfectly. It provides detailed data, supports various actions and notifications, and offers an open API for customization and enhancement. Zabbix is incredibly powerful; I have only scratched the surface.

Monitoring Data Example

References:

Official Resources: