What is Zabbix?

Zabbix is an open source monitoring tool that can be deployed on-premises or on the cloud depending on that you intend to monitor. With Zabbix, you can monitor a variety of devices: from physical servers, and network devices such as routers and switches on your IT infrastructure as well as cloud infrastructure.

In this tutorial, we will show you step-by-step how to install and configure an open-source monitoring system Zabbix on the CentOS 8 system. This guide will cover some topics, including installation and configuration of the LAMP Stack for our Zabbix installation, and how to change the default password for Zabbix admin web UI.

Prerequisites:

Before getting started, ensure that the following requirements are fulfilled:

  • An instance of CentOS 8 with a minimum of 2GB RAM and 10 GB available disk space.
  • A regular login user with Sudo privileges
  • Stable Internet Connection

What we will do?

Install Apache2/httpd on CentOS 7
Install and Configure PHP 7.2 and 7.4 on CentOS 8
Install and Configure MySQL
Install and Configure Zabbix on CentOS 8
Configure FirewallD
Zabbix Initial-Setup
Change Default Admin

Start installation

Login to your centos with root privilege. 
# Set email
HOSTNAME=zabbix01
DOMAINNAME=yourdomain.com
MAILTO=$ADMIN_EMAIL
PHP_VERSION=7.4
PHP_VERSION_SHORT=74
PHP_DEBUG_IP=“yourdebugip”
TIME_ZONE=“Asia/Kuala_Lumpur”
echo 
# Kernel domain name
kernel.domainname=`echo $DOMAINNAME`” >> /etc/sysctl.conf

 

echo -e “127.0.0.1\t`echo $HOSTNAME`.`echo $DOMAINNAME` `echo $HOSTNAME`” >> /etc/hosts
echo -e “::1\t`echo $HOSTNAME`.`echo $DOMAINNAME` `echo $HOSTNAME`” >> /etc/hosts
hostnamectl set-hostname $HOSTNAME.$DOMAINNAME
echo “HOSTNAME=\”$HOSTNAME.$DOMAINNAME\”” >> /etc/sysconfig/network
sysctl -p /etc/sysctl.conf

 

################################
# YUM Auto Update and rollback #
################################

 

echo ‘tsflags=repackage’ >> /etc/yum.conf
echo ‘%_repackage_all_erasures 1’ >> /etc/rpm/macros
mkdir -p /var/spool/repackage

 

echo ‘#!/bin/sh
yum update -y’ > /etc/yum_auto_update.sh

 

# HOW TO RESTORE:
# yum history
# yum history undo ID
# rpm -Uvh �rollback ‘3 hours ago’
# rpm -Uvh �rollback ‘august 13’
# rpm -Uvh �rollback ‘yesterday’

 

# Time zone:
ln -sf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime
#######################################################
#   Disable iptables at boot time and in process      #
#######################################################
systemctl disable iptables
service iptables stop
iptables-save > /tmp/iptables.txt
iptables-restore < /tmp/iptables.txt

 

# security precautions
# crond security to disable all users to run crond
echo ALL >>/etc/cron.deny

 

#disable IPv6
echo -e “NETWORKING_IPV6=no\nIPV6INIT=no” >>  /etc/sysconfig/network

 

#check if there is a user without password (empty password)
# cat /etc/shadow | awk -F: ‘($2==””){print $1}’

 

sed -i ‘s/#UseDNS yes/UseDNS no/g’ /etc/ssh/sshd_config
mkdir ~/.ssh
echo ‘GSSAPIAuthentication no’ > ~/.ssh/ssh_config

 

## add below lines to 
echo -e “root\tsoft\tnofile\t120000
root\thard\tnofile\t300000
mysql\tsoft\tnofile\t120000
mysql\thard\tnofile\t300000
apache\tsoft\tnofile\t120000
apache\thard\tnofile\t300000″ >> /etc/security/limits.conf

 

