前言
PostgreSQL建置高可用性,架構有許多種,但每種架構可用的場景都不太相同,需要由各位讀者自行去瞭解每種功能與切換方式
架構例如:
- PostgreSQL & pgpool
- PostgreSQL & streaming replication
- PostgreSQL & Linux Pacemaker
- PostgreSQL & Patroni
- PostgreSQL & repmgr
本篇主要是說明 PostgreSQL + repmgr 架構,並搭配主機VIP,讓AP連線只需要連至VIP即可連到Primary主機上;DR備援與PROD端因專案不需要整個Database都同步,只需要指定部份Table同步,因此採用了logical replication。
Infrastructure 架構圖
PostgreSQL Database Architecture Configuration Table 資料庫系統配置表
HostName | IP address | VIP | Software Version | Directory |
pgrep1 | 172.30.0.21 | 172.30.0.25 | PG 14 repmgr 5.3 | /pgbin : pg binary & repmgr /pgdata : pg instance |
pgrep2 | 172.30.0.22 | |||
pgrep3 | 172.30.0.23 | PG 14 | /pgbin : pg binary /pgdata : pg instance |
前置作業 (每台主機都需要安裝與設定)
Step 1. 安裝lib套件
# yum install make gcc gcc-c++ readline readline-devel libedit \ zlib zlib-devel libxml2 libxml2-devel flex bison libevent \ lz4 lz4-devel tcl tcl-devel openssl openssl-devel \ vim libxslt-devel pam-devel libselinux-devel telnet OpenIPMI-perl
Step 2. python套件 (platform-python為CentOS 8.4找到的名稱,需要安裝python3以上的版本)
# yum install platform-python
Step 3. 依需求規劃,存放PostgreSQL Binary & PostgreSQL Data之空間
[root@pgrep1 /]# df -h Filesystem Size Used Avail Use% Mounted on ... /dev/mapper/vg--pgdata1-lv--pgdata 30G 247M 30G 1% /pgdata /dev/mapper/vg--pgbin1-lv--pgbin 20G 175M 20G 1% /pgbin
Step 4. 建立PostgreSQL作業系統管理帳號,筆者取名為pgadm
[root@pgrep1 ~]# groupadd -g 2001 postgres [root@pgrep1 ~]# useradd -u 2001 -g postgres -G postgres pgadm [root@pgrep1 ~]# id pgadm uid=2001(pgadm) gid=2001(postgres) groups=2001(postgres) [root@pgrep1 ~]# passwd pgadm
Step 5. 設定節點1、節點2 ssh keyless
[pgadm@pgrep1 ~]$ ssh-keygen [pgadm@pgrep1 ~]$ ssh-copy-id pgrep2 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/pgadm/.ssh/id_rsa.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys pgadm@pgrep2's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'pgrep2'" and check to make sure that only the key(s) you wanted were added. [pgadm@pgrep2 ~]$ ssh-keygen [pgadm@pgrep2 ~]$ ssh-copy-id pgrep1 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/pgadm/.ssh/id_rsa.pub" The authenticity of host 'pgrep1 (172.30.0.21)' can't be established. ECDSA key fingerprint is SHA256:3/B7aqH3hYkGHZMyl9cpv851rGnZ87uUmthzgIARdPI. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys pgadm@pgrep1's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'pgrep1'" and check to make sure that only the key(s) you wanted were added.
0 留言