repmgr 을 활용해서 postgresql 이중화 서버를 구현해 보았습니다.
잘 모르셔도 그대로만 따라하면 구현이 되도록 자세하게 적어두었습니다.
혹시 읽다가 틀린 부분이 있다거나 이해가 되지 않는 부분이 있다면 댓글 부탁드립니다.
[root@localhost /]# sudo yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
[root@localhost /]# sudo yum install -y postgresql14-server
[root@localhost /]# sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
[root@localhost /]# curl https://dl.enterprisedb.com/default/release/get/14/rpm | sudo bash
[root@localhost /]# yum install dnf
[root@localhost /]# sudo dnf install repmgr14
[root@localhost /]# ln -s /usr/pgsql-14/bin/repmgr /usr/bin/repmgr
[root@localhost /]# ln -s /usr/pgsql-14/bin/repmgrd /usr/bin/repmgrd
postgres ALL=NOPASSWD: /usr/bin/systemctl stop postgresql-14.service, \
/usr/bin/systemctl start postgresql-14.service, \
/usr/bin/systemctl restart postgresql-14.service, \
/usr/bin/systemctl reload postgresql-14.service, \
/usr/bin/systemctl start repmgr14.service, \
/usr/bin/systemctl stop repmgr14.service
postgres 계정이 postgreSQL 또는 repmgr을 패스워드 없이 시작, 종료 할 수 있도록 설정.
[root@localhost /]# createuser --superuser repmgr
[root@localhost /]# createdb --owner=repmgr repmgr
listen_addresses = '*'
port = 5432
max_wal_senders = 10
max_replication_slots = 10
wal_level = 'replica'
hot_standby = on
archive_mode = on
archive_command = '/bin/true'
wal_log_hints = on
shared_preload_libraries = 'repmgr'
## type database user address auth-method
local replication {유저명} trust
host replication {유저명} 127.0.0.1/32 trust
host replication {유저명} {IP대역}/24 trust
local {DB명} {유저명} trust
host {DB명} {유저명} 127.0.0.1/32 trust
host {DB명} {유저명} {IP대역}/24 trust
Type : local 은 같은 머신에서의 연결을 의미하고 host 는 네트워크를 통한 연결을 의미합니다. host는 hostssl 과 hostnossl 로 세분화되어 SSL 연결만 허용하거나 금지할 수 있습니다.
Database : 이 규칙이 적용된 데이터 베이스를 지정합니다. sameuser 나 samerole 같은 특수 키워드를 사용하여 접근 규칙을 세밀하게 조정할 수 있습니다.
User : 이 규칙이 적용될 사용자를 지정합니다. all 로 설정해 모든 사용자에게 적용할 수 있습니다.
Address : 클라이언트의 ip주소 또는 네트워크를 지정합니다. local의 경우 이 필드는 사용되지 않습니다.
Auth-method : 클라이언트 인증 방법을 지정합니다. (trust , reject, md5, password, scram-sha-256, peer , gss, sspi, identm pam , ldap 등이 있습니다.)
node_id=1
node_name='{노드명}'
conninfo='host={IP주소} user={DB명} dbname={유저명} connect_timeout=2'
data_directory='/var/lib/pgsql/14/data'
service_start_command = 'sudo systemctl start postgresql-14.service'
service_stop_command = 'sudo systemctl stop postgresql-14.service'
service_restart_command = 'sudo systemctl restart postgresql-14.service'
service_reload_command = 'sudo systemctl reload postgresql-14.service'
[root@localhost /]# repmgr primary register
[root@localhost /]# repmgr cluster show
[root@localhost /]# systemctl stop postgresql-14
node_id=2
node_name='{노드명}'
conninfo='host={IP주소} user={DB명} dbname={유저명} connect_timeout=2'
data_directory='/var/lib/pgsql/14/data'
service_start_command = 'sudo systemctl start postgresql-14.service'
service_stop_command = 'sudo systemctl stop postgresql-14.service'
service_restart_command = 'sudo systemctl restart postgresql-14.service'
service_reload_command = 'sudo systemctl reload postgresql-14.service'
[root@localhost /]# firewall-cmd --permanent --add-port=5432/tcp
[root@localhost /]# firewall-cmd --reload
[root@localhost /]# repmgr -h {primary IP} -U {유저명} -d {DB명} standby clone --force
[root@localhost /]# firewall-cmd --list-all
[root@localhost /]# firewall-cmd --permanent --add-port=5432/tcp
[root@localhost /]# firewall-cmd reload
[root@localhost /]# sudo systemctl start postgresql-14.service
[root@localhost /]# repmgr standby register
https://github.com/yoojin-kwon12/PostgreSQL_HA_MASTER
https://github.com/yoojin-kwon12/PostgreSQL_HA_SLAVE