## exclude indonesia’s repositories
echo ‘exclude=.uk, .id, .ir, .cn, .th, .vn ‘ >> /etc/yum/pluginconf.d/fastestmirror.conf
echo ‘exclude=.netonboard.com’ >> /etc/yum/pluginconf.d/fastestmirror.conf
echo 
# by default MAILTO is unset, so crond mails the output by itself
# example:  MAILTO=root
MAILTO=`echo $ADMIN_EMAIL`

 

YUM_PARAMETER=\”-x kernel* -x php*\”
 >> /etc/sysconfig/yum-cron

 

sudo yum -y install httpd

#After the installation is complete, start the service and enable it to launch every time at system boot.
systemctl start httpd
systemctl enable httpd

yum -y instal net-tools

#The Apache/httpd web server has been installed on the system – check it using the netstat command.
netstat -plntu

#And you will get the default HTTP port 80 in the LISTEN state

Step 2 Install and Configure PHP 7.2 and PHP 7.4

#In this step, we will install PHP 7 from a third-party repository – we will install PHP 7.2 from the ‘webtatic’ repository.
#Before installing PHP 7 with all extensions needed, add the webtatic and the EPEL repository to the system.
#Run commands below.
yum -y install epel-release
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

#Now install PHP 7.2 packages from the webtatic repository using yum.
yum -y install mod_php72w php72w-cli php72w-common php72w-devel php72w-pear php72w-gd php72w-mbstring php72w-mysql php72w-xml php72w-bcmath

#And after the installation is complete, we need to edit the default ‘php.ini’ file using the vim editor.
vim /etc/php.ini

#Change the values of the configuration as shown below.
max_execution_time = 600
max_input_time = 600
memory_limit = 256M
post_max_size = 32M
upload_max_filesize = 16M
date.timezone = Asia/Jakarta

#save and exit

yum install php

#Now restart the httpd service.
systemctl restart httpd

#The PHP 7 installation and configuration for Zabbix has been completed.

Step 3Install and Configure MariaDB
#Zabbix offers support for many databases for the installation, including MySQL, PostgreSQL, SQLite, and Oracle database. For this guide, we will be using MariaDB as the database for our Zabbix installation.

#Install mariadb-server using the yum command below.
sudo yum -y install mariadb-server

#After the installation is complete, start the service and enable it to launch everytime at system boot.
systemctl start mariadb
systemctl enable mariadb

#Now run the command below to configure MariaDB root password.
mysql_secure_installation

#MariaDB database has been installed, and the root password has been configured.
#Next, we need to create a new database for our Zabbix installation. We will create a new database and user named ‘zabbix’ with password ‘[email protected]’.

mysql -u root -p

#Login to the MySQL shell.
create database zabbix;
grant all privileges on zabbix.* to [email protected]’localhost’ identified by ‘[email protected]’;
grant all privileges on zabbix.* to [email protected]’%’ identified by ‘[email protected]’;
flush privileges;

#New database for Zabbix installation has been created.

 Step 4 – Install and Configure Zabbix 
#In this step, we will install and configure Zabbix. We will install Zabbix from the official repository, then configure Zabbix-server and Zabbix-agent.

#- Install Zabbix Packages
#Add the Zabbix repository to the CentOS 7 system.

#Now install Zabbix using the yum command below.
yum -y install http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm

 

#Now install Zabbix using the yum command below.
yum -y install zabbix-get zabbix-server-mysql zabbix-web-mysql zabbix-agent

#Wait for the Zabbix packages installation.

#Import the Zabbix database sample to our ‘zabbix’ database. Go to the Zabbix documentation directory and extract the Zabbix sql file.

cd /usr/share/doc/zabbix-server-mysql-3.4.12/
gunzip create.sql.gz

#Now import the database sample to our ‘zabbix’ database.

mysql -u root -p yourdbpasswor < create.sql

