Installing Zabbix and Setting Up High Availability

ZABBIX

Installation and High Availability Setup

Zabbix is a powerful open-source monitoring solution that can monitor various services, servers, and network devices. In this blog, I will show how I installed the Zabbix server (version 7.0), configured it to use MariaDB as its database, and got it running on Ubuntu 22.04. I will also show how I setup 3 more Zabbix servers to ensure availability.

Single Node Setup

‣ Prerequisites

• Hypervisor

• 1 Virtual Machine

‣ My Setup

HYPERVISOR Proxmox
  • Dell PowerEdge R720
  • Intel Xeon E5-2680 v2 @ 2.80GHz
  • 256GB RAM
  • 7TB Storage
VIRTUAL MACHINE Ubuntu 22.04
  • 4 Cores
  • 8GB RAM
  • 80GB Storage

‣ Installation

Components

Zabbix Server : This is the core component that polls and traps data from your hosts, generates alerts, and communicates with the front end.

MariaDB Database : Zabbix data (items, triggers, configurations, historical data, etc.) is stored here.

Web Front End (Apache/NGINX + PHP) : Web Server that hosts the Zabbix UI.

This is the single node setup guide, which is good if you’re wanting to see if Zabbix is something that fits in your environment before setting up a high availability cluster.

Before starting, it’s always a good idea to ensure your system packages are up to date.

				
					sudo apt update
sudo apt upgrade -y
sudo shutdown -r now
				
			

After the reboot, I became a root user.

				
					sudo -s
				
			

Note

By default, Ubuntu disables root login over SSH for security reasons. If you’re like me and prefer to use something like MobaXterm, you can enable it until everything is setup and then disable it.

To enable SSH for root I edited the SSH configuration file.

				
					sudo nano /etc/ssh/sshd_config
				
			

I found the following line and uncommented it, and add yes.

				
					PermitRootLogin yes
				
			

I saved the file and then restarted SSH.

				
					sudo systemctl restart ssh
				
			

I then added the official Zabbix repository to my Ubuntu server, so that I’m able to install the latest Zabbix packages. (I installed version 7.0 and will later upgrade to 7.2)

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

				
			
  • wget – Downloads the Zabbix repository package.
  • dpkg -i – Installs the downloaded .deb package.
  • apt update – Refreshes the local package index to include the newly added repository

I then installed the Zabbix server, frontend, and agent.

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

Zabbix uses a web interface and a database to store information, so I installed Apache, MySQL, and PHP.

				
					sudo apt install apache2 -y
sudo apt install mysql-server -y
sudo apt install php php-mbstring php-bcmath php-xml php-gd php-ldap php-mysql php-zip -y
				
			

Note

By default Ubuntu does not have you setup a password for root.
In the following step, MySql will ask for root’s password.
To set one up I ran the following command sudo passwd root

I then logged into MariaDB to create a database for Zabbix.

				
					sudo mysql -u root -p
				
			

Next I created the Zabbix database and user.

				
					CREATE DATABASE zabbix CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'top_secrete_password';
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost';
set global log_bin_trust_function_creators = 1;
EXIT;
				
			
  • CREATE DATABASE zabbix – Creates a new database named zabbix.
  • CHARACTER SET utf8mb4 – Sets the character set to utf8mb4, which supports all Unicode characters, including emojis.
  • COLLATE utf8mb4_bin – Sets the collation to utf8mb4_bin. This collation compares strings based on the binary representation of each character, which is case-sensitive and accent-sensitive.
  • CREATE USER 'zabbix'@'localhost' – Create a new user named zabbix that can connect from the localhost only.
  • IDENTIFIED BY 'top_secret_password' – Sets the password for the zabbix user.
  • GRANT ALL PRIVILEGES – Grants all available privileges to the zabbix user.
  • SET GLOBAL – This command configured the MySQL server to trust the creation of stored functions and triggers without requiring binary logging of such creations.

Now that the Zabbix database is ready, I imported the schema and initial data. For me it looked like nothing was happening, but after a few seconds the import finished.

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

I then edited the following file.

				
					sudo nano /etc/zabbix/zabbix_server.conf
				
			

I verified the following lines matched the settings I made earlier.

				
					DBName=zabbix
DBUser=zabbix
DBPassword=top_secret_password
				
			

Last, I enabled the Zabbix server to start on boot and start it right away.

				
					sudo systemctl enable zabbix-server
sudo systemctl start zabbix-server
				
			

To verify everything is running properly I ran the following command:

				
					systemctl status zabbix-server
				
			

To finish the setup I went to the following url.

				
					http://10.33.99.100/zabbix
				
			

First page will be the language select.

I went through the list to make sure everything was showing as “OK.”

The “Database name” and “User” were already prefilled, so I just entered the password I created during the install.

I named my server and chose the dark theme.

Summary page.

The install was successfull.

Usernames are case-sensitive.

