repmgr+pg12構建高可用集群(2)


為了使repmgr正常運行,需要對postgresql.conf進行配置

 

#  監聽所有網段,默認為 localhost ,只監聽本地的連接
listen_addresses = '*'
#  數據庫監聽端口設置為 5432
port = 5432
#  最大的流復制連接數,一般為備數據庫連接數量,同時 pg_basebackup 需要通過流復制連接進行備份
max_wal_senders = 32
#  最多使用的復制槽數量
max_replication_slots = 32
#  最少保留的 WAL 日志數量
wal_keep_segments = 512
# WAL 日志級別,級別越高記錄的日志越多,數據庫至少配置為 replica,PostgreSQL 9.5和更早版本為hot_standby或者logical
wal_level = 'replica''logical'
#  開啟熱備模式,備數據庫接受讀連接
hot_standby = on
#  備數據庫查詢事務反饋給主數據庫,防止因為數據變化導致查詢中斷,repmgr需要能夠連接到它管理的每台服務器。
hot_standby_feedback = on
#  開啟歸檔
archive_mode = on
#  歸檔命令,將 WAL 日志拷貝到歸檔目錄 xxxx/archive 下
archive_command = 'test ! -f xxxx/archive/%f && cp %p xxxx/archive/%f'
#  數據頁變動時,將整個數據頁寫入 WAL 日志,執行 sys_rewind 時需要
full_page_writes = on
#  執行 sys_rewind 時需要
wal_log_hints = on
#  開啟數據庫日志收集
logging_collector = on
#  日志格式為 csv 格式
log_destination = 'csvlog'
#  日志文件存儲路徑為數據目錄下的 log 目錄
log_directory = 'log'
#  預加載 lib 庫文件,需要將 repmgr 庫寫入此變量,可以寫多個庫文件,以 ',' 進行分隔
shared_preload_libraries = 'repmgr'

 

舉例

1、數據庫配置

listen_addresses = '*'
port = 5432
max_wal_senders = 32
max_replication_slots = 32
wal_keep_segments = 512
wal_level = 'replica'
hot_standby = on
hot_standby_feedback = on
archive_mode = on
archive_command = 'test ! -f /var/lib/pgsql/12/archive/%f && cp %p /var/lib/pgsql/12/archive/%f'
full_page_writes = on
wal_log_hints = on
logging_collector = on
log_destination = 'csvlog'
log_directory = 'log'
shared_preload_libraries = 'repmgr'

----------------

  pg_hba.conf

host    replication     all             0.0.0.0/0                 trus

2、主機repmgr.conf

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、查詢主機狀態

[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

4、備機repmgr.conf

node_id=2                      
node_name='node2'                                                        
conninfo='host=192.168.101.7 port=5432 user=postgres  dbname=postgres'                                               
data_directory='/home/postgres/pgsql/12/data''

5、克隆備機,調用的pg_basebackup進行備機創建

[postgres@localhost bin]$ ./repmgr standby clone -h 192.168.101.9 -Upostgres
NOTICE: destination directory "/home/postgres/pgsql/12/data" provided
INFO: connecting to source node
DETAIL: connection string is: host=192.168.101.9 user=postgres
DETAIL: current installation size is 24 MB
NOTICE: checking for available walsenders on the source node (2 required)
NOTICE: checking replication connections can be made to the source server (2 required)
INFO: creating directory "/home/postgres/pgsql/12/data"...
NOTICE: starting backup (using pg_basebackup)...
HINT: this may take some time; consider using the -c/--fast-checkpoint option
INFO: executing:
  /usr/pgsql-12/bin/pg_basebackup -l "repmgr base backup"  -D /home/postgres/pgsql/12/data -h 192.168.101.9 -p 5432 -U postgres -X stream
NOTICE: standby clone (using pg_basebackup) complete
NOTICE: you can now start your PostgreSQL server
HINT: for example: pg_ctl -D /home/postgres/pgsql/12/data start
HINT: after starting the server, you need to register this standby with "repmgr standby register"

6、啟動並注冊備機

#啟動
./pg_ctl -D /home/postgres/pgsql/12/data start
#注冊 [postgres@localhost bin]$ .
/repmgr standby register INFO: connecting to local node "node2" (ID: 2) INFO: connecting to primary database WARNING: --upstream-node-id not supplied, assuming upstream node is primary (node ID 1) INFO: standby registration complete NOTICE: standby node "node2" (ID: 2) successfully registered

7、集群狀態檢查

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM