Building Zabbix 5.0.36 from Source on CentOS 7.9
This guide demonstrates a complete source-based installation of Zabbix 5.0.36 on CentOS Linux releace 7.9 (16 CPUs, 32 GB RAM). It also covers installing Nginx 1.6.2, MySQL 8.0.28 (minimal), and PHP 7.3. The required packages are:
- zabbix-5.0.36.tar.gz
- mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz
- nginx-1.6.2.tar.gz
1. Pre-installation Configuration
# Disable firewall and NetworkManager
systemctl stop firewalld && systemctl disable firewalld
systemctl stop NetworkManager && systemctl disable NetworkManager
# Disable SELinux permanently (requires reboot)
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
reboot
# Create MySQL service account
useradd -r -g mysql -s /bin/false mysql
# Create Zabbix user and group
groupadd zabbix
useradd -g zabbix zabbix -s /sbin/nologin
# Remove any existing MariaDB packages
yum remove -y mariadb*
# Create MySQL data directories
mkdir -p /data/mysql-cluster/mysql3306/{data,binlogs,logs,tmp}
mkdir /packages
# Configure YUM repositories (Alibaba Cloud mirrors)
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all && yum makecache
# Install essential tools
yum install -y net-tools
2. Nginx Installation
# Install Nginx dependencies
yum install -y mysql-devel libcurl libevent libevent-devel fping curl-devel libxml2 libxml2-devel gcc net-snmp-devel pcre-devel zlib-devel openssl-devel
# Download Nginx source
cd /packages
wget http://nginx.org/download/nginx-1.6.2.tar.gz
# Extract and compile
tar zxvf nginx-1.6.2.tar.gz -C /data/
cd /data/nginx-1.6.2
./configure --with-http_ssl_module
make && make install
# Set permissions and start
chmod -R 755 /usr/local/nginx/*
/usr/local/nginx/sbin/nginx
# Edit nginx.conf to enable PHP processing
vim /usr/local/nginx/conf/nginx.conf
# Uncomment the PHP location block around line 65:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
# Validate and reload
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
netstat -nulpt | grep nginx
# Test (replace IP with your own): http://192.168.169.100:80
3. MySQL 8.0.28 Installation
Create the my.cnf file as shown at the end of this section.
yum install libaio -y
# Download MySQL minimal tarball
cd /packages
wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz
tar xvf mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz
mv mysql-8.0.28-linux-glibc2.17-x86_64-minimal /usr/local/mysql
# Set PATH
echo 'export PATH=$PATH:/usr/local/mysql/bin:/usr/local/nginx/sbin' | tee -a /etc/profile
source /etc/profile
# Place my.cnf
vim /etc/my.cnf
# See sample configuration below
# Set ownership
chown mysql:mysql -R /data/mysql-cluster/mysql3306
# Initialize MySQL
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
# On error: rm -rf /data/mysql-cluster/mysql3306/data/* and retry
# Check error log (path from my.cnf)
cat /data/mysql-cluster/mysql3306/logs/error.log | grep -i error
# Install systemd service file and start
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/
/etc/init.d/mysql.server start
# Fix missing paths if needed:
mkdir /var/log/mariadb && touch /var/log/mariadb/mariadb.log && chown -R mysql:mysql /var/log/mariadb
# Retrieve temporary root password
ps -ef | grep mysql
cat /data/mysql-cluster/mysql3306/logs/error.log | grep root
# Example: A temporary password is generated for root@localhost: JLYwq)wga5kR
# Login and set up database
mysql -uroot -p
-- Change root password
ALTER USER root@localhost IDENTIFIED BY '123456';
-- Create Zabbix database and user
CREATE USER zabbix@localhost IDENTIFIED WITH mysql_native_password BY 'qaz123456';
CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost;
SET GLOBAL log_bin_trust_function_creators = 1;
FLUSH PRIVILEGES;
EXIT;
# Create alias for convenience
echo "alias dba3306='mysql -uroot -p123456'" >> /root/.bashrc
source /root/.bashrc
dba3306
Sample my.cnf:
[client]
port = 3306
socket = /data/mysql-cluster/mysql3306/tmp/mysqld3306.sock
[mysqld]
user = mysql
port = 3306
socket = /data/mysql-cluster/mysql3306/tmp/mysqld3306.sock
pid-file = /data/mysql-cluster/mysql3306/tmp/my3306.pid
basedir = /usr/local/mysql
datadir = /data/mysql-cluster/mysql3306/data
slow_query_log_file = /data/mysql-cluster/mysql3306/logs/3306slow.log
log_error = /data/mysql-cluster/mysql3306/logs/error.log
log_bin = /data/mysql-cluster/mysql3306/binlogs/my3306_bin
4. PHP 7.3 Installtaion
# Add Remi repository and install PHP 7.3
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install -y php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json \
php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache \
php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip \
php73-php-recode php73-php-snmp php73-php-soap php73-php-xml php73-php-ldap
# Configure php.ini
vim /etc/opt/remi/php73/php.ini
# Set/modify:
date.timezone = Asia/Shanghai
max_execution_time = 300
post_max_size = 16M
max_input_time = 300
mysqli.default_socket = /data/mysql-cluster/mysql3306/tmp/mysqld3306.sock
pdo_mysql.default_socket = /data/mysql-cluster/mysql3306/tmp/mysqld3306.sock
# Start PHP-FPM
systemctl start php73-php-fpm
systemctl enable php73-php-fpm
netstat -ntlp | grep 9000
5. Test PHP
cat > /usr/local/nginx/html/test.php << 'EOF'
<?php
$i=100;
echo $i;
?>
EOF
curl http://192.168.169.100/test.php
# Should output: 100
6. Zabbix Server and Agent Installation
# Download Zabbix 5.0.36 (use browser if wget fails)
cd /packages
wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.36.tar.gz
# Alternative: upload manually to /packages
tar zxvf zabbix-5.0.36.tar.gz -C /data/
cd /data/zabbix-5.0.36
# Install extra dependencies
yum install -y net-snmp-devel net-snmp-utils
# Compile and install
./configure --enable-server --enable-proxy --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl
make install
echo $? # Should be 0
# Create MySQL socket symlink for Zabbix
ln -s /data/mysql-cluster/mysql3306/tmp/mysqld3306.sock /tmp/mysql.sock
# Import database schema (run in order)
cd /data/zabbix-5.0.36/database/mysql/
mysql -uzabbix -p'qaz123456' zabbix < schema.sql
mysql -uzabbix -p'qaz123456' zabbix < images.sql
mysql -uzabbix -p'qaz123456' zabbix < data.sql
# Configure Zabbix server
vim /usr/local/etc/zabbix_server.conf
# Set:
LogFile=/tmp/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword='qaz123456'
DBPort=3306
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
# Verify config (should show only non-commented, non-empty lines)
grep -v -E '^#|^$' /usr/local/etc/zabbix_server.conf
# Create library symlinks
ln -s /usr/local/mysql/lib/libmysqlclient.so.21 /usr/lib64
ln -s /usr/local/mysql/lib/private/libcrypto.so.1.1 /usr/lib64
ln -s /usr/local/mysql/lib/private/libssl.so.1.1 /usr/lib64
# Start Zabbix server
zabbix_server
netstat -nulpt | grep zabbix_server # Expected port 10051
7. Prepare Zabbix Web Frontend
# Copy PHP UI files to Nginx document root
cp -a /data/zabbix-5.0.36/ui/* /usr/local/nginx/html
chmod -R 777 /usr/local/nginx/html
chown -R zabbix:mysql /usr/local/nginx/html/*
8. Web Setup
Access http://192.168.169.100/setup.php (replace IP).
- Database type: MySQL
- Databace user:
zabbix - Password:
qaz123456 - Follow the wizard clicking "Next step" until completion.
- Default login credentials:
Admin/zabbix
After signing in, the Zabbix dashboard appears. The installation is complete.