create database zabbix;
grant all privileges on zabbix.* to [email protected]’localhost’ identified by ‘yourdbpassword’;
grant all privileges on zabbix.* to [email protected]’%’ identified by ‘yourdbpassword’;

set password for ‘zabbix’@’localhost’ = password(‘yourdbpassword’);
set password for ‘zabbix’@’%’ = password(‘yourdbpassword’);
flush privileges;
#Type your root password and make sure there is no error.

#- Configure Zabbix Server

#Zabbix-server is the central process of the Zabbix software system. We will configure the Zabbix-server by editing the configuration file using the vim editor.

#Run the following command.

vi /etc/zabbix/zabbix_server.conf

#On the database line configuration, type the configuration as below and change the ‘DBPassword’ value with your own database password.
# create default mysql password
MYSQL_ROOT_PASSWORD=$(cat /dev/urandom | tr -dc ‘a-zA-Z0-9\#\%’ | fold -w 32 | head -n 1)”1#1″
echo $MYSQL_ROOT_PASSWORD
echo “[client]
user=root
password=\”$MYSQL_ROOT_PASSWORD\”” > ~/.my.cnf

DBHost=localhost
DBPassword=yourdbpassword

#Save and exit.

#Now start the Zabbix-server service and enable it to launch every time at system boot.

systemctl start zabbix-server
systemctl enable zabbix-server

#Zabbix-server is running on the CentOS system – check it using the command below.

#And you will get the result as shown below.

active and running.

#- Configure Zabbix Agent

#Zabbix-agent must be installed on the target monitoring system. The agent will gather all information about the server and report data to the Zabbix-server.

#Edit the Zabbix-agent configuration file using vi.

#Change the following lines with your own info:

Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=zabbix

#Save and exit.

#Now start the Zabbix-agent and enable it to launch every time at system boot.

systemctl start zabbix-agent
systemctl enable zabbix-agent

#Zabbix-agent is running on the system – check it using the following command.

systemctl status zabbix-agent

#And you will get the result as shown below.
active and running

 Step 5 – Configure Firewalld
#In this step, we will open the HTTP and https port for Zabbix admin web UI, and will also add an additional port for Zabbix-server and Zabbix-agent.

#If you do not have firewalld on your system, install it using the following command.

yum -y install firewalld

systemctl start firewalld
systemctl enable firewalld

#Now we will open the HTTP and https port, and the port that will be used by the Zabbix-server and Zabbix agent (port 10051 and 10050).

#Run the following firewall-cmd commands.

firewall-cmd –add-service={http,https} –permanent
firewall-cmd –add-port={10051/tcp,10050/tcp} –permanent

#Now reload the firewalld configuration and check the port.

#Firewalld configuration for Zabbix installation has been completed.

Finalize Zabbix installation via a browser

Zabbix-Server-Setup-Page-CentOS8-768x404

The next page displays all the prerequisites needed for the installation of Zabbix. If some errors are displayed, click on the ‘Back’ button and install what’s missing. If there are no errors as shown, click ‘Next step’ to go ahead with the installation.

Pre-requisites-check-zabbix-gui-centos8-768x456

In the next step, provide the database details as shown and click ‘Next step

Zabbix-Database-Details-GUI-CentOS8-768x456

Next, specify the name of your database server as indicated in the ‘Name’ text field.  Leave other details just as they are and click ‘Next Step

Zabbix-Server-Details-CentOS8-768x456

The next page presents you with a summary of the database information that you have provided. If all is good, click ‘Next Step’. Else go back and make corrections if need be.

Pre-Installation-Summary-CentOS8-768x456

If the details you provided are correct, you will get a notification below indicating that you have successfully installed Zabbix server. Click ‘Finish’.

Zabbix-Successfull-installation-CentOS8-768x456

A login page will be displayed below: Use Admin as the username and zabbix as the password to sign in.

Zabbix-Login-Page-CentOS8-768x456

Bravo! you have successfully managed to install Zabbix server on CentOS 8.