How to Install and Configure Zabbix on Ubuntu 18.04
9 min read
Zabbix is one of the most popular open-source monitoring software tools. Zabbix collects metrics from your networks devices, systems and applications and ensures they are up and running. In case of any issues, Zabbix will send notification alerts via various methods.
Zabbix can be deployed for agent-based and agent-less monitoring. The Zabbix agent has a small footprint and can run on various platforms, including Linux, UNIX, macOS and Windows.
This tutorial describes how to install and configure the latest version of Zabbix 4.0 on an Ubuntu 18.04 server using MySQL as a database back-end. We will also show you how to install the Zabbix agent on a remote host and add the host to the Zabbix server.
Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges .
Creating MySQL Database
Zabbix supports both MySQL/MariaDB and PostgreSQL . In this tutorial, we’ll use MySQL as a database back-end.
If you already don’t have MySQL installed on your Ubuntu server you can install by following these instructions .
Login to the MySQL shell by typing the following command:
From within the MySQL shell, run the following SQL statement to create a new database :
CREATE DATABASE zabbix CHARACTER SET utf8 collate utf8_bin;
Next, create a MySQL user account and grant access to the database :
GRANT ALL ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY 'change-with-strong-password';
change-with-strong-passwordwith a strong password.
Once done, exit the mysql console by typing:
Installing Zabbix on Ubuntu
At the time of writing this article, the latest stable version of Zabbix is version 4.0. The Zabbix packages available in Ubuntu repositories are often outdated so we’ll use the official Zabbix repository .
1. Installing Zabbix
Download the latest Zabbix repository
.deb package with following wget command :
Once the file is downloaded, add the Zabbix repository to your Ubuntu 18.04 system by typing:
sudo apt install ./zabbix-release_4.0-2+bionic_all.deb
Update the package index and install the Zabbix server, the web frontend with MySQL database support and the Zabbix agent:
sudo apt update
sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-agent
2. Configuring PHP for Zabbix frontend
During the installation, an Apache configuration file is created that contains all the required Apache and PHP settings. You only need to make a small change and set the appropriate timezone .
Open the configuration file, uncomment the timezone line and change it to your time zone. You can find the complete list of time zones supported by PHP here .
... <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 America/Denver </IfModule> ...
Once done, save the configuration file and restart the Apache service for the changes to take effect:
sudo systemctl restart apache2
3. Configuring the MySQL Database For Zabbix Server
The Zabbix installation package provides a dump file which includes an initial schema and data for the Zabbix server with MySQL.
Import the MySQL dump file by running:
zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p zabbix
When prompted enter the user password you created previously. On success, no output is given.
Next, we need to edit the Zabbix configuration and set the database password.
Open the configuration file in your editor:
sudo nano /etc/zabbix/zabbix_server.conf
Search for the following section, uncomment the
DBPassword directive and add the database password.
... ### Option: DBPassword # Database password. # Comment this line if no password is used. # # Mandatory: no # Default: DBPassword=change-with-strong-password ...
Save and close the file.
Restart the Zabbix server and agent services and make them start at system boot:
sudo systemctl restart zabbix-server zabbix-agent
sudo systemctl enable zabbix-server zabbix-agent
To check whether the Zabbix server is running type:
sudo systemctl status zabbix-server
● zabbix-server.service - Zabbix Server Loaded: loaded (/lib/systemd/system/zabbix-server.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2018-11-29 03:30:44 PST; 43s ago Main PID: 14293 (zabbix_server) Tasks: 34 (limit: 2319) CGroup: /system.slice/zabbix-server.service ...
Installing and Configuring Zabbix Frontend
Zabbix web interface is written in PHP and allows us to configure the server, view gathered data and add hosts that we want to monitor.
Before start using the web interface, we need to install it.
Open your favorite browser and type your server’s domain name or public IP address followed by
On the first screen, you will be presented with a welcome message. Click
Next step to continue.
Next, you will see the following information page that lists all of the PHP prerequisites required to run the Zabbix Frontend. All of the values in this table should be
OK, scroll down to verify that everything is set up correctly. Once verified, click
Next step to proceed.
On the next screen, the setup wizard will ask you to enter your database connection details. Enter the MySQL user and database details you previously created.
Entering a name for the server is optional. Enter it if you have more than one Zabbix monitoring servers. If provided, it will be displayed in the menu bar and page titles.
Next step to continue.
On the next screen, you will be shown the pre-installation summary.
Next step and once the installation is completed you will be taken to a page informing you that Zabbix web interface has been installed. To access your Zabbix login page click on the
The default user is “Admin” and the password is “zabbix”. Enter the username and password and click on the
Log in button.
Once you log in, you will be redirected to the Zabbix administration dashboard.
From here, you can start customizing your Zabbix installation and adding new hosts. Your first step should be to change the current password. To do that navigate to the user profile page by clicking on the profile icon on the top navigation.
Adding a New Host to Zabbix Server
The procedure for adding a new host for monitoring to the Zabbix server includes two steps.
First, you need to install the Zabbix agent on the remote host and then add the host to the Zabbix server through the web interface.
Installing the Zabbix agent
This tutorial assumes that the host machine also uses Ubuntu 18.04.
Same as when installing the Zabbix server, run the following commands to enable the Zabbix repository:
sudo apt install ./zabbix-release_4.0-2+bionic_all.deb
Update the package index and install the Zabbix agent package:
sudo apt update
sudo apt install zabbix-agent
Zabbix supports two methods for server-client communication encryption, Preshared Key (PSK) and certificate-based encryption. In this tutorial, we will use the pre-shared keys (PSK) method to secure the connection between the server and agent.
Use to following command to generate a pre-shared key and save it to a file:
openssl rand -hex 32 | sudo tee /etc/zabbix/zabbix_agentd.psk
The PSK key will look something like this:
Open the Zabbix agent configuration file:
sudo nano /etc/zabbix/zabbix_agentd.conf
Search for the
Server IP Address and change it from the default value to your Zabbix server IP:
... ### Option: Server # List of comma delimited IP addresses, optionally in CIDR notation, or DNS names of Zabbix servers and Zabbix proxies. # 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.1 ...
Next, find the
TSLConnect option, uncomment it and set it to
... ### 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=psk ...
TLSAccept option, uncomment it and set it to
... ### 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=psk ...
Next, find the
TLSPSKIdentity option, uncomment it and set it to
PSK 001 The value needs to be a unique string:
... ### Option: TLSPSKIdentity # Unique, case sensitive string used to identify the pre-shared key. # # Mandatory: no # Default: TLSPSKIdentity=PSK 001 ...
Finally, locate the
TLSPSKFile option, uncomment it and set it to point to the previously created pre-shared key:
... ### Option: TLSPSKFile # Full pathname of a file containing the pre-shared key. # # Mandatory: no # Default: TLSPSKFile=/etc/zabbix/zabbix_agentd.psk ...
Once done, save and close the file.
Start the Zabbix agent service and set it to start at boot time with:
sudo systemctl start zabbix-agent
sudo systemctl enable zabbix-agent
Next, you’ll need to add a firewall rule that enables traffic from your Zabbix server on TCP port
Assuming you are using
UFW to manage your firewall and you want to allow access from the
192.168.121.70 IP address you would run the following command:
sudo ufw allow proto tcp from 192.168.121.70 to any port 10050
Set up a New Host
Now that the agent on the remote host that you want to monitor is installed and configured the Next step is to register the host on the Zabbix server.
Log in to the Zabbix Server web interface as the admin user:
Once inside, in the top navigation bar click on the
Configuration, and then
Next, click on the blue
Create host button in the top right corner of the screen and the host configuration page will open:
Enter the Hostname and the IP Address of the remote host machine you want to monitor. Add the host to one or multiple groups by selecting the group from the list, or enter a non-existing group name to create a new one. The
Linux Servers group is a good choice.
Once done, click the
Templates tab. Select the
Template OS Linux and click on the
Add link to add the template to the host.
Next, click on the
Encryption tab. Select PSK for both
Connections to host and
Connections from host.
PSK identity value to
PSK 001, the value of the
TLSPSKIdentity option of the Zabbix agent you configured in the previous step.
PSK value filed add the key you generated for the Zabbix agent, the one stored in the
Finally, to add the host click on the blue Add
You have successfully installed the latest Zabbix on your Ubuntu system and learned how to add new hosts that you want to monitor.
You should now check the Zabbix Documentation and learn more about how to configure and use Zabbix.
If you hit a problem or have feedback, leave a comment below.