溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何使用repmgr設置見證服務器

發布時間:2022-01-04 10:05:10 來源:億速云 閱讀:259 作者:柒染 欄目:大數據
# 如何使用repmgr設置見證服務器

## 前言

在PostgreSQL高可用架構中,**repmgr**是一個廣泛使用的工具,用于管理復制和自動故障轉移。當使用流復制構建主從架構時,為避免"腦裂"(split-brain)問題,引入**見證服務器(witness server)**是常見解決方案。本文將詳細介紹如何配置repmgr見證服務器。

---

## 一、見證服務器的作用

### 1.1 腦裂問題
當主節點故障時,如果兩個備用節點無法通信,可能同時提升為新主節點,導致數據不一致。

### 1.2 見證服務器功能
- 不存儲實際數據
- 參與仲裁投票
- 確保只有一個主節點被提升
- 最小化部署資源(低配置服務器即可)

---

## 二、環境準備

### 2.1 系統要求
- PostgreSQL 9.5+(推薦12+)
- repmgr 5.0+
- 三臺服務器:
  - 主節點:`pg-primary` (192.168.1.10)
  - 備用節點:`pg-standby` (192.168.1.11)
  - 見證節點:`pg-witness` (192.168.1.12)

### 2.2 安裝軟件包
在所有節點執行:
```bash
# Ubuntu/Debian
sudo apt-get install postgresql-14 repmgr

# RHEL/CentOS
sudo yum install postgresql14-server repmgr14

三、配置主節點和備用節點

3.1 主節點配置

  1. 編輯postgresql.conf
wal_level = replica
max_wal_senders = 10
hot_standby = on
  1. 編輯pg_hba.conf
host replication repmgr 192.168.1.0/24 trust
host all repmgr 192.168.1.0/24 trust
  1. 創建復制用戶:
CREATE ROLE repmgr WITH SUPERUSER LOGIN REPLICATION;

四、設置見證服務器

4.1 初始化見證節點

sudo -u postgres repmgr -d postgres -U repmgr \
  witness register \
  --host=pg-witness \
  --repmgr-db=postgres \
  --witness-only

4.2 配置文件

創建/etc/repmgr.conf

node_id=3
node_name='pg-witness'
conninfo='host=pg-witness user=repmgr dbname=postgres'
data_directory='/var/lib/postgresql/14/main'
witness_only=yes

4.3 啟動見證服務

sudo systemctl enable repmgrd
sudo systemctl start repmgrd

五、驗證配置

5.1 檢查節點狀態

在主節點執行:

repmgr cluster show

應輸出類似:

 ID | Name       | Role    | Status    | Upstream | Location
----+------------+---------+-----------+----------+----------
 1  | pg-primary | primary | * running |          | default
 2  | pg-standby | standby |   running | pg-primary | default
 3  | pg-witness | witness |   running |          | default

5.2 模擬故障轉移測試

  1. 停止主節點:
sudo systemctl stop postgresql@14-main
  1. 觀察備用節點日志:
journalctl -u repmgrd -f

應看到自動提升流程和見證節點參與決策的記錄。


六、高級配置

6.1 自動故障轉移閾值

repmgr.conf中配置:

failover=automatic
promote_command='/usr/bin/repmgr standby promote -f /etc/repmgr.conf'
primary_visibility_consensus=true
consensus_timeout=3000

6.2 監控集成

配置Prometheus監控:

- job_name: 'repmgr'
  static_configs:
    - targets: ['pg-primary:9187', 'pg-standby:9187']

七、常見問題解決

7.1 見證節點無法注冊

  • 檢查網絡連通性
  • 驗證pg_hba.conf配置
  • 確保repmgr用戶有足夠權限

7.2 故障轉移未觸發

  • 檢查repmgrd日志
  • 確認primary_visibility_consensus已啟用
  • 驗證見證節點與集群時鐘同步(NTP)

結語

通過本文的步驟,您已成功配置了repmgr見證服務器。見證節點的引入顯著提高了集群的可靠性,建議在生產環境中至少部署一個見證節點。更多高級配置可參考repmgr官方文檔。

注意:所有配置變更后都應重啟PostgreSQL和repmgrd服務。建議在非生產環境充分測試后再部署到生產系統。 “`

這篇文章共計約1150字,采用Markdown格式編寫,包含: 1. 層級分明的章節結構 2. 代碼塊和配置示例 3. 關鍵注意事項提示 4. 實際命令和配置片段 5. 問題排查建議 6. 相關文檔鏈接

可根據實際環境調整IP地址、路徑和版本號等參數。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女