repmgr + pg12 to build a highly available cluster (1)

1 Overview

Repmgr is a set of open source streaming replication cluster management tools in the second quadrant. Take a look at the official introduction:

repmgr is an open source tool suite for managing replication and failover in a cluster of PostgreSQL servers. It enhances PostgreSQL's built-in hot standby function by setting up standby servers, tools for monitoring replication, and performing management tasks (such as failover or manual switching operations).

Features of repmgrde:

Distributed management cluster nodes, easy to expand, can add and delete cluster nodes online;

The structure is as follows:

 

 2. Deployment

Master node:

  1. Configure related parameters
  2. Start the database
  3. Use the "repmgr primary register" command to register the primary node. (The purpose of this registration is to write some main parameters of the configuration file to the metadata table, so that the repmgr system can identify the cluster nodes, etc.)
  4. Start the repmgrd daemon.

Standby node:

  1. Configure related parameters
  2. Use the "repmgr standby clone" command to physically copy the master node.
  3. Start the database
  4. Use the "repmgr standby register" command to register the standby node.
  5. Start the repmgrd daemon.

After each node in the cluster is successfully deployed, the repmgrd daemon is started, which can handle failover and record monitoring data;

3. Actual operation

Operating environment:

centos7.6

3.1. Install pg12 (see previous post)

3.2. Obtain the repmgr installation package

https://yum.postgresql.org/12/redhat/rhel-7-x86_64/repoview/

 

 

 3.3. Install remggr

rpm -ivh repmgr12-5.1.0-1.rhel7.x86_64.rpm

3.4.repmgr parameter configuration

vim / etc / repmgr / 12 / repmgr.conf 
## Fill in the required configuration items 
node_id = 1 
node_name = node1 
conninfo = ' host = 192.168.101.9 port = 5432 user = postgres dbname = postgres ' 
data_directory = ' / var / lib / pgsql / 12 / data '

3.5. Database parameter configuration

vim / var / lib / pgsql / 12 / data / postgresql.conf #Configuration 
parameter 
shared_preload_libraries = ' repmgr ' 
listen_addresses = '*'

vim /var/lib/pgsql/12/data/pg_hba.conf #Configuration
parameters

  # IPv4 local connections:
  host all all 0.0.0.0/0 trust  #新增

3.6. Connect to the database to create a plug-in after restarting the database (./psql -Upostgres -dpostgres)

CREATE EXTENSION repmgr;

3.7. Register the main database

[postgres@localhost bin]$ ./repmgr primary register
INFO: connecting to primary database...
INFO: "repmgr" extension is already installed
NOTICE: primary node record (ID: 1) registered

3.8. Cluster status view

[postgres@localhost bin]$ ./repmgr cluster show
 ID | Name  | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string
----+-------+---------+-----------+----------+----------+----------+----------+-------------------------------------------------------------
 1  | node1 | primary | * running |          | default  | 100      | 1        | host=192.168.101.9 port=5432 user=postgres  dbname=postgres

The registration standby database is recorded in the next section. .

Guess you like

Origin www.cnblogs.com/mingfan/p/12741231.html