Create a Monitoring Server using Zabbix 4 on Ubuntu 18.04

Estimated reading time: 5 min

Introduction

Zabbix is an enterprise-ready open source monitoring application for monitoring a large number of systems in real time. Zabbix can collect metrics from a different method such as Zabbix agent, SNMP or IPMI, etc. It provides an easy to use dashboard for monitoring the entire IT environment on a single interface. You can use the templatized alerts or you can also define your custom alerts on top of the metrics gathered. If an alert goes off, Zabbix can notify you using many channels such as email, Slack or Pagerduty, etc. Zabbix also provides extensive API interface to integrate it into your app.

In this tutorial, we will install the latest available version of Zabbix, Zabbix 4.2 on a Ubuntu 18.04 server. We will secure the Zabbix dashboard using Let’s Encrypt SSL certificates. We will also learn how to install Zabbix agent on a remote server to gather the metrics of a remote server.

Prerequisites

  • A VPS or Dedicated server with at least 1GB RAM and Ubuntu 18.04 installed.
  • You must be logged in via SSH as sudo or root user. This tutorial assumes that you are logged in as a sudo user.
  • A domain name pointed towards your Snel server to generate Let’s Encrypt certificate.

Step 1: Update the System

Update the system with the latest packages and security patches using these commands.

sudo apt update
sudo apt upgrade -y

After upgrade, make sure to reboot the system using the command sudo reboot.

Step 2: Add Zabbix Repository

Download Zabbix repository installer Debian package by running.

wget https://repo.zabbix.com/zabbix/4.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.2-1+bionic_all.deb

Install Zabbix repository into the system by installing the downloaded package.

sudo dpkg -i zabbix-release_4.2-1+bionic_all.deb

Update the Ubuntu repository cache.

sudo apt update

Step 3: Install Zabbix

Since we already have set up Zabbix repository in place, we can directly go ahead and install Zabbix by running the command.

sudo apt -y install zabbix-server-mysql zabbix-frontend-php zabbix-agent

The above command will install the Zabbix server and agent along with its front-end component. This will also install all other required dependencies such as Apache Web Server, MariaDB Server and PHP 7.2 with the required PHP modules.

Step 4: Create MySQL Database

MariaDB, which is an open source fork of MySQL is already running on our server. Secure the database instance by running the following command.

sudo mysql_secure_installation

Make sure to use a strong password for MySQL root user.

After going through all the steps in the above script. Login to the MySQL shell as root user by running the command.

sudo mysql -u root -p

Run the following queries to create a new database and a database user for Zabbix application.

CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY 'Password';
QUIT;

Make sure to replace Password with a very strong password and make a note of it.

Step 5: Import Database

Import Zabbix initial database by running the following command.

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

You will be asked to provide the password of zabbix database user which we have created earlier.

Open the Zabbix server configuration file.

sudo vi /etc/zabbix/zabbix_server.conf

Scroll down to find the following lines and enter the password of MySQL zabbix user.

### Option: DBPassword
#       Database password.
#       Comment this line if no password is used.
#
# Mandatory: no
# Default:
# DBPassword=

DBPassword=Password

Step 6: Configure Apache

Enable Apache SSL and rewrite module by running.

sudo a2enmod ssl rewrite

Open Zabbix Apache Vhost configuration file.

sudo vi /etc/apache2/conf-enabled/zabbix.conf

Scroll down to find the following PHP configuration. Uncomment the php_value date.timezone line and set the PHP timezone according to your geographical location.

     <IfModule mod_php7.c>
        php_value max_execution_time 300
        php_value memory_limit 128M
        php_value post_max_size 16M
        php_value upload_max_filesize 2M
        php_value max_input_time 300
        php_value max_input_vars 10000
        php_value always_populate_raw_post_data -1
        php_value date.timezone Europe/Amsterdam
    </IfModule>

Step 7: Configure Let’s Encrypt SSL

Install Certbot repository by running the following commands.

sudo apt -y install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt update

Install Certbot for Apache by running.

sudo apt-get install certbot python-certbot-apache

Generate the certificate and install in on default virtual host by running the following command.

sudo certbot --apache -d example.com

The command will ask you for your email address to send you renewal notices. While installing the certificate, it will ask you if you wish to redirect all HTTP request to HTTPS or not. Choose the option 2 to automatically redirect all HTTP requests to HTTPS.

The Certbot package comes with a cron job which will automatically renew the certificates when they are due for expiry.

