How to Install and Configure Zabbix on CentOS 7

Zabbix is an open source monitoring tool for network services, network hardware, servers, and application. Designed to track and monitor the status of your system and servers. Zabbix offers support for many database systems - including MySQL, PostgreSQL, SQLite, and IBM DB2  - to store data. Zabbix backend is written in C, and the frontend is written in PHP.

In this tutorial, we will show you step-by-step how to install and configure an open source monitoring system Zabbix 3.4 on the CentOS 7 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

  • CentOS 7 Server
  • Root privileges

What we will do?

  1. Install Apache2/httpd on CentOS 7
  2. Install and Configure PHP 7.2 on CentOS 7
  3. Install and Configure MySQL
  4. Install and Configure Zabbix 3.4 on CentOS 7
  5. Configure FirewallD
  6. Zabbix Initial-Setup
  7. Change Default Admin

Step 1 - Install Apache2/httpd

In this guide, we will run Zabbix under the Apache web server. The web server packages can be installed from the default CentOS 7 repository.

Install Apache/httpd using the yum command below.

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

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.

Netstat command

Step 2 - Install and Configure PHP 7.2 on CentOS 7

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.

Now restart the httpd service.

systemctl restart httpd

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

Step 3 - Install 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 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

Type your root password and press Enter.

Install MariaDB

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]'.

Login to the MySQL shell.

mysql -u root -p

And run the following MySQL queries on the 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.

Create database

Step 4 - Install and Configure Zabbix 3.4

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.

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.

Install Zabbix

- Import Database Sample

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.6/
gunzip create.sql.gz

Now import the database sample to our 'zabbix' database.

mysql -u root -p zabbix < create.sql

Type your root password and make sure there is no error.

Import the database

- 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.

vim /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.

DBHost=localhost
[email protected]

Save and exit.

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

systemctl start zabbix-server
systemctl enable zabbix-server

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

systemctl status zabbix-server

And you will get the result as shown below.

Configure zabbix server

- Configure Zabbix Agent

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

Edit the Zabbix-agent configuration file using vim.

vim /etc/zabbix/zabbix_agentd.conf

Change following lines with your own info:

 Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=hakase-labs

Save and exit.

Now start the zabbix-agent and enable it to launch everytime 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.

Configure zabbix agent

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

Start the firewalld service and enable it to launch everytime at system boot.

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.

firewall-cmd --reload
firewall-cmd --list-all

Configure the firewall

Firewalld configuration for Zabbix installation has been completed.

Step 6 - Zabbix Initial Setup

Before going any further, we will restart all of our services using the systemctl commands below.

systemctl restart zabbix-server
systemctl restart zabbix-agent
systemctl restart httpd

Now open your web browser, and type your server IP address.

http://192.168.33.10/zabbix/

And you will be redirected to the Zabbix welcome message.

Zabbix setup

Click the 'Next Step' button.

Now, Zabbix will check all system requirements for its installation. Make sure there is no error.

Check pre-requisites

Then click the 'Next step' button again.

For the database info, type all your database setup.

Configure db

And click the 'Next step' button.

Now comes the Zabbix server details configuration. On the 'Host' field, type your own server IP address, and change the name with your own domain name or hostname.

Server details

Click the 'Next step' button again.

Make sure all of those configurations are correct, then click the next button to install Zabbix.

Installation summary

And when the installation is complete, you will get the page as shown below.

Zabbix successfully installed

Click the 'Finish' button and you will be redirected to the Zabbix login page.

Login with default user 'admin' and password 'zabbix'.

Login to zabbix

Now you get the Zabbix admin Dashboard.

Zabbix dashboard

Zabbix server installation has been completed.

Step 7 - Change Default Admin Password

In this step, we want to change the default Zabbix admin password for security.

On the Zabbix admin dashboard, click the user icon on the top right.

Change Default Admin Password

Click the 'Change Password' button and type your new password.

Change password

Now click the 'update' button, and the default admin password has been changed.

Zabbix monitoring system is now installed on the CentOS 7 server.

Reference

About Muhammad Arul

Muhammad Arul is a freelance system administrator and technical writer. He is working with Linux Environments for more than 5 years, an Open Source enthusiast and highly motivated on Linux installation and troubleshooting. Mostly working with RedHat/CentOS Linux and Ubuntu/Debian, Nginx and Apache web server, Proxmox, Zimbra Administration, and Website Optimization. Currently learning about OpenStack and Container Technology.

Share this page:

Suggested articles

10 Comment(s)

Add comment

Comments

By: A Hanjrah at: 2018-05-07 19:33:22

Works like a charm! Each and every command is in accordance with CentOS 7. Thank you for this awsome tutorial.

By: Jacob Biblow at: 2018-05-29 13:36:42

Works like a charm!

1. Missing the postfix part for sending notifications via email.

