Tuesday, April 29, 2025

Install Zabbix with PostgreSQL Database on RHEL 9 | CentOS 9: A Comprehensive Guide

 

Introduction

Zabbix is one of the most popular open-source monitoring tools available, providing comprehensive real-time monitoring of systems, networks, and applications. When coupled with a PostgreSQL database, Zabbix becomes a powerful solution that can handle large-scale monitoring with excellent performance. In this guide, we’ll walk through the installation of Zabbix with PostgreSQL as the backend on RHEL 9 and CentOS 9.

Prerequisites

Before we begin, ensure you have the following in place:

RequirementDescription
Operating SystemA server running RHEL 9 or CentOS 9
PrivilegesRoot or sudo privileges
NetworkA stable internet connection (IPv4 address and Hostname for this demonstration: 192.168.1.212zabbix.dev.naijalabs.net)
Install Zabbix with PostgreSQL on RHEL 9

Photo by admingeek from Infotechys

Install Zabbix with PostgreSQL Database on RHEL 9 | CentOS 9:

To start, ensure that your server is up to date by running:

sudo dnf update -y

Step 1: Install PostgreSQL

The first step is to install PostgreSQL, which will be the database server for Zabbix.

Install PostgreSQL

sudo dnf install -y postgresql-server postgresql-contrib

Initialize the Database

sudo postgresql-setup --initdb

Start and Enable PostgreSQL

sudo systemctl enable --now postgresql.service

After starting PostgreSQL, secure it by setting a password for the PostgreSQL user:

sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'your_password';"

Step 2: Add Zabbix Repository

To install Zabbix, we need to add its official repository to your system.

Add Zabbix Repository

sudo rpm -Uvh https://repo.zabbix.com/zabbix/7.0/rhel/9/x86_64/zabbix-release-latest.el9.noarch.rpm

This repository contains the necessary packages to install Zabbix and its dependencies. Run this command to update your system’s repository:

sudo dnf clean all

Step 3: Install Zabbix Server

With the repository added, we can now install the Zabbix server, frontend, and agent.

sudo dnf install -y zabbix-server-pgsql zabbix-web-pgsql zabbix-web zabbix-web-deps zabbix-sql-scripts zabbix-selinux-policy zabbix-apache-conf zabbix-agent

These packages install the Zabbix server (which will use PostgreSQL as its database), the web interface, and the Zabbix agent.

Step 4: Configure PostgreSQL for Zabbix

Next, we need to set up PostgreSQL to work with Zabbix. This involves creating a database and user for Zabbix.

Create Zabbix Database and User

Create a Zabbix user with a password:

sudo -u postgres createuser --pwprompt zabbix

Create the Zabbix database:

sudo -u postgres createdb -O zabbix zabbix

Grant the user necessary privileges:

sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE zabbix TO zabbix;"

Exit the PostgreSQL shell:

\q

Step 5: Configure Zabbix Server

Now that we’ve set up the PostgreSQL database, the next step is to configure the Zabbix server to connect to it.

Import the Zabbix Schema

sudo zcat /usr/share/zabbix-sql-scripts/postgresql/server.sql.gz | sudo -u zabbix psql zabbix

Edit Zabbix Configuration File

Open the Zabbix server configuration file for editing:

sudo vim /etc/zabbix/zabbix_server.conf

Make the following changes:

DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=your_actual_password
NodeAddress=localhost:10051

These lines configure the Zabbix server to connect to the PostgreSQL database using the user and password you created earlier.

Step 6: Install and Configure Zabbix Frontend

The Zabbix frontend is a web-based interface that allows you to manage and monitor your environment.

Install Apache and PHP

sudo dnf install -y httpd php php-pgsql

Start and Enable Apache

sudo systemctl enable --now httpd

Configure PHP for Zabbix

Zabbix requires specific PHP settings. Edit the PHP configuration file used by Zabbix:

sudo vim /etc/php-fpm.d/zabbix.conf

Set the timezone and other necessary values (e.g. America/New_York) :

php_value[date.timezone] = Your/Timezone

Restart PHP-FPM to apply the changes:

sudo systemctl restart php-fpm

Step 7: Start Zabbix Services

Now that everything is set up, we can start the Zabbix services.

Start and Enable Zabbix Server and Agent

sudo systemctl enable --now zabbix-server zabbix-agent httpd php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-server.service → /usr/lib/systemd/system/zabbix-server.service.
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-agent.service → /usr/lib/systemd/system/zabbix-agent.service.
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.

Restart Apache to ensure everything is running smoothly:

sudo systemctl restart httpd

We also want to account for the firewall and ensure the necessary ports are open to allow traffic:

sudo firewall-cmd --permanent --add-port=10051/tcp
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload

If SELinux is enabled (it should be btw), enter the following command to allow the Zabbix frontend to connect to the server:

sudo setsebool -P httpd_can_network_connect on

Step 8: Access the Zabbix Frontend

To access the Zabbix frontend, open a web browser and go to your server’s IP address followed by /zabbix. For example (http://your_server_ip/zabbix):

Install Zabbix with PostgreSQL on RHEL 9

No comments:

Post a Comment

HTTP Appache Server LAB 7

 Apache HTTP Server (httpd) Configuration,