repmgr是一個(gè)對postgresql流復(fù)制進(jìn)行管理以及自動故障轉(zhuǎn)移的開源軟件,大大的簡化了PG流復(fù)制架構(gòu)的管理。但是repmgr不具備提供VIP功能,只能借助keepalived實(shí)現(xiàn)VIP,并確保VIP運(yùn)行在primary節(jié)點(diǎn)上。其不具備連接池功能,所以只是一個(gè)輕量級開源軟件。下面詳細(xì)介紹該架構(gòu)的詳細(xì)搭建過程。
yumcheck-update
yumgroupinstall "Development Tools"
yuminstall yum-utils openjade docbook-dtds docbook-style-dsssldocbook-style-xsl
yuminstall flex libselinux-devel libxml2-devel libxslt-developenssl-devel pam-devel readline-devel
./configure&& make install
注意,確保pg_config在安裝用戶的環(huán)境變量PATH中,repmgr會默認(rèn)安裝到postgres的軟件目錄下。
createuser repluser with usperuser password ****;
createdatabase repmgr with owner=repluser;
local replication repluser trust
host replication repluser 127.0.0.1/32 trust
host replication repluser 10.26.60.0/24 scram-sha-256
local repmgr repluser trust
host repmgr repluser 127.0.0.1/32 trust
host repmgr repluser 10.26.60.0/24 scram-sha-256
spcl-pg250:5432:repmgr:repluser:Repl#2021
spcl-pg249:5432:repmgr:repluser:Repl#2021
node_id=1
node_name=host01
conninfo=host=host01user=repluser dbname=repmgr connect_timeout=2
data_directory=/pgdata’
repmgr-f /etc/repmgr.conf primary register
repmgr-f /etc/repmgr.conf cluster show
node_id=2
node_name=host02
conninfo=host=host02user=repluser dbname=repmgr connect_timeout=2
data_directory=/pgdata
[postgres@host02pgdata]$ repmgr -h host01 -U repluser -d repmgr -f/pgdata/repmgr.conf standby clone --dry-run
NOTICE:destination directory "/pgdata" provided
INFO:connecting to source node
DETAIL:connection string is: host=host01 user=repluser dbname=repmgr
DETAIL:current installation size is 31 MB
INFO:"repmgr" extension is installed in database "repmgr"
INFO:replication slot usage not requested; no replication slot will beset up for this standby
INFO:parameter "max_wal_senders" set to 32
NOTICE:checking for available walsenders on the source node (2 required)
INFO:sufficient walsenders available on the source node
DETAIL:2 required, 31 available
NOTICE:checking replication connections can be made to the source server (2required)
INFO:required number of replication connections could be made to thesource server
DETAIL:2 replication connections required
WARNING:data checksums are not enabled and "wal_log_hints" is "off"
DETAIL:pg_rewind requires "wal_log_hints" to be enabled
NOTICE:standby will attach to upstream node 1
HINT:consider using the -c/--fast-checkpoint option
INFO:all prerequisites for "standby clone" are met
repmgr-h host01 -U repluser -d repmgr -f /etc/repmgr.conf standby clone
repmgr-f /etc/repmgr.conf standby register
repmgr-f /etc/repmgr.conf cluster show
至此,repmgr就搭建及配置完成。
repmgrstandby switchover -f /etc/repmgr.conf --siblings-follow --dry-run --切換檢查
repmgr-f /etc/repmgr.conf standby switchover
repmgr-f /etc/repmgr.conf standby promote ---備節(jié)點(diǎn)
repmgr-f /etc/repmgr.conf standby follow --如果有多個(gè)備節(jié)點(diǎn),在其他備節(jié)點(diǎn)執(zhí)行
shared_preload_libraries = repmgr
monitor_interval_secs=2
connection_check_type=connection
reconnect_attempts==6
reconnect_interval=4
failover=automatic
promote_command=/usr/local/postgresql/bin/repmgr standby promote -f /etc/repmgr.conf --log-to-file
follow_command=/usr/local/postgresql/bin/repmgr standby follow -f /etc/repmgr.conf --log-to-file --upstream-node-id=%n
log_level=INFO
log_facility=STDERR
log_file=/data/pgdata/log/repmgr.log
log_status_interval=300
repmgrd_service_start_command = repmgrd --daemonize=true
repmgrd_service_stop_command = kill `cat /data/pgdata/repmgrd.pid`
repmgrd_pid_file= /pgdata/repmgrd.pid
repmgrdaemon start
--自動failover之后需手工將原主節(jié)點(diǎn)恢復(fù)成備節(jié)點(diǎn),然后執(zhí)行repmgr-f /etc/repmgr.conf standby register --force ,否則下次不會自動failover。
global_defs {
router_id pg_ha
# enable_script_security
}
vrrp_script checkpg {
script "/etc/keepalived/scripts/checkpg.sh"
interval 15
fall 3
rise 1
}
vrrp_instance VI_pgusdp {
state BACKUP
interface ens160
virtual_router_id 152
priority 80
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 234235
}
track_script {
checkpg
}
notify_master "/etc/keepalived/scripts/master.sh"
notify_backup "/etc/keepalived/scripts/slave.sh"
virtual_ipaddress {
10.**.**.**/24
}
}
#!/bin/bash
export PGDATABASE=postgres
export PGPORT=5432
export PGUSER=postgres
export PGBIN=/usr/local/postgresql/bin
export PGDATA=/data/pgdata
LOGFILE=/etc/keepalived/log/keepalived.log
nc -w 3 localhost 5432 a=`echo $?`
if [ $a -eq 1 ] ;then
exit 1
else
SQL1=SELECT pg_is_in_recovery from pg_is_in_recovery();
db_role=`echo $SQL1 | ${PGBIN}/psql -d $PGDATABASE -U $PGUSER -h $PGDATA -At -w`
if [ $db_role == t ];then
exit 1
fi
fi
LOGFILE=/etc/keepalived/log/keepalived.log
export PGDATABASE=postgres
export PGPORT=5432
export PGUSER=postgres
export PGBIN=/usr/local/postgresql/bin
export PGDATA=/data/pgdata
LOGFILE=/etc/keepalived/log/keepalived.log
SQL1=SELECT pg_is_in_recovery from pg_is_in_recovery();
db_role=`echo $SQL1 | ${PGBIN}/psql -d $PGDATABASE -U $PGUSER -h $PGDATA -At -w`
if [ $db_role == t ];then
echo -e `date +"%F %T"` "the current database is standby DB! " >> $LOGFILE
exit 1
else
echo -e `date +"%F %T"` "the current database is master DB!" >> $LOGFILE
fi
LOGFILE=/etc/keepalived/log/keepalived.log
export PGDATABASE=postgres
export PGPORT=5432
export PGUSER=postgres
export PGBIN=/usr/local/postgresql/bin
export PGDATA=/data/pgdata
LOGFILE=/etc/keepalived/log/keepalived.log
SQL1=SELECT pg_is_in_recovery from pg_is_in_recovery();
db_role=`echo $SQL1 | ${PGBIN}/psql -d $PGDATABASE -U $PGUSER -h $PGDATA -At -w`
if [ $db_role == t ];then
echo -e `date +"%F %T"` "the current database is standby DB! " >> $LOGFILE
else
echo -e `date +"%F %T"` "the current database is master DB!" >> $LOGFILE
fi
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/129213.html
摘要:作者譚峰張文升出版日期年月頁數(shù)頁定價(jià)元本書特色中國開源軟件推進(jìn)聯(lián)盟分會特聘專家撰寫,國內(nèi)多位開源數(shù)據(jù)庫專家鼎力推薦。張文升中國開源軟件推進(jìn)聯(lián)盟分會核心成員之一。 很高興《PostgreSQL實(shí)戰(zhàn)》一書終于出版,本書大體上系統(tǒng)總結(jié)了筆者 PostgreSQL DBA 職業(yè)生涯的經(jīng)驗(yàn)總結(jié),本書的另一位作者張文升擁有豐富的PostgreSQL運(yùn)維經(jīng)驗(yàn),目前就職于探探科技任首席PostgreS...
摘要:開源數(shù)據(jù)庫中文資料非常缺乏,很多社區(qū)朋友苦于上手的中文資料少,因此匯總收集以下中文資料,包括中文手冊,中文書籍,技術(shù)博客,培訓(xùn)視頻和歷屆大會材料。希望這些中文資料能夠方便有需要的朋友,降低的上手門檻。 開源數(shù)據(jù)庫 PostgreSQL 中文資料非常缺乏,很多社區(qū)朋友苦于上手的中文資料少,因此匯總收集以下 PostgreSQL 中文資料,包括 PostgreSQL 中文手冊,中文書籍,技...
摘要:量化派是一家數(shù)據(jù)驅(qū)動的科技金融公司,通過人工智能大數(shù)據(jù)機(jī)器學(xué)習(xí)等前沿技術(shù)提供消費(fèi)信貸撮合及消費(fèi)場景下的白條服務(wù),每年處理千萬級用戶信用及信用消費(fèi)申請。 「小楊」最近裝修房子,準(zhǔn)備去銀行貸款,但是聽說好多人會因?yàn)閭€(gè)人征信問題被銀行拒絕貸款!于是,他先查了一下自己的央行征信,發(fā)現(xiàn)竟然沒有自己的征信信息,「小楊」陷入了沉思,自己經(jīng)常在淘寶、jd 上買東西,也有淘寶花唄和京東白條,怎么會沒有征...
摘要:環(huán)境說明需求與目標(biāo)本文將通過對目前主流的幾種高可用方案進(jìn)行對比分析,并基于騰訊云和等基礎(chǔ)產(chǎn)品進(jìn)行搭建配置測試總結(jié)。 本文來源 | 云+社區(qū)專欄文章作者 | 萬守兵,騰訊云資深架構(gòu)師。8年以上大型互聯(lián)網(wǎng)公司運(yùn)維工作經(jīng)驗(yàn),騰訊云資深遷云架構(gòu)師,一直從事大型互聯(lián)網(wǎng)服務(wù)端架構(gòu)設(shè)計(jì)和優(yōu)化工作。個(gè)人專注于云計(jì)算、k8s和 DevOps領(lǐng)域。 導(dǎo)讀:在企業(yè)實(shí)際生產(chǎn)環(huán)境中為了能夠給業(yè)務(wù)上層應(yīng)用提供高...
閱讀 1359·2023-01-11 13:20
閱讀 1707·2023-01-11 13:20
閱讀 1215·2023-01-11 13:20
閱讀 1908·2023-01-11 13:20
閱讀 4166·2023-01-11 13:20
閱讀 2759·2023-01-11 13:20
閱讀 1402·2023-01-11 13:20
閱讀 3673·2023-01-11 13:20