基础信息:
节点 | 角色 | pg版本 | 节点IP | os版本 | pg安装方式 |
---|---|---|---|---|---|
node1 | primary | 14.12 | 10.204.121.214 | Ubuntu2204 | apt |
node2 | standby | 14.12 | 10.204.121.214 | Ubuntu2204 | apt |
安装pg(所有节点)
sudo apt update
sudo apt install postgresql-14 -y
sudo systemctl status postgresql@14-main.service
sudo -u postgres psql -c "SELECT version();"
安装repmgr(所有节点)
下面安装的是14匹配的repmgr,如果是其他版本把14换成其他版本即可
sudo apt-get install postgresql-14-repmgr -y
配置主库node1
修改配置文件 /etc/postgresql/14/main/postgresql.conf
sed -i '/cluster_name/s/14\/main/node1/' /etc/postgresql/14/main/postgresql.conf
cat <<EOF >> /etc/postgresql/14/main/postgresql.conf
listen_addresses = '*'
max_wal_senders = 10
max_replication_slots = 10
wal_level = 'hot_standby'
hot_standby = on
archive_mode = on # repmgr 本身不需要 WAL 文件归档。
archive_command = '/bin/true'
shared_preload_libraries = 'repmgr'
wal_log_hints = 'on'
EOF
- 创建 repmgr 用户
su -l postgres -c "createuser -s repmgr"
su -l postgres -c "createdb repmgr -O repmgr"
- 配置 /etc/postgresql/14/main/pg_hba.conf
这个hba文件是为了配置repmgr用户无密码访问repmgr数据库的,所以上面创建用户的时候没有设置密码,trust就是这个意思,还有其他的配置项可以看配置文件里的解释
sed -i '/# DO NOT DISABLE!/i \
local replication repmgr trust \
host replication repmgr 127.0.0.1/32 trust \
host replication repmgr 0.0.0.0/0 trust \
local repmgr repmgr trust \
host repmgr repmgr 127.0.0.1/32 trust \
host repmgr repmgr 0.0.0.0/0 trust' /etc/postgresql/14/main/pg_hba.conf
- 配置/etc/postgresql/14/main/repmgr.conf,内容如下
cat <<EOF