Zabbix Database

Ricardo Martin | Apr 5, 2024 min read

Why a standalone database?

Setting up a standalone database in a cluster setup makes a lot of sense for a few reasons. Firstly, it keeps things simple by keeping the database separate from the rest of the cluster. This means less chance of things getting tangled up or going wrong. Plus, it’s easier to expand because you can focus resources just on the database without messing with other components of the cluster. Also, having the database all to itself boosts performance since it doesn’t have to share resources with other services. So yeah, having a standalone database in your cluster setup is a smart move for smoother operations, easier growth, and better performance overall.

Server Setup

As I mentioned on my previous post, I’ll be using PostgreSQL as the main database, and Ubuntu 24.04 as the base operating system.

This guide assumes that you are capable of deploying a ubuntu server on your own. If not, please follow this guide before proceeding.

1. Create a new user on the server

Although not mandatory, it is recommended that you create a dedicated user to access the database. We’ll create a user named zabbix. The command is very simple:

sudo adduser zabbix

2. Install PostgreSQL on the server

After creating the new user, we need to install the database.

sudo apt install -y postgresql postgresql-contrib

3. Configure the database

Now that we have PostrgreSQL installed, we need configure the database.

Create a new database

We’ll create a database named zabbix

sudo -u postgres createdb -O zabbix zabbix 

Create new users

We’ll be creating a few users on the database:

  1. zabbix: This user will be used to connect the zabbix servers to the database
  2. zabbixweb: This user will be used to connect the zabbix frontend to the database

In cluster mode, the frontend connects to the database to check the availability of each server in the cluster.

Run the command below to create the user zabbix

sudo -u postgres createuser --pwprompt zabbix

Run the command below to create the user zabbixweb

sudo -u postgres createuser --pwprompt zabbixweb

Grant permissions

Now that we have created the users, we need to grant access to the database.

1. Connect to the database with the user postgres
sudo -u postgres psql zabbix
2. Allow users to connect to the database
GRANT CONNECT ON DATABASE zabbix TO zabbix;
GRANT CONNECT ON DATABASE zabbix TO zabbixweb;
3. Grant read access to the database
GRANT pg_read_all_data TO zabbix;
GRANT pg_read_all_data TO zabbixweb;
4. Grant write access to the database
GRANT pg_write_all_data TO zabbix;
GRANT pg_write_all_data TO zabbixweb;

4. Make the database available on LAN

In order to make the database available for other devices on the LAN, we need to modify the PostgreSQL config file. To find the location of your config file run the command below:

sudo -u postgres psql -c "SHOW config_file;" 

The output will look like the image below

postgresconfig

In my case the config file is located at /etc/postgresql/16/main/postgresql.conf. Use the text editor of your choice and open the config file.

sudo vim /etc/postgresql/16/main/postgresql.conf

Search for listen_addresses and add listen_addresses = ‘*’ to the config file.

#listen_addresses = 'localhost'
listen_addresses = '*'

In the same directory as the postgresql.conf file, you’ll find the pg_hba.conf file. Open that file and include the lines below

# TYPE  DATABASE	USER	ADDRESS   	METHOD
host    all     	all     0.0.0.0/0    md5
host    all         all     ::/0         md5

To apply the configuration, reload the server

sudo service postgresql reload

Make sure your server has a static IP address. Below is the /etc/netplan/*.yaml config I’m using

  • 10.0.0.20: Zabbixdb address
  • 10.0.0.1: Gateway
  • 10.0.0.200: Internal DNS server
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      addresses:
        - 10.0.0.20/24
      routes:
        - to: default
          via: 10.0.0.1
      nameservers:
        addresses: [10.0.0.200]
        search: [ns01.rcfmartin.com]

Next Steps

On the next post of this series, I will be covering the zabbix server setup. We’ll be using Ubuntu 24.04 as the base operating system.

I’ll see you on the next one!