repmgr是一個對postgresql流復制進行管理以及自動故障轉移的開源軟件,大大的簡化了PG流復制架構的管理。但是repmgr不具備提供VIP功能,只能借助keepalived實現VIP,并確保VIP運行在primary節點上。其不具備連接池功能,所以只是一個輕量級開源軟件。下面詳細介紹該架構的詳細搭建過程。
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在安裝用戶的環境變量PATH中,repmgr會默認安裝到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 ---備節點
repmgr-f /etc/repmgr.conf standby follow --如果有多個備節點,在其他備節點執行
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之后需手工將原主節點恢復成備節點,然后執行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
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/129213.html
摘要:作者譚峰張文升出版日期年月頁數頁定價元本書特色中國開源軟件推進聯盟分會特聘專家撰寫,國內多位開源數據庫專家鼎力推薦。張文升中國開源軟件推進聯盟分會核心成員之一。 很高興《PostgreSQL實戰》一書終于出版,本書大體上系統總結了筆者 PostgreSQL DBA 職業生涯的經驗總結,本書的另一位作者張文升擁有豐富的PostgreSQL運維經驗,目前就職于探探科技任首席PostgreS...
摘要:開源數據庫中文資料非常缺乏,很多社區朋友苦于上手的中文資料少,因此匯總收集以下中文資料,包括中文手冊,中文書籍,技術博客,培訓視頻和歷屆大會材料。希望這些中文資料能夠方便有需要的朋友,降低的上手門檻。 開源數據庫 PostgreSQL 中文資料非常缺乏,很多社區朋友苦于上手的中文資料少,因此匯總收集以下 PostgreSQL 中文資料,包括 PostgreSQL 中文手冊,中文書籍,技...
摘要:量化派是一家數據驅動的科技金融公司,通過人工智能大數據機器學習等前沿技術提供消費信貸撮合及消費場景下的白條服務,每年處理千萬級用戶信用及信用消費申請。 「小楊」最近裝修房子,準備去銀行貸款,但是聽說好多人會因為個人征信問題被銀行拒絕貸款!于是,他先查了一下自己的央行征信,發現竟然沒有自己的征信信息,「小楊」陷入了沉思,自己經常在淘寶、jd 上買東西,也有淘寶花唄和京東白條,怎么會沒有征...
摘要:環境說明需求與目標本文將通過對目前主流的幾種高可用方案進行對比分析,并基于騰訊云和等基礎產品進行搭建配置測試總結。 本文來源 | 云+社區專欄文章作者 | 萬守兵,騰訊云資深架構師。8年以上大型互聯網公司運維工作經驗,騰訊云資深遷云架構師,一直從事大型互聯網服務端架構設計和優化工作。個人專注于云計算、k8s和 DevOps領域。 導讀:在企業實際生產環境中為了能夠給業務上層應用提供高...
閱讀 1347·2023-01-11 13:20
閱讀 1686·2023-01-11 13:20
閱讀 1133·2023-01-11 13:20
閱讀 1861·2023-01-11 13:20
閱讀 4104·2023-01-11 13:20
閱讀 2705·2023-01-11 13:20
閱讀 1386·2023-01-11 13:20
閱讀 3599·2023-01-11 13:20