Ubuntu

How to install and configure Zabbix monitoring server on Linux

Install and Configure Zabbix Server

Zabbix is an open-source utility for monitoring servers, network devices, network services, and applications. It helps to keep an eye on the network infrastructure and detect issues with hardware or software programs. Zabbix tools gather information from the devices being monitored and send it to a central authority.

Zabbix has two major components: Zabbix server and Zabbix agent. Zabbix server is the main component that receives the collected data from the monitored devices. Zabbix agent collects data from the devices you want to monitor and forward it to the Zabbix server.

In this post, we will be explaining how to install and configure Zabbix on Linux to monitor servers health. We will be using two Linux machines; one as a monitoring server on which we will install and configure the Zabbix server and the other as a client that we want to monitor. On the client machine, we will install the Zabbix agent that will collect data and report to the Zabbix server. We will also install the Zabbix agent on the Zabbix monitoring server so that it can also monitor itself.

Note: We will be using the Ubuntu 20.04 LTS (Focal Fossa) for both the Zabbix server and client machine. For both machines, we will require Sudo privileges.

Step 1: Installing Pre-requisites

Zabbix uses MySQL as a backend database for storing the collected information while it uses Apache and PHP as the frontend for serving the web interface. On the machine that you want to configure as Zabbix monitoring server, you will need to install:

  1. Apache 1.3.12 or later
  2. PHP 7.2.5 or later
  3. MySQL: 5.5 or 8.0.x

Installing Apache Web Server

Apache web server will be used to serve the Zabbix web interface. Issue the below commands in Terminal to install it:

$ sudo apt update

$ sudo apt install apache2

You can also visit our post on How to install Apache web server on Linux.

To verify if Apache service is enabled and running. Issue the below command:

$ sudo systemctl status apache2

If the service is not enabled or running, you can manually enable and start is using the below commands:

$ sudo systemctl enable apache2

$ sudo systemctl start apache2

Now if a firewall is running on your system, allow the Apache through it:

$ sudo ufw allow ‘Apache’

Installing and Configuring PHP Packages

Now we will install PHP along with few dependencies. Issue the following command in Terminal to do this:

$ sudo apt install php-cli php-common php-dev php-pear php-gd php-mbstring php-mysql php-xml php-bcmath libapache2-mod-php

After the installation of PHP packages is completed, we will need to do a little configuration. Edit the “php.ini” configuration file for Apache2:

$ sudo nano /etc/php/7.4/apache2/php.ini

Make the following changes in the file. Remove the semicolon (;) from the date.timezone line.

date.timezone = <Your_Time_Zone>
max_execution_time = 600 
max_input_time = 600 
memory_limit = 256M 
post_max_size = 32M 
upload_max_filesize = 16M

Replace <Your_Time_Zone> with the time zone of your server’s location.

Now edit the “php.ini” configuration file for PHP cli:

$ sudo nano /etc/php/7.4/cli/php.ini

Make the same above changes in this file, then save, and close it.

Installing and Configuring MySQL Server

Now in this step, we will install and configure MySQL server to store the data collected by the Zabbix server from the agents. The version of MySQL currently available on Ubuntu 20.04 LTS repositories is 8.0. You can also follow our guide on Installing MySQL server.

Issue the below command in Terminal to install MySQL server:

$ sudo apt install mysql-server

Once the installation is completed, issue the below command to secure the SQL server. It will set the root password for the MySQL server along with some other security options.

$ sudo mysql_secure_installation

Hit y for all of the prompts. When asked to set the root password, enter the password twice.

Step 2: Installing and Configuring Zabbix

Now we will install and configure Zabbix on the same machine where we have installed all the prerequisites (Apache, MySQL, and PHP).

1. Install Zabbix Repository

First, we will need to download and install the Zabbix official repository to our system. Issue the below commands in Terminal to do so:

$ wget https://repo.zabbix.com/zabbix/5.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.2-1+ubuntu20.04_all.deb
$ sudo dpkg -i zabbix-release_5.2-1+ubuntu20.04_all.deb

Now update the local repository to include the Zabbix repository:

$ sudo apt update

Once the repository is updated, you can install Zabbix using the below command:

$ sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-agent

It will also install the Zabbix agent that will let the Zabbix server to monitor itself.

2. Import Zabbix Schema

Now we will need to import the Zabbix initial schema to the newly created “Zabbix” database.

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

Provide the password for the MySQL user “Zabbix” you created during the Zabbix database creation.

3. Configuring the Database for Zabbix Server

Now we will create a new database on MySQL and configure it for Zabbix server.

