Instalación Zabbix 4.4 + PostgreSQL + TimescaleDB en CentOS 8

From Zabbix-ES
Jump to navigation Jump to search

Update systemc after install

$ dnf check-update
$ dnf -y update

Stop and disable FirewallD

$ systemctl stop firewalld
$ systemctl disable firewalld

Configure SELinux

Nota: SELINUX=disabled in the /etc/selinux/config file
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - No SELinux policy is loaded.
# SELINUXTYPE= can take one of these two values:
#       targeted - Targeted processes are protected,
#       mls - Multi Level Security protection.
Nota: Reboot your system. After reboot, confirm that the getenforce command returns Disabled

Install and update Webmin via RPM

Nota: Create the /etc/yum.repos.d/webmin.repo file containing:	(Optional)
name=Webmin Distribution Neutral

You should also fetch and install my GPG key with which the packages are signed, with the commands

$ dnf -y install wget
$ cd /tmp
$ wget
$ rpm --import jcameron-key.asc

You will now be able to install with the command

$ dnf -y install webmin

All dependencies should be resolved automatically

# To modify my listen port:
$ dnf -y install perl-Socket6

To use the PostgreSQL Yum Repository, follow these steps

Nota: Disable the AppStream modules You will probably never want to use if You use pgdg build (dnf -y module disable postgresql).
$ dnf -y module disable postgresql

Instalacion de PostgreSQL

Install the repository RPM

$ dnf install

Install the client packages

$ dnf install postgresql11

Optionally install the server packages

$ dnf install postgresql11-server

Optionally initialize the database and enable automatic start

 $ /usr/pgsql-11/bin/postgresql-11-setup initdb
 $ systemctl enable postgresql-11
 $ systemctl start postgresql-11

Modify pg_hba.conf in /var/lib/pgsql/11/data/, ident by md5

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer

# IPv4 local connections:
host    all             all               ident --> md5

# IPv6 local connections:
host    all             all             ::1/128                 ident --> md5

# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all               ident --> md5
host    replication     all             ::1/128                 ident --> md5

Install Zabbix repository

$ rpm -Uvh
$ dnf clean all

Install Zabbix server, frontend, agent

$ dnf -y install zabbix-server-pgsql zabbix-web-pgsql zabbix-apache-conf zabbix-agent

Create initial database

$ sudo -u postgres createuser --pwprompt zabbix
$ sudo -u postgres createdb -O zabbix zabbix

Import initial schema and data. You will be prompted to enter your newly created password

$ zcat /usr/share/doc/zabbix-server-pgsql*/create.sql.gz | sudo -u zabbix psql zabbix

Configure the database for Zabbix server

# Edit file /etc/zabbix/zabbix_server.conf

Configure PHP for Zabbix frontend

#	Edit file /etc/php-fpm.d/zabbix.conf, uncomment and set the right timezone for you.
php_value[date.timezone] = America/Argentina/Buenos_Aires

Start Zabbix server and agent processes and make it start at system boot

$ systemctl restart zabbix-server zabbix-agent httpd php-fpm
$ systemctl enable zabbix-server zabbix-agent httpd php-fpm

Connect to your newly installed Zabbix frontend

Nota: http://server_ip_or_name/zabbix

Install TimescaleDB extension and Configure

Nota:  Add TimescaleDB's third party repository and install TimescaleDB, which will download any dependencies it needs from the PostgreSQL repo.
$ tee /etc/yum.repos.d/timescale_timescaledb.repo <<EOL
$ dnf -y update
$ dnf -y install timescaledb-postgresql-11

The easiest way to get started is to run timescaledb-tune

$ timescaledb-tune --pg-config=/usr/pgsql-11/bin/pg_config

These changes are then written to your postgresql.conf and will take effect on the next (re)start

$ systemctl restart postgresql-11

TimescaleDB extension must also be enabled for the specific DB by executing

$ echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | sudo -u postgres psql zabbix
could not change directory to "/root": Permission denied
 _____ _                               _     ____________
|_   _(_)                             | |    |  _  \ ___ \
  | |  _ _ __ ___   ___  ___  ___ __ _| | ___| | | | |_/ /
  | | | |  _ ` _ \ / _ \/ __|/ __/ _` | |/ _ \ | | | ___ \
  | | | | | | | | |  __/\__ \ (_| (_| | |  __/ |/ /| |_/ /
  |_| |_|_| |_| |_|\___||___/\___\__,_|_|\___|___/ \____/
               Running version 1.4.2
For more information on TimescaleDB, please visit the following links:

 1. Getting started:
 2. API reference documentation:
 3. How TimescaleDB is designed:

Note: TimescaleDB collects anonymous reports to better understand and assist our users.
For more information and how to disable, please see our docs

Then run the timescaledb.sql script located in database/postgresql

Nota: Si la BD es grande, es recomendable ejecutar el particionado desde una sesion con el comando screen par poder dejarla en BG ya que puede tardar mucho tiempo.
# zcat /usr/share/doc/zabbix-server-pgsql-5.0.0/timescaledb.sql.gz | sudo -u zabbix psql zabbix


# zcat /usr/share/doc/zabbix-server-pgsql-5.0.0/timescaledb.sql.gz

SELECT create_hypertable('history', 'clock', chunk_time_interval => 86400, migrate_data => true);
SELECT create_hypertable('history_uint', 'clock', chunk_time_interval => 86400, migrate_data => true);
SELECT create_hypertable('history_log', 'clock', chunk_time_interval => 86400, migrate_data => true);
SELECT create_hypertable('history_text', 'clock', chunk_time_interval => 86400, migrate_data => true);
SELECT create_hypertable('history_str', 'clock', chunk_time_interval => 86400, migrate_data => true);
SELECT create_hypertable('trends', 'clock', chunk_time_interval => 86400, migrate_data => true);
SELECT create_hypertable('trends_uint', 'clock', chunk_time_interval => 86400, migrate_data => true);
UPDATE config SET db_extension='timescaledb',hk_history_global=1,hk_trends_global=1;
UPDATE config SET compression_status=1,compress_older='7d';