Nos disponemos a preparar un entorno sobre el que realizar pruebas con repmgr 13 (versión 5.2) y postgresql versión 13.

En nuestro caso se tratará de un OEL 8.3 (con kernel de redhat).

Una vez creada la primera máquina virtual procedemos a la instalación de los repositorios y desactivar el módulo por defecto:

[root@postgres1 ~]# curl https://dl.2ndquadrant.com/default/release/get/13/rpm | sudo bash

[root@postgres1 ~]# dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

[root@postgres1 ~]# dnf -qy module disable postgresql

 

Instalamos los productos:

[root@postgres1 ~]# dnf install postgresql13-server -y

[root@postgres1 ~]# dnf install repmgr13 -y

 

Modificamos el fichero /etc/sudoers para que nos deje utilizar los servicios de ambos productos desde el usuario postgres:

## Allow root to run any commands anywhere
root ALL=(ALL) ALL
postgres ALL= NOPASSWD: /bin/systemctl stop postgresql-13, \
/bin/systemctl start postgresql-13, \
/bin/systemctl status postgresql-13, \
/bin/systemctl restart postgresql-13, \
/bin/systemctl reload postgresql-13, \
/bin/systemctl start repmgr13, \
/bin/systemctl status repmgr13, \
/bin/systemctl restart repmgr13, \
/bin/systemctl reload repmgr13, \
/bin/systemctl stop repmgr13

 

Inicializamos postgresql:

[root@postgres1 ~]# /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database ... OK
[root@postgres1 ~]# systemctl enable postgresql-13
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-13.service → /usr/lib/systemd/system/postgresql-13.service.
[root@postgres1 ~]# systemctl start postgresql-13

 

Creamos la base de datos para repmgr:

[postgres@postgres1 ~]$ psql -c 'CREATE USER repmgr WITH REPLICATION SUPERUSER LOGIN';
CREATE ROLE
[postgres@postgres1 ~]$ psql -c 'CREATE DATABASE repmgr OWNER repmgr';
CREATE DATABASE
[postgres@postgres1 ~]$ psql -c 'ALTER USER repmgr SET search_path TO repmgr, "$user", public';
ALTER ROLE

 

Añadimos al fichero pg_hba.conf las siguientes entradas (notar que la ip 104 es para otro entorno que servirá para otras pruebas más adelante -pgbouncer y witness-):

host repmgr repmgr 192.168.0.101/32 trust
host repmgr repmgr 192.168.0.102/32 trust
host repmgr repmgr 192.168.0.103/32 trust
host repmgr repmgr 192.168.0.104/32 trust
host replication repmgr 192.168.0.101/32 trust
host replication repmgr 192.168.0.102/32 trust
host replication repmgr 192.168.0.103/32 trust
host replication repmgr 192.168.0.104/32 trust

 

Añadimos al fichero postgresql.conf las siguientes entradas (notar que el parámetro wal_log_hints es para poder hacer pg_rewind):

listen_addresses = '*'
port=5432

hot_standby = on
wal_level = replica
archive_mode = on
archive_command = '/bin/true'
max_wal_senders = 10
max_replication_slots = 10
wal_log_hints = on

 

Añadimos al fichero /etc/repmgr/13/repmgr.conf las siguientes entradas:

node_id=1
node_name=postgres1
conninfo='host=192.168.0.101 user=repmgr dbname=repmgr'
data_directory='/var/lib/pgsql/13/data'
pg_bindir='/usr/pgsql-13/bin'
log_file='/var/lib/pgsql/13/repmgr.log'
use_replication_slots=true
service_start_command='sudo /bin/systemctl start postgresql-13'
service_stop_command='sudo /bin/systemctl stop postgresql-13'
service_restart_command='sudo /bin/systemctl restart postgresql-13'
service_reload_command='/usr/pgsql-13/bin/pg_ctl -D /var/lib/pgsql/13/data reload'
service_promote_command='/usr/pgsql-13/bin/pg_ctl -D /var/lib/pgsql/13/data promote'
promote_command='/usr/pgsql-13/bin/repmgr standby promote -f /etc/repmgr/13/repmgr.conf --log-to-file'
follow_command='/usr/pgsql-13/bin/repmgr standby follow -f /etc/repmgr/13/repmgr.conf --log-to-file --upstream-node-id=%n'
ssh_options='-q -o ConnectTimeout=10'

 

Chequemos los comandos:

[postgres@postgres1 ~]$ repmgr node service --list-actions --action=start
sudo /bin/systemctl start postgresql-13
[postgres@postgres1 ~]$ repmgr node service --list-actions --action=stop
sudo /bin/systemctl stop postgresql-13
[postgres@postgres1 ~]$ repmgr node service --list-actions --action=reload
/usr/pgsql-13/bin/pg_ctl -D /var/lib/pgsql/13/data reload
[postgres@postgres1 ~]$ repmgr node service --list-actions --action=restart
sudo /bin/systemctl restart postgresql-13
[postgres@postgres1 ~]$ repmgr node service --list-actions --action=promote
/usr/pgsql-13/bin/pg_ctl -D /var/lib/pgsql/13/data promote

 

Añadimos el servicio al firewall:

[root@postgres1 ~]# firewall-cmd --zone=public --permanent --add-service=postgresql
success
[root@postgres1 ~]# firewall-cmd --reload
success

 

Cambiamos la password al usuario postgres:

[root@postgres1 ~]# passwd postgres
Changing password for user postgres.
New password:
BAD PASSWORD: The password contains the user name in some form
Retype new password:
passwd: all authentication tokens updated successfully.

 

Clonamos esta máquina para hacer el resto de máquinas (postgres2 y postgres3).

Ojo!! porque el resto de máquinas tienen que tener el PG_DATA vacío.

Una vez clonadas y cambiadas sus hostnames e ips, configuramos el ssh sin password (entre todas):

[postgres@postgres1 ~]$ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/pgsql/.ssh/id_rsa):
Created directory '/var/lib/pgsql/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/lib/pgsql/.ssh/id_rsa.
Your public key has been saved in /var/lib/pgsql/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:eaAi7BRAmGHeiL39FqBiQMy5C9m00FLHSZYaCDhrsJQ postgres@nodo1
The key's randomart image is:
+---[RSA 4096]----+
|@X+o+o |
|#E*o+ |
|=%+=. . |
|*++= . . o |
|+.B o o S . |
|.= . o . . |
| . o |
| . |
| |
+----[SHA256]-----+

[postgres@postgres1 ~]$ ssh-copy-id postgres@192.168.0.101
[postgres@postgres1 ~]$ ssh-copy-id postgres@192.168.0.102
[postgres@postgres1 ~]$ ssh-copy-id postgres@192.168.0.103

 

Ir a parte 2