2. there is an error when going to latest data that says: "

count(): Parameter must be an array or an object that implements Countable [ in latest.php:104]

"

 

anyway thank you so much!

By: Andre C at: 2018-06-01 18:35:21

 Works like a charm! Each and every command is in accordance with Amazon LInux as well. Thank you for this awsome tutorial.

By: Gabriel at: 2018-06-22 14:52:55

I have a problem, and I have searched but I have not found the solution.

 

When typing systemctl status zabbix-server the result I get is the following:

 

? zabbix-server.service - Zabbix Server

   Loaded: loaded (/usr/lib/systemd/system/zabbix-server.service; enabled; vendor preset: disabled)

   Active: deactivating (sop-sigterm) (Result: exit-code) since Fri 2018-06-22 08:13:48 -04; 1h 5min ago

  Process: 15183 ExecStop = / bin / kill -SIGTERM $ MAINPID (code = exited, status = 1 / FAILURE)

  Process: 15128 ExecStart = / usr / sbin / zabbix_server -c $ CONFFILE (code = exited, status = 0 / SUCCESS)

 Main PID: 15130 (code = exited, status = 0 / SUCCESS)

   CGroup: /system.slice/zabbix-server.service

           ??15151 / usr / sbin / zabbix_server -c /etc/zabbix/zabbix_server.conf

           ??15153 / usr / sbin / zabbix_server -c /etc/zabbix/zabbix_server.conf

 

Jun 22 08:13:48 localhost.localdomain kill [15183]: with the same uid as the present process

Jun 22 08:13:48 localhost.localdomain kill [15183]: -s, --signal <sig> send specific signal

Jun 22 08:13:48 localhost.localdomain kill [15183]: -q, --queue <sig> use sigqueue (2) rather than kill (2)

Jun 22 08:13:48 localhost.localdomain kill [15183]: -p, --pid print pids without signaling them

Jun 22 08:13:48 localhost.localdomain kill [15183]: -l, --list [= <signal>] list signal names, or convert one to a name

Jun 22 08:13:48 localhost.localdomain kill [15183]: -L, --table list signal names and numbers

Jun 22 08:13:48 localhost.localdomain kill [15183]: -h, --help display this help and exit

Jun 22 08:13:48 localhost.localdomain kill [15183]: -V, --version output version information and exit

Jun 22 08:13:48 localhost.localdomain kill [15183]: For more details see kill (1).

Jun 22 08:13:48 localhost.localdomain systemd [1]: zabbix-server.service: control process exited, code = exited status = 1

 

it's diferent.

 

Please, Help me

By: Daniel at: 2018-07-23 23:48:06

I had a similar issue.  Cause is SELINUX for me.  Disabled until i can understand the details...

Here is a clue.

http://d-prototype.com/archives/10737

By: kho at: 2018-08-10 11:02:46

thanks a lot, save time.

but after all the installation done it gives me the error Zabbix server is not running?

how to fix? 

i have added listenIP also

By: Nguy?n M?nh D?ng at: 2018-08-29 02:14:59

First you need to know what causes make your error by using command :vi /var/log/zabbix/zabbix_server.log

After that you can follow intructions below : (in my case I met an error : Cannot bind socket to “/var/run/zabbix/zabbix_server_preprocessing.sock”: [13] Permission denied.)

# getsebool -a | grep zabbix # setsebool -P zabbix_can_network on # systemctl stop mysqld # systemctl stop zabbix-server # systemctl stop zabbix-agent # yum install -y policycoreutils-python # sudo yum install wget # wget -O zabbix_server_add.te https://support.zabbix.com/secure/attachment/53320/53320_zabbix_server_add.te –no-check-certificate # checkmodule -M -m -o zabbix_server_add.mod zabbix_server_add.te # semodule_package -o zabbix_server_add.pp -m zabbix_server_add.mod # semodule -i zabbix_server_add.pp # systemctl restart zabbix-server; # systemctl restart zabbix-agent # systemctl start mysqld # systemctl start zabbix-server # systemctl start zabbix-agent

After install python package you can fix your error!

Hope this help!

By: Tiborg at: 2018-10-01 18:46:03

Hello,

great tutorial!

But I am stuck at some point.

At the Zabbix pre-requisites it gives an error.

PHP option "date.timezone" unknown Fail

Time zone for PHP is not set (configuration parameter "date.timezone")

I already searched in the php file and I used date.timezone = Europe

 

I also changed it to Asia/Jakarta but the error still accurs.

How can I fix this? Thanks in advance.

By: till at: 2018-10-01 18:49:10

Try to set the timezone in php.ini file to this exact line:

date.timezone = "Asia/Jakarta"

and restart apache.

By: Tiborg at: 2018-10-02 12:30:43

Lol, I forgot to remove the ; before the command line date.timezone.

Thank you for the quick answer!