Install and configure Zabbix on CentOS

How to Install and Configure Zabbix on CentOS

This step-by-step tutorial shows you the exact process of how to install and configure Zabbix on CentOS (7/8/9). Find out how.

Zabbix is an open-source software built to monitor networks, servers, the cloud, applications, and services. By setting up Zabbix, you can detect problems via smart thresholds and get alerted when there is a critical issue going on in your environment.

CentOS being ideal for a server, many companies prefer to set up Zabbix on it. In this guide, we will show you from installing Zabbix to monitoring servers, everything included.

Let’s get started!

Prerequisites

You only need 4 things for using Zabbix:

How to Install and Configure Zabbix on CentOS

As shown above, to install and configure Zabbix on CentOS, you should install some other programs first. So we will show you how to install them before we move to install Zabbix.

Install and Configure Apache

First of all, you need to install the Apache web server. To do that, use this command:

$ sudo yum install httpd

Output:

Installing Apache web server CentOS

After the installation is completed, check its running status with this command:

$ systemctl status httpd.service

If it’s inactive, you’ll need to start it by yourself. Do so using this command:

$ systemctl start httpd.service

Output:

Activate Apache server on CentOS

Install PHP

The next step is to install PHP and all the necessary extensions. But before that, you need to install the ‘epel’ repo using this command:

$ sudo yum install epel-release

Output:

Installing PHP on CentOS

After that, install PHP and all the necessary extensions with this command:

$ sudo yum install php php-pear php-cgi php-common php-mbstring php-snmp php-gd php-xml php-mysqlnd php-gettext php-bcmath

Now you need to tweak the “php.ini” configuration file. This will allow the Zabbix server to run smoothly. Open the file in nano first with this command:

$ sudo nano /etc/php.ini

It’s a very long file. Since you need to tweak a few values, it’s best that you use the search function in nano instead of manually searching them yourself. 

To search for a text in nano, press “Ctrl+W”. Then enter the text you want to search for. And then press “Enter” to jump to the first match of that text.

Find these variables in the file and change the values to the ones given here:

post_max_size = 16M

upload_max_filesize = 2M

max_execution_time 300

max_input_time = 300

memory_limit = 128M

session.auto_start = 0

mbstring.func_overload = 0

When you’re done, it’s time to set your timezone in the same file. This is how it looks in ours after modifying:

date.timezone = Asia/Dhaka

You can find your specific timezone in this PHP manual.

Now save the file by pressing “Ctrl+O” and exit with “Ctrl+X”. After that, you need to reboot the Apache system so that the changes take effect. Use the following command:

$ systemctl restart httpd.service

Output:

Reboot Apache server on CentOS

Install MariaDB

After PHP, you need to install the MariaDB server. For installing this, you will need quite some commands. This is because we need to add and configure a repo. No worries. We will show you all the needed commands.

Before anything else, if you don’t have wget, install that first with this command:

$ sudo yum install wget

Then one by one, execute the following commands:

$ sudo wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
$ chmod +x mariadb_repo_setup
$ sudo ./mariadb_repo_setup

Output:

Setting up MariaDB repo on centOS

Now install the MariaDB Client with these two commands:

$ sudo yum install perl-DBI libaio libsepol lsof boost-program-options
$ sudo yum install MariaDB-client

Output:

Installing MariaDB on CentOS
Installing MariaDB on CentOS for Zabbix server

After MariaDB gets installed successfully, start it with the following command:

$ systemctl start mariadb.service

Now you need to secure the MariaDB server. Run this command first:

$ mariadb-secure-installation

You will be taken through some prompts which you need to configure. Follow our image guides to set up MariaDB.

Output:

Securing MariaDB on CentOS for Zabbix server
Installing MariaDB on CentOS for Zabbix server

Create a Database for Zabbix

That being done, the next thing you need is to set up a database for Zabbix. Use this command:

$ mysql -uroot -p

Enter the root password which you created earlier. Now you need to create a user and another password for Zabbix. Use the following commands (but substitute the values to match your own):