Create the Database

Login to MYSQL console as a root user. Issue the below command to do so:

$ sudo mysql -u root -p

Now to create a database, issue the following command:

create database zabbix character set utf8 collate utf8_bin;

Then create a user along with a password and grant it privileges to access the database:

grant all privileges on zabbix.* to zabbix@'localhost' identified by 'PASSWORD';

Now issue the below command to apply the changes:

flush privileges;

Then exit the console:

exit

Now the database and the user have been created for the Zabbix server.

Configure the Database

In order to point the Zabbix server to the database, edit the Zabbix configuration file zabbix_server.conf using the below command:

$ sudo nano /etc/Zabbix/ zabbix_server.conf

Look for the following line:

# DBPassword=

Uncomment this line and set its value to the password for the MySQL user “Zabbix” you created during the Zabbix database creation in the previous step.

Then save and close the zabbix_server.conf file.

Once you are done with the Zabbix configuration, restart the Apache server:

$ sudo systemctl restart apache2.service

Then start and enable the Zabbix server:

$ systemctl start zabbix-server

$ systemctl enable zabbix-server

Also verify if the Zabbix server is active and running properly:

$ systemctl status zabbix-server

Step 3: Configuring Zabbix Frontend

Now let’s configure the browser-based Zabbix frontend. Open any web browser and go to the following address:

http://zabbix-server-hostname-or-IP/zabbix

A wizard with the following welcome screen will appear. Click Next step.

Next, the wizard will check for all the pre-requisites. Make sure all the values for the pre-requisites are OK and then click Next step.

When the following screen shows up, enter the password for “Zabbix” user you configured earlier and then click Next step.

Now, you will be asked to enter the Zabbix server details. Provide the Zabbix server hostname or IP address or you can also leave the details as defaults. Then click Next step.

Then select your time zone and theme for the web interface. Then click Next step.

Now, you will see the Pre-installation summary for review. If you are ok with everything, click Next step.

Next, you will be informed that the installation of the Zabbix frontend has been completed. Click Finish to close the installation wizard. Then login to the Zabbix server using the following default credentials:

Username: Admin

Password: zabbix

After logging in, you will see the following Dashboard with one host available in it which is the Zabbix server itself as we have also installed the agent on it. Now the Zabbix server will start monitoring itself.

Step 4: Installing and Configuring Zabbix Agent on Client

Now on the client machine, we will install agent and connect it to the Zabbix server.

Install and Configure Agent

1. Issue the below commands in Terminal to install Zabbix repository:

$ wget https://repo.zabbix.com/zabbix/5.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.2-1+ubuntu20.04_all.deb
$ sudo dpkg -i zabbix-release_5.2-1+ubuntu20.04_all.deb

Then install the agent:

$ sudo apt install zabbix-agent

3. Edit the Zabbix agent configuration file:

$ sudo nano /etc/zabbix/zabbix_agentd.conf

Search the below entry in the file:

Server=127.0.0.1

Replace it with the Zabbix server’s IP address which in our case would be:

Server=192.168.72.157

Then save and close the Zabbix agent configuration file.

4. Start and enable the Zabbix service:

$ sudo systemctl start zabbix-agent

$ sudo systemctl enable zabbix-agent

Then verify whether the Zabbix agent is active and running properly.

$ sudo systemctl status zabbix-agent

5. Also, allow port 10050 through the firewall:

$ sudo ufw allow 10050/tcp

Add Host to the Zabbix Server

In the previous section, we installed the agent on the client machine. Now, we will add this machine in the Zabbix server.

1. Login to the Zabbix server web interface by visiting:

http://zabbix-server-hostname-or-IP/zabbix.

2. Go to Configuration > Hosts from the left navigation bar. Then click Create host as marked by the arrow in the following screenshot.

3. Type the hostname of the Zabbix agent machine and then add it to the Linux servers group.

4. Type the IP address of the Zabbix agent machine.

5. Then go to the Templates tab, select Templates/Operating systems.

From the list, select Linux by Zabbix agent and then click Select.

Then click the Add button.

Now click the Add button at the bottom of the web interface to add this host to the Zabbix server. Once added, you will be notified with the Host added notification at the top of window.

If you head over to Dashboard, you will see two hosts added to your Zabbix server; one is the Zabbix server itself and the other is the client machine.

In this post, you have learned how to install and configure the Zabbix server on Linux. You have also learned how to install and configure the Zabbix agent on the Zabbix server and the client machines. Now you can easily keep track of the servers and monitor their health.

Similar Posts