Finally, restart Zabbix server, agent and Apache web server.

sudo systemctl restart zabbix-server zabbix-agent apache2

Also, enable the Zabbix server, agent and Apache web server to automatically start at boot time by running.

sudo systemctl enable zabbix-server zabbix-agent apache2

Step 8: Finish Installation from Browser

Open your favorite web browser and navigate to https://example.com/zabbix and you should see the following interface.

Proceed to the next step and you will be taken to the requirements interface. If you had followed the tutorial correctly, you should see that all the requirements are installed and configured.

On the next interface, you will need to provide the database details which you have created in Step 4 of the tutorial.

On next interface, Zabbix server details, leave the default options there and proceed to the next interface. On the final step, the installer will show you a summary of the changes. Proceed to install the software.

After installation, you will be taken to the login screen. Use the default login Admin and zabbix to login. After successful login, immediately change the login password.

By default, Zabbix is configured to monitor the server itself. You should see the server running and also the issues associated with the server.

Step 9: Installing Remote Zabbix Agent

In this tutorial, we will learn how to add Zabbix agent on a remote server using PSK (Pre-Shared Keys) encryption. We will use a Ubuntu 18.04 for this also. Log in to the remote server using ssh and set up Zabbix repository by running the following commands.

wget https://repo.zabbix.com/zabbix/4.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.2-1+bionic_all.deb
sudo dpkg -i zabbix-release_4.2-1+bionic_all.deb
sudo apt update

Install Zabbix agent by running the command.

sudo apt -y install zabbix-agent

Generate a 32-bit long random key using OpenSSL and save it in a file.

openssl rand -hex 32 | sudo tee /etc/zabbix/zabbix_agentd.psk

The above command will also print the key on the terminal. Make a note of it as it will be required later while adding the agent on the dashboard.

Now open the Zabbix client configuration file by running the command.

sudo vi /etc/zabbix/zabbix_agentd.conf

Scroll down to find the following lines.

Server=127.0.0.1

Replace it with the actual IP address of your Zabbix server.

Server=10.0.25.26

Similarly, also provide actual Zabbix server IP address in ServerActive configuration.

ServerActive=10.0.25.26

Now scroll down to find the following lines.

####### TLS-RELATED PARAMETERS #######
### Option: TLSConnect
#       How the agent should connect to server or proxy. Used for active checks.
#       Only one value can be specified:
#               unencrypted - connect without encryption
#               psk         - connect using TLS and a pre-shared key
#               cert        - connect using TLS and a certificate
#
# Mandatory: yes, if TLS certificate or PSK parameters are defined (even for 'unencrypted' connection)
# Default:
# TLSConnect=unencrypted

Uncomment the TLSConnect and set it to psk.

TLSConnect=psk

Similarly, find and uncomment # TLSAccept=unencrypted and change it to.

TLSAccept=psk

Now, find and uncomment # TLSPSKIdentity= and change it to.

TLSPSKIdentity=Node01

Finally, find and uncomment # TLSPSKFile= and change it to.

TLSPSKFile=/etc/zabbix/zabbix_agentd.psk

Save the file and exit from the editor. Restart Zabbix agent and enable to it automatically start at boot time by running the command.

sudo systemctl restart zabbix-agent
sudo systemctl enable zabbix-agent

Step 10: Adding Remote Zabbix Agent

Login to your Zabbix server dashboard and navigate to Configuration >> Hosts. Click on Create Host button to add a new host.

Add host

On create hosts interface, provide a name for your node. Select Linux Servers on Groups and provide the IP address of agent machine.

On Template tab search for Template OS Linux and click Add button.

Now, navigate to Encryption tab and select PSK on both Connections to host and Connections from host. Provide the PSK identity name same as you entered in the agent configuration. Also provide the 32-bit PSK, which we generated on the agent machine.

Upon clicking the Add button, the remote host will be added to the server. If you see a green color on ZBX in availability means that server is able to talk to the remote Zabbix agent.

You will see the issues related to the new node on the dashboard page.

Conclusion

In this tutorial, we have learned how to install Zabbix server 4.2 on Ubuntu 18.04. We also secured the Zabbix dashboard using Let’s Encrypt SSL certificate. We successfully added Zabbix agent on a remote server and added it on our Zabbix server. You can now add as many hosts as you want into your Zabbix instance.

Was this article helpful?
Dislike 0
Views: 5710

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *