Zabbix

Installing Zabbix 7 LTS on Ubuntu

published on

This guide is all about installing Zabbix 7 on Ubuntu. If you want to use an earlier version of Zabbix for some reason see some of the earlier guides on Zabbix on this site.

Whilst previous tutorials have used Openresty this one uses NGinx to make things easier.

Initial setup

To begin add repositories for PHP and NGinx rather than using the default ones:

sudo add-apt-repository ppa:ondrej/php
sudo add-apt-repository ppa:ondrej/nginx
sudo apt-get update

Install PHP

It's now time to install PHP and a number of accompanying packages that Zabbix will use:

sudo apt install openssl php8.3-{common, cli, bz2, zip, curl, intl, mysql, pgsql, snmp, memcached, imagick, gd, imap, ldap, soap, tidy, xml, gd, gmp, pspell, mbstring, opcache, fpm, ssh2, imap, redis, apcu, mcrypt, bcmath}

Install MariaDB

We should now install MariaDB so that Zabbix will be able to use an SQL database:

sudo apt install mariadb-server mariadb-client
sudo systemctl enable mariadb
sudo mysql_secure_installation

The /etc/mysql/mariadb.conf.d/50-server.cnf file should already contain the first line below. If it doesn't then add it. The second line will need adding just below the first one:

bind-address = 127.0.0.1
local-infile = 0

Finally, restart the mariadb package:

sudo systemctl restart mariadb

Create the database that Zabbix will use

Execute sudo mysql -u root -p to access MySQL as the root user and enter the following commands. Remember to change the password below to something more secure:

create database zabbix character set utf8mb4 collate utf8mb4_bin;
create user zabbix@localhost identified by 'password';
grant all privileges on zabbix.* to zabbix@localhost;
set global log_bin_trust_function_creators = 1;
exit

Install NGinx

Now we can move on to installing NGinx. This is also quite simple:

sudo apt update && sudo apt install nginx
sudo rm /etc/nginx/sites-enabled/default

It's time to install Zabbix

Now it is time to install Zabbix. The instructions below presume that you are installing Zabbix 7 on Ubuntu 22.04. However, if you are using a different version of Ubuntu make sure to visit https://www.zabbix.com/download to get the instructions you need for your version of Ubuntu.

Run the following three commands to add the correct repository:

wget https://repo.zabbix.com/zabbix/7.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_7.0-2+ubuntu22.04_all.deb
sudo dpkg -i zabbix-release_7.0-2+ubuntu22.04_all.deb
sudo apt update

Now install the necessary Zabbix components by running:

sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-sql-scripts zabbix-agent

Finally, set up the database by running:

zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix

Make some more changes

First of all we need to make a change at the MySQL prompt. Run sudo mysql -uroot -p and enter the following commands:

set global log_bin_trust_function_creators = 0;
exit

Now add the password you chose for your database to the Zabbix server configuration file. Edit the /etc/zabbix/zabbix_server.conf file and update or add the DBPassword line with the password you chose above.

Set up the server block

You've already installed a server block when installing Zabbix above. However, it needs to now be updated to accept requests from your chosen domain name.

Edit the /etc/zabbix/nginx.conf file and update the Listen and server_name directives. Typically Listen would be set to port 80.

Finally enable your settings by restarting the software:

sudo systemctl restart php8.3-fpm zabbix-server zabbix-agent nginx
sudo systemctl enable zabbix-server zabbix-agent nginx

Get a TLS certificate

It's now time to get a TLS certificate so that you don't access Zabbix over an unsecure connection. Run the following commands to install certbot and request a certificate:

sudo apt-get install snapd
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot 
sudo certbot -d [domain]  --nginx
sudo certbot renew --dry-run

You can add multiple -d [domain] sections on the same line above in the event that you want to secure both [domain] and www.[domain].

Check your firewall

This guide presumes you already have a firewall installed and set up. You need to make sure that ports 80, 443, 10050 and 10051 are open.

If you plan on using email notifications in Zabbix you will also want to open ports 465 and 587.

Setup Zabbix

We are now getting close to finishing our installation. Visit your domain and you should see a Zabbix welcome page. Follow the prompts to finish installing Zabbix.

When setup is over

Once you have completed the setup procedure you will be directed to the Zabbix login page. Initially the username is Adminand the password is zabbix.

Once you have logged in make sure to change the password. You can do this by selecting Users on the left-hand side then choosing Users in the menu that opens up. Now click on Admin and then click on Password. Finally, click on Change Password.

Congratulations

Well done! You have now finished installing Zabbix and can explore and use it as you wish. There is a lot of configure and learn and this is something you can explore and experiment with now that everything is working as it should.