0% found this document useful (0 votes)
85 views

Install PostgreSQL 10 With Repmgr On CentOS 7

This document provides instructions for installing PostgreSQL 10 with replication using Repmgr on two CentOS 7 servers, one configured as the master and the other as the slave. It describes the prerequisites and steps to configure firewall, PostgreSQL, and Repmgr on the master server. It then explains how to clone the master's data and configuration to the slave server and configure it as the standby. It also covers setting up public key authentication between the servers to allow passwordless SSH access between the nodes.

Uploaded by

Aymen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

Install PostgreSQL 10 With Repmgr On CentOS 7

This document provides instructions for installing PostgreSQL 10 with replication using Repmgr on two CentOS 7 servers, one configured as the master and the other as the slave. It describes the prerequisites and steps to configure firewall, PostgreSQL, and Repmgr on the master server. It then explains how to clone the master's data and configuration to the slave server and configure it as the standby. It also covers setting up public key authentication between the servers to allow passwordless SSH access between the nodes.

Uploaded by

Aymen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

furkanonder / PostgreSQL10-Repmgr-CentOS7.

md
Created 4 years ago • Report abuse

Star

Code Revisions 1 Stars 1 Forks 3

Install PostgreSQL 10 with Repmgr on CentOS 7

PostgreSQL10-Repmgr-CentOS7.md

Prerequisites
2 CentOS 7 servers (One will act as master and the other one as slave)
postgresql-10,repmgr10
Public key authentication

FireWalld Configuration (Master Server And Slave


Server)

systemctl start firewalld


systemctl enable firewalld
firewall-cmd --add-service=postgresql --permanent
firewall-cmd --reload
firewall-cmd --list-all

Master Server Configuration

Installation

yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-


7-x86_64/pgdg-centos10-10-2.noarch.rpm
yum install postgresql10-server postgresql10-contrib repmgr10
/usr/pgsql-10/bin/postgresql-10-setup initdb

Configure repmgr by editing /etc/repmgr


/10/repmgr.conf
node_id=1
node_name=node1
conninfo='host=<master server ip> user=repmgr dbname=repmgr'
data_directory=/var/lib/pgsql/10/data/

Configure PostgreSQL itself and streaming replication


by editing /var/lib/pgsql/10/data/postgresql.conf
change listener_address to master server ip

listen_addresses = '*'

Set the value to 2 (since we have two servers, one master and one slave).

max_wal_senders = 2

wal_level determines how much information is written to the WAL. The default value
is minimal, which writes only the information needed to recover from a crash or
immediate shutdown. archive adds logging required for WAL archiving, and
hot_standby further adds information required to run read-only queries on a standby
server. This parameter can only be set at server start.

wal_level = hot_standby

hot_standby = on

Archive settings

archive_mode = on
archive_command = 'cp %p /var/lib/pgsql/10/archive/%f'

Specifies the minimum number of past log file segments kept in the pg_xlog
directory, in case a standby server needs to fetch them for streaming replication.

wal_keep_segments = 10

/var/lib/pgsql/10/data/pg_hba.conf
pg_hba.conf is client authentication is controlled by a configuration file.

local replication repmgr trust


host replication repmgr 127.0.0.1/32 trust
host replication repmgr <master server ip/subnet> trust

local repmgr repmgr trust


host repmgr repmgr 127.0.0.1/32 trust
host repmgr repmgr <slave server ip/subnet> trust

Start PostgreSQL

systemctl start postgresql-10

Create the required users for replication and repmgr and the repmgr DB.

passwd postgres
sudo su - postgres
psql
CREATE USER repmgr SUPERUSER LOGIN ENCRYPTED PASSWORD 'secret';
CREATE DATABASE repmgr OWNER repmgr;
\q
exit

Save this file and restart postgres.

systemctl restart postgresql-10

Register master node for repmgr.

sudo su - postgres
/usr/pgsql-10/bin/repmgr -f /etc/repmgr/10/repmgr.conf master register
exit

Slave Server Configuration

Installation
yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-
7-x86_64/pgdg-centos10-10-2.noarch.rpm
yum install postgresql10-server postgresql10-contrib repmgr10

Sync the configuration and contents of the master with the slave.

sudo su - postgres
/usr/pgsql-10/bin/repmgr -D /var/lib/pgsql/10/data -d repmgr -p 5432 -U
repmgr -R postgres standby clone <master server ip>
exit

Configure repmgr by editing /etc/repmgr


/10/repmgr.conf

node_id=2
node_name=node2
conninfo='host=<slave server ip> user=repmgr dbname=repmgr'
data_directory=/var/lib/pgsql/10/data

Enable and Start PostgreSQL

systemctl start postgresql-10


systemctl enable postgresql-10

Register the slave in repmgr

passwd postgres
sudo su - postgres
/usr/pgsql-10/bin/repmgr -f /etc/repmgr/10/repmgr.conf standby register
--force
exit

Public key authentication

Master Server
Nodes can connect to each other over SSH without a password prompt with users
root and postgres.
Let's create a key pair.Press Enter to all sections.

ssh-keygen

Copying your Public Key using ssh-copy-id

ssh-copy-id postgres@master_server_ip

Slave Server
Nodes can connect to each other over SSH without a password prompt with users
root and postgres.

Let's create a key pair.Press Enter to all sections.

ssh-keygen

Copying your Public Key using ssh-copy-id

ssh-copy-id root@slave_server_ip

TEST

On the Master or Slave Server

sudo su - postgres -c " /usr/pgsql-10/bin/repmgr -f /etc/repmgr


/10/repmgr.conf cluster show"

You might also like