Jump toUpdate content
How to monitor Instances with Zabbix on Ubuntu Focal Fossa
- compute
- instances
- Zabbix
- monitoring
- MariaDB
Zabbix is an open-source software that offers real-time monitoring of servers, virtual machines, network devices, and web applications. Zabbix provides monitoring metrics network utilization, CPU load and disk space consumption. These metrics are collected and stored in a database.
Zabbix allows you to determine the health status of an IT infrastructure, helps you analyze data over time which can be used to plan upgrades in the infrastructure when requirements grow.
Metrics are collected and stored in a database, allowing to determine the health status of an IT infrastructure, help to analyze data over time which can be used to plan upgrades in the infrastructure when requirements grow.
This tutorial uses two Ubuntu Focal Fossa (20.04) Instances. One acts as a server hosting the Zabbix application and the other acts as a client being monitored.
- You have an account and are logged into cloud.scaleway.com
- You have configured your SSH Key
- You have sudo privileges or access to the root user.
- You have two Instances running Ubuntu Bionic Beaver
- The instance acting as server should have a LEMP-Stack installed
Installing the Zabbix server
Make sure that a LEMP-Stack is installed on the instance before continuing.
The version of Zabbix available within the repositories of Ubuntu is outdated. Start by downloading the repository configuration package. Refer to the Zabbix website for the latest version of the repository:
wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-1+ubuntu20.04_all.deb
Install the repository configuration with the help of
dpkg
:dpkg -i zabbix-release_6.0-1+ubuntu20.04_all.deb
Update the apt packet cache to use the newly installed repository:
apt update
Install the Zabbix server, the web frontend and
zabbix-agent
which collects information about the instance itself:apt install zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-sql-scripts zabbix-agent
Setting up the MariaDB database
Data of the Zabbix server is stored in a rational database and the application comes with support for MariaDB (MySQL) and PostgreSQL. It is also possible to store data in nosql databases, like Elasticsearch.
This tutorial uses a MariaDB database with Zabbix.
Log into MariaDB with the user root and the password set during the installation:
mysql -uroot -p
Create the Zabbix database and set the charset to UTF-8:
create database zabbix character set utf8mb4 collate utf8mb4_bin;
Create a user for the Zabbix server, grant access to the database created previously and set a password for the user (
secure_zabbix_mariadb_password
):create user zabbix@localhost identified by 'secure_zabbix_mariadb_password';
grant all privileges on zabbix.* to zabbix@localhost;Flush the privileges to apply the new configuration:
flush privileges;
Exit the MariaDB console:
quit;
Set up the database schema and import the data into the database created previously with
zcat
as the file is compressed. When prompted, enter the password of the MariaDB user created previously. No output is returned when the data is imported successfully:zcat /usr/share/doc/zabbix-sql-scripts/mysql/server.sql.gz | mysql -uzabbix -p zabbix
Set the password in the Zabbix configuration file by opening it in a text editor (i.e.
nano
):nano /etc/zabbix/zabbix_server.conf
Scroll down to this section:
### Option: DBPassword
# Database password.
# Comment this line if no password is used.
#
# Mandatory: no
# Default:
# DBPassword=Uncomment the line
# DBPassword
by removing the leading hash and set the password (DBPassword=secure_zabbix_mariadb_password
) for the Zabbix MariaDB user. Then safe the file and quit the text editor.
Configuring Nginx
Create an Nginx configuration file for the Zabbix web interface and open it in a text editor. Make sure to replace
zabbix.example.com
with the hostname of your instance:nano /etc/nginx/sites-available/zabbix.example.com
Copy the following content into the configuration file:
server {
listen 80;
server_name zabbix.example.com;
root /usr/share/zabbix;
location / {
index index.php index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock; # Important: Make sure that the path corresponds to the PHP version installed on the instance
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param PHP_VALUE "
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone = Europe/Paris
always_populate_raw_post_data = -1
";
fastcgi_buffers 8 256k;
fastcgi_buffer_size 128k;
fastcgi_intercept_errors on;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}Important:For security reasons, we recommend that you use an encrypted connection to the Zabbix web interface. A free certificate can be obtained from Let’s Encrypt.
Create a symlink to activate the new server block
ln -s /etc/nginx/sites-available/zabbix.example.com /etc/nginx/sites-enabled/
Check the spelling syntax of the Nginx configuration:
nginx -t
If no errors were detected, restart Nginx to activate the new configuration:
systemctl restart nginx.service
Start the Zabbix service and enable it to be started automatically during the system startup:
systemctl start zabbix-server && systemctl enable zabbix-server
Verify the status of the Zabbix server:
systemctl status zabbix-server
Configuring the Zabbix web interface
Type the domain name of your Zabbix instance in a web browser and open the page. The Installation wizard displays. Click Next step to launch it:
A check of pre-requirements displays, all off the values must have the status OK.
Click Next step to continue:
Enter the MariaDB (MySQL) database information. They are already configured for the Zabbix server, but the web interface requires them too. Click Next step once the information is filled in the form.
Click Next step to continue. A pre-installation summary displays.
Check that all given information is correct and click Next step to continue.
Click Finish to complete the installation of the Zabbix web interface:
Configuring Zabbix agent
The following steps must be done on the second instance which shall be monitored by Zabbix.
Log into the second instance via SSH.
Download and install the repository configuration. As on the server, the Zabbix repository needs to be added to apt, to be able to use the latest release of the tool.
wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-1+ubuntu20.04_all.deb
dpkg -i zabbix-release_6.0-1+ubuntu20.04_all.debUpdate the apt package index.
apt update
Install
zabbix-agent
.apt install zabbix-agent
Generate a pre-shared key (PSK) to secure the connection between the server and agent.
sh -c "openssl rand -hex 32 > /etc/zabbix/zabbix_agentd.psk" && cat /etc/zabbix/zabbix_agentd.psk
Important:Zabbix also supports TLS certificates for authentication. In this tutorial PSKs are used as a basic authentication method.
An output as the following displays. Take a note of it, as it will be required later.
01134cd49a5a27cc07d8469ebe9610841ce4062337d7cbaa337a4290682b6acc
Open the Zabbix Agent configuration file in a text editor (i.e.
nano
):nano /etc/zabbix/zabbix_agentd.conf
Scroll down until the following block displays on screen:
### Option: Server
# List of comma delimited IP addresses, optionally in CIDR notation, or DNS names of Zabbix servers and $
# Incoming connections will be accepted only from the hosts listed here.
# If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally
# and '::/0' will allow any IPv4 or IPv6 address.
# '0.0.0.0/0' can be used to allow any IPv4 address.
# Example: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.example.com
#
# Mandatory: yes, if StartAgents is not explicitly set to 0
# Default:
# Server=
Server=127.0.0.1Replace
127.0.0.1
with the IP of the Zabbix server instance.Scroll down further in the configuration file until the
TLSConnect
block displays on screen.### 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=unencryptedUncomment the Line
# TLSConnect=unencrypted
and modify it as follows:TLSConnect=psk
.Scroll down to the
TLSAccept
block which manages incoming connections.### Option: TLSAccept
# What incoming connections to accept.
# Multiple values can be specified, separated by comma:
# unencrypted - accept connections without encryption
# psk - accept connections secured with TLS and a pre-shared key
# cert - accept connections secured with TLS and a certificate
#
# Mandatory: yes, if TLS certificate or PSK parameters are defined (even for 'unencrypted' connection)
# Default:
# TLSAccept=unencryptedUncomment the line
# TLSAccept=unencrypted
and modify it as follows:TLSAccept=psk
.Scroll down to the
TLSPSKIdentity
block in the configuration file.### Option: TLSPSKIdentity
# Unique, case sensitive string used to identify the pre-shared key.
#
# Mandatory: no
# Default:
# TLSPSKIdentity=Uncomment the last line of the block and set a unique name to identify the PSK used:
TLSPSKIdentity=ZabbixPSK-01
. This value is used as PSK ID when adding the host through the Zabbix web interface.Scroll down to the
TLSPSKFile
block in the configuration file to provide the file path to the key generated in a previous step.### Option: TLSPSKFile
# Full pathname of a file containing the pre-shared key.
#
# Mandatory: no
# Default:
# TLSPSKFile=Uncomment the last line of block and set the path to the PSK file:
TLSPSKFile=/etc/zabbix/zabbix_agentd.psk
. Then save the file and exit the editor.Restart the
zabbix-agent
service and enable it to start automatically during the system boot.systemctl restart zabbix-agent
systemctl enable zabbix-agentAllow traffic on port 10050, if ufw is installed and active on the Instance.
ufw allow 10050/tcp
Adding a host to Zabbix
Open a web browser and navigate to your Zabbix server instance (i.e.
http://zabbix.example.com/
). Enter the Username Admin and the Password zabbix, then click Sign in. The Zabbix dashboard displays:Click Configuration, then Hosts once you log in. On the hosts page, click Create Host to add the second instance:
Enter the Host name of the second instance and its IP address. Optionally one or several groups can be chosen to bundle Instances in groups.
Click Templates to choose a configuration template for the instance. Select
Templates/Operating systems
->Linux by Zabbix agent
and click Select.Click the Encryption tab and set PSK for both Connections to host and Connections from host. Set PSK identity to the value of the
TLSPSKIdentity
configured in the Zabbix Agent configuration (i.e. ZabbixPSK-01) and set the PSK value to the key generated during the configuration of the Agent. Once set, click Add at the bottom of the page to add the instance to Zabbix.Once added, wait for about one minute before reloading the server list. The new Instance appears and the labels ZBX and PSK indicate that the Zabbix agent is running on the Instance and that the connection is encrypted with a pre-shared key.
Adding users
Click Administration in the navigation bar on the top of the page, then on Users
Click Create user to create a new user account.
Fill in the details of the new user. Required information are:
- Alias - The login of the user
- Name - The first name of the user
- Surname - The family name of the user
- Groups - The groups to which the user belongs. Choose Zabbix Administrators to create a new admin user
- Password and Password confirmation
The other values are already pre-set in working condition.
Once all information are entered, click Add to create the user.
Configuring email notifications
Zabbix proposes a wide range of notification plugins including emails, jabber, SMS and many more to get alerted in case of an issue.
To configure email notifications, click Administration, then on Media types in the navigation bar on the top of the page. A list of all pre-configured notification options displays:
Click Email to edit the settings. Enter the SMTP credentials of your email provider and update the configuration by clicking on Update.
Note:To send email from instance, make sure to unblock the SMTP ports in the Instances security group.
Click Administration in the navigation bar on the top of the page, then on Users
Click the Alias of the user to modify.
Click the Media tab, then on Add to configure a new notification
Enter the destination email address and notification time-ranges, then click Add.
Click Update to make the modifications effective. An email notification is being sent on each event.
Displaying status graphs
Zabbix collects status information of the Instances and generates status graphs from them.
Click Monitoring, then on Graphs in the navigation bar on top of the page.
Select the instance and the services to display, then choose the desired time-frame for the graph:
This setup allows basic monitoring of Instances. For more information on how to monitor devices and services with Zabbix, refer to the official documentation.