$ MariaDB [(none)]> create database zabbixtest character set utf8 collate utf8_bin;
$ MariaDB [(none)]> create user ‘uzabbix’@’localhost’ identified by 'password1234';
$ MariaDB [(none)]> grant all privileges on zabbixtest.* to uzabbix@localhost;
$ MariaDB [(none)]> set global log_bin_trust_function_creators = 1;
$ MariaDB [(none)]> quit;

Output:

Creating database user on CentOS for Zabbix server

Install Zabbix Server on CentOS

After tackling all the requirements for installing Zabbix, you can now get started with the main course.

First, install the Zabbix repo with these two commands:

$ rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm
$ sudo dnf clean all

Output:

Installing Zabbix server on CentOS

Next, install all the Zabbix components with this command:

$ sudo dnf install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-agent

Output:

Installing Zabbix server on CentOS

For the changes to take effect on the Apache server, you need to reboot it. Issue this command:

$ systemctl restart httpd

Configure Zabbix Server on CentOS

Now that you’ve installed the Zabbix server and agent, you need to configure it. So the first thing to do is import the initial schema and data from Zabbix. For that, run this command:

$ zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -u uzabbix -p zabbixtest

After importing the schema, disable log_bin_trust_function_creators. Enter mysql with this command:

$ mysql -uroot -p

Enter your password and change the value like this:

$ MariaDB [(none)]> set global log_bin_trust_function_creators = 0;
$ MariaDB [(none)]> quit;

Output:

Change global log_bin_trust_function_creators value on MariaDB

Next up, open the Zabbix configuration file in nano. We will modify it. Use this command:

$ sudo nano /etc/zabbix/zabbix_server.conf

Edit the values of these variables like this:

DBHost=localhost
DBName=zabbixtest
DBUser=uzabbix
DBPassword=password1234

Remember to set your own values as you created previously. After that, save and exit. Then restart Zabbix with the following command:

$ systemctl restart zabbix-server.service

You also need to deal with the Zabbix Agent configuration file. Again, open it in nano using this command:

$ sudo nano /etc/zabbix/zabbix_agentd.conf

Edit these variables:

Server=127.0.0.1
ListenPort=10050

When done, save and exit. Then restart the Zabbix server once more.

Change Firewall Rules

Before moving on to the Zabbix front end, you need to modify some firewall rules. Do so by running these commands:

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

Lastly, start Zabbix and Apache servers. Also, enable them in boot. Use the two commands here:

$ systemctl restart zabbix-server zabbix-agent httpd php-fpm
$ systemctl enable zabbix-server zabbix-agent httpd php-fpm

Configure Zabbix Frontend on CentOS

This section is pretty straightforward. Open a web browser and use this template URL to start configuring the front:

https://<ip address>/zabbix/setup.php

You should see the Zabbix welcome screen. Click on “Next Step”. You will be taken to a Prerequisites page. Double-check if everything is okay. Then click “Next Step”.

Now fill out the form using the database info you created earlier. Here is what ours look like:

Database host: localhost
Database port: 0
Database name: zabbixtest
User: uzabbix
Password: <password>

When finished, click “Next Step”.

Next, you need to enter the host and port details. This is how ours look:

Host: localhost
Port: 10051
Name: Distroid Zabbix

Use any name you like. Then click on “Next Step”.

Now see if all the configurations are okay on the Pre-installation summary page. If so, proceed to the installation by clicking “Next Step”.

After the installation, you will get a congratulations message.

Next, go to the login page using this template URL:

https://<ip address>/zabbix/index/php

Use ‘Admin’ for your Username and ‘zabbix’ for the Password. You will be taken to the dashboard.

Set up Zabbix

You can set up all your monitoring processes and change other settings from this dashboard. 

For example, if you want to change your password, go to the ‘Administration’ tab. Then Users > User > Change Password. Enter your new password and click “Update”.

Other activities include:

  • Adding hosts for monitoring the Zabbix server: Configuration > Hosts > Create Host
  • Viewing graphs: Monitoring > Graphs

Final Thoughts

This guide shows you how to install and configure Zabbix on CentOS. We’ve covered every necessary step and required command to configure the server. 

Not everyone may be tech-savvy enough to complete the full tutorial without running into errors. If you happen to run into one, feel free to let us know in the comments. 

If this guide helped you, please share it.

Leave a Reply
Related Posts