Once logged in you’ll see this default page.

High Availability Setup

‣ My Setup

HYPERVISOR Proxmox
  • Dell PowerEdge R720
  • Intel Xeon E5-2680 v2 @ 2.80GHz
  • 256GB RAM
  • 7TB Storage
VIRTUAL MACHINES Ubuntu 22.04
  • 4 Cores
  • 8GB RAM
  • 80GB Storage
SERVERS IP Addresses
  • Zabbix-HA1 : 10.33.99.101
  • Zabbix-HA2 : 10.33.99.102
  • Zabbix-DB1 : 10.33.99.103
  • Virtual IP : 10.33.99.105

‣ Installation

For this setup, I used 3 servers. 1 for the database, and 2 for the Zabbix frontend. I also utilized Nginx to setup a virtual IP that will be used by both Zabbix frontend servers.

• ZABBIX-DB1 •

First, I SSH’d into the server I’ll be using as the database.

I then downloaded and installed MariaDB 10.5 (When installing the latest version I was getting compatibility issues, so I installed an older version).

				
					wget https://downloads.mariadb.com/MariaDB/mariadb-10.5
chmod +x mariadb-10.5
sudo ./mariadb-10.5

				
			
  • wget – Downloads the MariaDB repository setup script.
  • chmod +x – Makes the script executable.
  • sudo ./mariadb-10.5 – Installs the repo on the system.

Then I installed MariaDB, and enabled it to start upon boot.

				
					sudo apt install mariadb-server
sudo systemctl enable mariadb
sudo systemctl start mariadb
				
			

Note

MariaDB has a script that helps improve security,

You can run the following command and follow the prompts to better secure it.

				
					sudo mariadb-secure-installation
				
			

Next I logged into MariaDB as root.

				
					mariadb -u root -p
				
			

I then created the database and users for zabbix-ha1, zabbix-ha2, and the virtual IP I’ll be setting up later.

				
					create database zabbix character set utf8mb4 collate utf8mb4_bin;

create user zabbix@'10.33.99.101' identified by 'top_secret_password';
create user zabbix@'10.33.99.102' identified by 'top_secret_password';
create user zabbix@'10.33.99.105' identified by 'top_secret_password';

grant all privileges on zabbix.* to 'zabbix'@'10.33.99.101' identified by 'top_secret_password';
grant all privileges on zabbix.* to 'zabbix'@'10.33.99.102' identified by 'top_secret_password';
grant all privileges on zabbix.* to 'zabbix'@'10.33.99.105' identified by 'top_secret_password';

set global log_bin_trust_function_creators = 1;
quit;
				
			
  • 10.33.99.101 – The IP address of my zabbix-ha1 server.
  • 10.33.99.102 – The IP address of my zabbix-ha2 server.
  • 10.33.99.105 – The virtual IP address I’ll be setting up with Nginx.
  • set global .. – Temporarily allows creation of functions (required when importing the schema).

I then installed the Zabbix repository and SQL Scripts, which are used during the installation and configuration of a Zabbix server.

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

Then ran the import.

				
					zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -u root -p zabbix
				
			
  • zcat – Decompresses the Zabbix SQL schema.
  • | mysql --default ... – Pipes and imports it into the ‘zabbix’ database.

Note

The location of server.sql.gz might defer depending on which flavor of Linux you’re using.

After the imported completed I disabled the log_bin trust.

				
					mysql -u root -p
set global log_bin_trust_function_creators = 0;
quit;
				
			

• ZABBIX-HA1 •

Zabbix server will be installed on both Zabbix-HA1 and Zabbix-HA2.

First, I downloaded and added the Zabbix 7.0 repository.

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

				
			

Then I installed the server package along with MySQL database support.

				
					sudo apt install zabbix-server-mysql
				
			

Next, I needed to make some changes to the .conf file.

				
					sudo nano /etc/zabbix/zabbix_server.conf
				
			

I found the following lines and filled them out accordingly.

				
					DBHost=10.33.99.103
DBUser=zabbix
DBPassword=password
				
			
  • DBHost – I put the IP address of the zabbix-db1 server.
  • DBUser – I left it as ‘zabbix’.
  • DBPassword – I changed this to the password I setup earlier.

I scrolled to the very bottom of the file and uncommented the following lines.

				
					HANodeName=zabbix-ha1
NodeAddress=10.33.99.101
				
			
  • HANodeName – I put the name of the server (It doesn’t have to be the name of the server but I like to keep consistency).
  • NodeAddress – The IP address of this server (zabbix-ha1).

Then saved and exited.

				
					CTRL + X
'Enter'
Y
				
			

• ZABBIX-HA2 •

Now to do the same on Zabbix-HA2 with some minor changes.

Once again I downloaded and added the Zabbix 7.0 repository.

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

Then I installed the server package along with MySQL database support.

				
					sudo apt install zabbix-server-mysql
				
			

Next, I needed to make some changes to the .conf file.

				
					sudo nano /etc/zabbix/zabbix_server.conf
				
			

I found the following lines and filled them out accordingly.

				
					DBHost=10.33.99.103
DBUser=zabbix
DBPassword=password
				
			
  • DBHost – I put the IP address of the zabbix-db1 server.
  • DBUser – I left it as ‘zabbix’.
  • DBPassword – I changed this to the password I setup earlier.

Here’s where the minor differences are. I scrolled to the very bottom of the file and filled these lines as follows.

				
					HANodeName=zabbix-ha1
NodeAddress=10.33.99.102
				
			
  • HANodeName – I put the name of the server (It doesn’t have to be the name of the server but I like to keep consistency).
  • NodeAddress – The IP address of this server (zabbix-ha2).

Then I enabled Zabbix to start on boot and to started the service on both ha1 and ha1.

				
					sudo systemctl enable zabbix-server
sudo systemctl start zabbix-server
				
			

• NGINX •

This will be setup on both ha1 and ha2 servers, again with some minor differences on each.

First, I installed ‘keepalived’ on both servers.

				
					sudo apt install keepalived
				
			

On zabbix-ha1 I configured the conf. file as the master.

				
					vrrp_track_process chk_nginx {
  process nginx
  weight 10
}

vrrp_instance ZBX_1 {
  state MASTER
  interface ens18
  virtual_router_id 51
  priority 244
  advert_int 1
  authentication {
    auth_type PASS
    auth_pass top_secret_password
  }
  track_process {
    chk_nginx
  }
  virtual_ipaddress {
    10.33.99.105/24
  }
}
				
			
  • state – I changed this to MASTER. This node start with higher priority.
  • interface – I changed this to the name of the server’s interface name.
  • priority – I changed this to 244.
  • auth_pass – I entered a secure password.
  • virtual_ipaddress – The IP address I’m going to use to access Zabbix.

On zabbix-ha2 there’s a few differences.

				
					vrrp_track_process chk_nginx {
  process nginx
  weight 10
}

vrrp_instance ZBX_1 {
  state MASTER
  interface ens18
  virtual_router_id 51
  priority 244
  advert_int 1
  authentication {
    auth_type PASS
    auth_pass top_secret_password
  }
  track_process {
    chk_nginx
  }
  virtual_ipaddress {
    10.33.99.105/24
  }
}
				
			
  • state – I changed this to BACKUP. This node start with lower priority.
  • interface – I changed this to the name of the server’s interface name.
  • priority – I changed this to 243.
  • auth_pass – I entered a secure password.
  • virtual_ipaddress – The IP address I’m going to use to access Zabbix.

On both servers I installed the Zabbix frontend.

				
					sudo apt install nginx zabbix-frontend-php zabbix-nginx-conf
				
			
  • nginx – Installs the Nginx web server, which will server the Zabbix frontend.
  • zabbix-frontend-conf – Installs the PHP frontend for Zabbix.
  • zabbix-nginx-conf – Installs the configuration files needed to set up Zabbix with Nginx.

I then edited the following .conf file on both servers.

				
					sudo nano /etc/zabbix/nginx.conf
				
			

I then uncommented the following lines and changed the port and server name (this will be the same on both ha1 and ha2).

				
					# listen 8080;
# server_name example.com;

listen 80;
server_name 10.33.0.105;
				
			

Then finally enabled Nginx and keepalived to start on boot, and started the services.

				
					sudo systemctl enable nginx keepalived
sudo systemctl start nginx keepalived
				
			

• FRONTEND •

To setup the front end, I’ll have to go through the initial Zabbix configuration twice. The first will be on ha1, then stopping Nginx on ha1, and repeating it for ha2. But, I’ll be doing it from the virtual IP I setup, and not the server’s individual IP addresses.

First, I went to the virtual IP address I configured.

				
					http://10.33.99.105/
				
			

First page will be the language select.

I verified everything was ‘OK’.

Then I configured the database connection.

  • Database host – I inputed the IP address of zabbix-db1.
  • Password – The password I setup for the database in MariaDB.
  • Database TLS encryption – I unchecked this.

Then I named it after zabbix-ha1.

Summary page.

Then clicked ‘Finish’.

I then stopped Nginx on zabbix-ha1.

				
					sudo systemctl stop nginx
				
			

Then went back to the virtual IP address.

				
					http://10.33.99.105/
				
			

And did everything the same as earlier.

Then only difference is that I made sure to name it after zabbix-ha2.

Then I went back to zabbix-ha1 and started Nginx.

				
					sudo systemctl start nginx
				
			

What's Next

In the upcoming posts I’ll show how I setup SAML authentication using Microsoft Azure, proxies, SMTP alerts, Microsoft Teams alerts, using SNMPwalk to get MIBs for configuring custom items, and more.

×

Table of Contents