點(diǎn)擊上方“IT那活兒”公眾號,關(guān)注后了解更多內(nèi)容,不管IT什么活兒,干就完了!!!
主機(jī)信息
IP3:192.168.21.152 witness PG-3
安裝PostgreSQL
參數(shù)調(diào)整:
hot_standby=on
SSH免密 兩臺主機(jī)均做
PG-1:?
vim /etc/hosts
192.168.21.151 PG-1
192.168.21.150 PG-2
192.168.21.152 PG-3
ssh-keygen
ssh-copy-id -i .ssh/idrsa.pub postgres@PG-2
ssh-copy-id -i .ssh/idrsa.pub postgres@PG-3
PG-2:
vim /etc/hosts
192.168.21.151 PG-1
192.168.21.150 PG-2
192.168.21.152 PG-3
ssh-keygen
ssh-copy-id -i .ssh/idrsa.pub postgres@PG-1
ssh-copy-id -i .ssh/idrsa.pub postgres@PG-3
PG-3:?
vim /etc/hosts
192.168.21.151 PG-1
192.168.21.150 PG-2
192.168.21.152 PG-3
ssh-keygen
ssh-copy-id -i .ssh/idrsa.pub postgres@PG-1
ssh-copy-id -i .ssh/idrsa.pub postgres@PG-2
安裝repmgr ,三臺主機(jī)都安裝
tar -xzvf repmgr.4.2.tar.gz
cd repmgr.4.2
./configure
make
make install
配置pg_hba.conf和創(chuàng)建repmgr用戶和庫
initdb -A scram-sha-256 -D /data/pg133 -E utf8 --wal-segsize=1024 -U postgres -W -k
create database repmgr;
create user repmgr replication login superuser password 4Replic%;
alter user repmgr set search_path to repmgr,"$user",public;
shared_preload_libraries=repmgr;
vi /home/postgres/.pgpass
ip:port:repmgr:repmgr:repmgr
ip:port:replication:repmgr:repmgr #注意該行必須有,否則在執(zhí)行switchover的時候,standby可以正常提升為primary,但舊primary 無法自動跟隨新主,每臺主機(jī)上都要進(jìn)行配置。
repmgr集群搭建
vim /etc/remgr/repmgr.conf
node_id=1
node_name=PG-1.PG
conninfo=host=PG-1.PG port=5432 user=repmgr dbname=repmgr
data_directory=/data/pg134
replication_user=repmgr
replication_type=physical
use_replication_slots=true
location=my-repmgr
#witness settings
witness_sync_interval=10
#logging settings
log_level=INFO
log_facility=STDERR
log_file=/opt/repmgr/repmgr.log
log_status_interval=2
#Environment/Command Settings
pg_bindir=/opt/pg134/bin
repmgr_bindir=/opt/pg134/bin
passfile=/home/postgres/.pgpass
use_primary_conninfo_password=false
#Standby promote_Settings
promote_check_timeout=60
promote_check_interval=1
#Standby Follow Settings
primary_follow_timeout=60
standby_follow_timeout=15
#Standby Switchover Settings
shutdown_check_timeout=60
standby_reconnect_timeout=60
wal_receive_check_timeout=30
#Node Rejoin Settings
node_rejoin_timeout=60
#Failover And Monitoring Settings
failover=automatic
priority=100
connection_check_type=ping
reconnect_attempts=5
reconnect_interval=2
promote_command=/opt/pg134/bin/repmgr standby promote -f /opt/repmgr/repmgr.conf --log-to-file
follow_command=/opt/pg134/bin/repmgr standby follow -f /opt/repmgr/repmgr.conf --upstream-node-id=%n --log-to-file
primary_notification_timeout=60
repmgrd_standby_startup_timeout=30
monitoring_history=yes
monitor_interval_secs=2
degraded_monitoring_timeout=-1
async_query_timeout=60
repmgrd_pid_file=/opt/repmgr/repmgrd.pid
standby_disconnect_on_failover=true
sibling_nodes_disconnect_timeout=30
child_node_connected_min_count=1
child_nodes_check_interval=2
child_nodes_disconnect_timeout=10
child_nodes_connected_include_wintess=true
#child_nodes_disconnect_command = /opt/pg134/bin/pg_ctl stop -D /data/pg134
primary_visibility_consensus=true
#Service Control Commands
service_start_command=/opt/pg134/bin/pg_ctl start -w -D /data/pg134
service_stop_command=/opt/pg134/bin/pg_ctl stop -w -D /data/pg134
service_restart_command=/opt/pg134/bin/pg_ctl restart -w -D /data/pg134
service_reload_command=/opt/pg134/bin/pg_ctl reload -w -D /data/pg134
repmgrd_service_start_command=> /opt/repmgr/repmgrd.pid && /opt/pg134/bin/repmgrd -f /opt/repmgr/repmgr.conf -d -p /opt/repmgr/repmgrd.pid
repmgrd_service_stop_command=kill -9 `cat /opt/repmgr/repmgrd.pid`
repmgr -f /etc/repmgr/repmgr.conf cluster show
repmgrd -f /etc/repmgr/repmgr.conf --verbose --monitoring-history > /var/log/repmgr/repmgr.log 2>&1 &
或者
repmgr -f /etc/repmgr/repmgr.conf daemon start
vim /etc/repmgr/repmgr.conf
node_id=2
node_name=PG-2.PG
conninfo=host=PG-2.PG port=5432 user=repmgr dbname=repmgr
data_directory=/data/pg134
replication_user=repmgr
replication_type=physical
use_replication_slots=true
location=my-repmgr
#witness settings
witness_sync_interval=10
#logging settings
log_level=INFO
log_facility=STDERR
log_file=/opt/repmgr/repmgr.log
log_status_interval=2
#Environment/Command Settings
pg_bindir=/opt/pg134/bin
repmgr_bindir=/opt/pg134/bin
passfile=/home/postgres/.pgpass
use_primary_conninfo_password=false
#Standby promote_Settings
promote_check_timeout=60
promote_check_interval=1
#Standby Follow Settings
primary_follow_timeout=60
standby_follow_timeout=15
#Standby Switchover Settings
shutdown_check_timeout=60
standby_reconnect_timeout=60
wal_receive_check_timeout=30
#Node Rejoin Settings
node_rejoin_timeout=60
#Failover And Monitoring Settings
failover=automatic
priority=100
connection_check_type=ping
reconnect_attempts=5
reconnect_interval=2
promote_command=/opt/pg134/bin/repmgr standby promote -f /opt/repmgr/repmgr.conf --log-to-file
follow_command=/opt/pg134/bin/repmgr standby follow -f /opt/repmgr/repmgr.conf --upstream-node-id=%n --log-to-file
primary_notification_timeout=60
repmgrd_standby_startup_timeout=30
monitoring_history=yes
monitor_interval_secs=2
degraded_monitoring_timeout=-1
async_query_timeout=60
repmgrd_pid_file=/opt/repmgr/repmgrd.pid
standby_disconnect_on_failover=true
sibling_nodes_disconnect_timeout=30
child_node_connected_min_count=1
child_nodes_check_interval=2
child_nodes_disconnect_timeout=10
child_nodes_connected_include_wintess=true
child_nodes_disconnect_command = /opt/pg134/bin/pg_ctl stop -D /data/pg134
primary_visibility_consensus=true
#Service Control Commands
service_start_command=/opt/pg134/bin/pg_ctl start -w -D /data/pg134
service_stop_command=/opt/pg134/bin/pg_ctl stop -w -D /data/pg134
service_restart_command=/opt/pg134/bin/pg_ctl restart -w -D /data/pg134
service_reload_command=/opt/pg134/bin/pg_ctl reload -w -D /data/pg134
repmgrd_service_start_command=> /opt/repmgr/repmgrd.pid && /opt/pg134/bin/repmgrd -f /opt/repmgr/repmgr.conf -d -p /opt/repmgr/repmgrd.pid
repmgrd_service_stop_command=kill -9 `cat /opt/repmgr/repmgrd.pid`
repmgr -f /etc/repmgr/repmgr.conf -U repmgr -d repmgr -h 192.168.28.166 standby clone --dry-run -c
--dry-run選項用于檢查。
repmgr -f /etc/repmgr/repmgr.conf -U repmgr -d repmgr -h 192.168.28.166 standby clone -c
克隆從主PostgreSQL的數(shù)據(jù)目錄中的文件節(jié)點(diǎn),使用postgresql的pg_basebackup,會自動創(chuàng)建一個recovery.conf文件。
pg_ctl -D /data/pgdata start
repmgr -f /etc/repmgr/repmgr.conf standby register
repmgr -f /etc/repmgr/repmgr.conf daemon start
或
repmgrd -f /etc/repmge/repmgr.conf -d -p /data/repmgr/repmgrd.pid
initdb -A scram-sha-256 -D /data/pg133 -E utf8 --wal-segsize=1024 -U postgres -W -k
create database repmgr;
create user repmgr with login superuser replication password 4Replic%;
alter user repmgr set search_path to repmgr,"$user",public;
數(shù)據(jù)庫配置參數(shù):
shared_preload_libraries=repmgr;
數(shù)據(jù)庫重啟。
vi /etc/repmgr/repmgr.conf
node_id=3
node_name=PG-3.PG
conninfo=host=PG-3.PG port=5432 user=repmgr dbname=repmgr
data_directory=/data/pg134
replication_user=repmgr
replication_type=physical
use_replication_slots=true
location=my-repmgr
#witness settings
witness_sync_interval=10
#logging settings
log_level=INFO
log_facility=STDERR
log_file=/opt/repmgr/repmgr.log
log_status_interval=2
#Environment/Command Settings
pg_bindir=/opt/pg134/bin
repmgr_bindir=/opt/pg134/bin
passfile=/home/postgres/.pgpass
use_primary_conninfo_password=false
#Standby promote_Settings
promote_check_timeout=60
promote_check_interval=1
#Standby Follow Settings
primary_follow_timeout=60
standby_follow_timeout=15
#Standby Switchover Settings
shutdown_check_timeout=60
standby_reconnect_timeout=60
wal_receive_check_timeout=30
#Node Rejoin Settings
node_rejoin_timeout=60
#Failover And Monitoring Settings
failover=automatic
priority=100
connection_check_type=ping
reconnect_attempts=5
reconnect_interval=2
promote_command=/opt/pg134/bin/repmgr standby promote -f /opt/repmgr/repmgr.conf --log-to-file
follow_command=/opt/pg134/bin/repmgr standby follow -f /opt/repmgr/repmgr.conf --upstream-node-id=%n --log-to-file
primary_notification_timeout=60
repmgrd_standby_startup_timeout=30
monitoring_history=yes
monitor_interval_secs=2
degraded_monitoring_timeout=-1
async_query_timeout=60
repmgrd_pid_file=/opt/repmgr/repmgrd.pid
standby_disconnect_on_failover=true
sibling_nodes_disconnect_timeout=30
child_nodes_check_interval=2
child_node_connected_min_count=1
child_nodes_disconnect_timeout=10
child_nodes_connected_include_wintess=true
child_nodes_disconnect_command = /opt/pg134/bin/pg_ctl stop -D /data/pg134
primary_visibility_consensus=true
#Service Control Commands
service_start_command=/opt/pg134/bin/pg_ctl start -w -D /data/pg134
service_stop_command=/opt/pg134/bin/pg_ctl stop -w -D /data/pg134
service_restart_command=/opt/pg134/bin/pg_ctl restart -w -D /data/pg134
service_reload_command=/opt/pg134/bin/pg_ctl reload -w -D /data/pg134
repmgrd_service_start_command=> /opt/repmgr/repmgrd.pid && /opt/pg134/bin/repmgrd -f /opt/repmgr/repmgr.conf -d -p /opt/repmgr/repmgrd.pid
repmgrd_service_stop_command=kill -9 `cat /opt/repmgr/repmgrd.pid`
repmgr -f /etc/repmgr/repmgr.conf witness register -h PG-1 -U repmgr -d repmgr
注意:-h連接的是primary節(jié)點(diǎn),當(dāng)發(fā)生故障切換時,見證節(jié)點(diǎn)會自動連接到最新的primary節(jié)點(diǎn)。
repmgr -f /etc/repmgr/repmgr.conf daemon start
或
repmgrd -f /etc/repmge/repmgr.conf -d -p /data/repmgr/repmgrd.pid
基于同步的模式
7.1 在現(xiàn)有環(huán)境開啟同步復(fù)制
#!/bin/bash
DBPATH=/opt/pg134/bin
DBPORT=5432
DBHOST=127.0.0.1
/opt/pg134/bin/pg_ctl stop -D /data/pg134
$DBPATH/psql -U postgres -p $PGPORT -h $DBHOST <checkpoint;
alter system set synchronous_standby_names to ;
select pg_reload_conf();
q
EOF
使用復(fù)制槽
在現(xiàn)有環(huán)境中使用復(fù)制槽:
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/129225.html
摘要:相比自建,其可靠性更高,方便運(yùn)維維護(hù)。宋體經(jīng)過審慎考慮,用戶同時選用三種數(shù)據(jù)庫,針對性的滿足不同目標(biāo)。宋體宋體其中,相比于在上的快速高效是其優(yōu)勢,也是用戶選型的重要砝碼。PostgreSQL UDB用在大數(shù)據(jù)分析上,查詢效率更高。相比自建,其可靠性更高,方便運(yùn)維維護(hù)。 — 31會議運(yùn)維經(jīng)理 湯雷 如何用好PostgreSQL? PostgreSQL是業(yè)內(nèi)一款十分流行的開源數(shù)...
摘要:經(jīng)過對比選型,用戶同時選用三種數(shù)據(jù)庫來針對性的滿足不同目標(biāo)。基于能夠帶來的這些特性優(yōu)勢,用戶選擇了。相比自建,其可靠性更高,方便運(yùn)維維護(hù)。整個過程中用戶不需要任何人工干預(yù)和配置修改,真正做到自動容災(zāi)。 據(jù)DB-Engines 最新發(fā)布的2019年8月份數(shù)據(jù)庫流行度排行榜(如下圖)顯示,名列前茅的MySQL和PostgreSQL數(shù)據(jù)庫的流行趨勢與去年同期相比依然穩(wěn)增不減。 showImg...
摘要:前面我們簡單闡述了分布式數(shù)據(jù)庫的架構(gòu),并通過一條簡單的查詢語句解釋了分布式的執(zhí)行計劃。 引言 第八屆中國架構(gòu)師大會(SACC2016)10月27號到29號在北京萬達(dá)索菲特大飯店成功舉辦。大會以架構(gòu)創(chuàng)新之路為主題,云集了國內(nèi)外頂尖專家,共同探討云計算和大數(shù)據(jù)等技術(shù)背景下,如何通過架構(gòu)創(chuàng)新及各種IT新技術(shù)來帶動企業(yè)轉(zhuǎn)型增效。作為一家專注于云端數(shù)據(jù)倉庫的初創(chuàng)公司,酷克數(shù)據(jù)受邀在SACC201...
閱讀 1346·2023-01-11 13:20
閱讀 1684·2023-01-11 13:20
閱讀 1132·2023-01-11 13:20
閱讀 1858·2023-01-11 13:20
閱讀 4100·2023-01-11 13:20
閱讀 2704·2023-01-11 13:20
閱讀 1385·2023-01-11 13:20
閱讀 3597·2023-01-11 13:20