3. Monitor node 구성
1) Monitor 생성
(1) Monitor 생성 옵션
- pg_autoctl create monitor --help 로 옵션 조회할 수 있습니다.
--pg_ctl : pg_ctl 경로 (보통 $PGHOME/bin 아래에 위치)
--pgdata : pgdata 경로 (보통 $PGHOME/data)
--pgport : PostgreSQL DB 에 사용할 포트 (Default 5432)
--hostname : 사용할 hostname
Hostname 을 명시하지 않으면 아래의 알고리즘을 통해 host 를 가져옵니다.
- 8.8.8.8:53 커넥션 시도하여 public ip 획득 후 TCP/IP 클라이언트 주소 확인
- Reverse DNS lookup 하여 로컬의 hostname 확인
- Reverse DNS lookup 가 정상적으로 작동하면 해당 hostname 사용
Reverse DNS lookup 가 되지 않으면 첫 항목의 TCP/IP 클라이언트 주소 사용
--ssl-self-signed : 자체 서명된 인증서를 통해 네트워크 암호화
--no-ssl : ssl 암호화 사용하지 않음 (권장하지 않음, ssl-self-signed 사용 권장)
--auth : 노드에 연결하기 위한 인증방식 설정 [trust | password | scram-sha-256]
--skip-pg-hba : pg_hba 편집 하지 않기 (Default 는 pg_hba.conf 에 내용 추가됨)
--ssl-mode : 연결에 사용 할 ssl 모드
--ssl-ca-file : Postgres ssl_ca_file 의 경로 설정
--ssl-crl-file : Postgres ssl_crl_file 의 경로 설정
--server-key : Postgres ssl_key_file 의 경로 설정
--server-cert : Postgres ssl_cert_file 의 경로 설정
--run : 구성 완료 후 pg_autoctl 서비스 실행
[postgres@localhost data]$ pg_autoctl create monitor \
--pgctl /postgres/pgsql/bin/pg_ctl \
--pgdata /postgres/pgsql/data \
--ssl-self-signed
--pgport 5432 \
--auth trust
17:44:36 3928 INFO Using default --ssl-mode "require"
17:44:36 3928 INFO Using --ssl-self-signed: pg_autoctl will create self-signed
certificates, allowing for encrypted network traffic
17:44:36 3928 WARN Self-signed certificates provide protection against
eavesdropping; this setup does NOT protect against Man-In-The-Middle attacks nor
Impersonation attacks.
17:44:36 3928 WARN See https://www.postgresql.org/docs/current/libpq-ssl.html for
details
17:44:36 3928 INFO /usr/bin/openssl req -new -x509 -days 365 -nodes -text -out
/postgres/pgsql/data/server.crt -keyout /postgres/pgsql/data/server.key -subj
"/CN=localhost.localdomain"
17:44:36 3928 INFO Started pg_autoctl postgres service with pid 3932
17:44:36 3928 INFO Started pg_autoctl monitor-init service with pid 3933
17:44:36 3932 INFO /postgres/pgsql/bin/pg_autoctl do service postgres --pgdata
/postgres/pgsql/data -v
17:44:36 3937 INFO /postgres/pgsql/bin/postgres -D /postgres/pgsql/data -p 5432 -h
*
17:44:36 3932 INFO Postgres is now serving PGDATA "/postgres/pgsql/data" on port
5432 with pid 3937
17:44:36 3933 WARN NOTICE: installing required extension "btree_gist"
17:44:36 3933 INFO Granting connection privileges on ::1/128
17:44:36 3933 WARN Skipping HBA edits (per --skip-pg-hba) for rule: hostssl
"pg_auto_failover" "autoctl_node" ::1/128 trust
17:44:36 3933 INFO Your pg_auto_failover monitor instance is now ready on port
5432.
17:44:36 3933 INFO Monitor has been successfully initialized.
17:44:36 3928 WARN pg_autoctl service monitor-init exited with exit status 0
17:44:36 3932 INFO Postgres controller service received signal SIGTERM, terminating
17:44:36 3932 INFO Stopping pg_autoctl postgres service
17:44:36 3932 INFO /postgres/pgsql/bin/pg_ctl --pgdata /postgres/pgsql/data --wait
stop --mode fast
17:44:36 3928 INFO Stop pg_autoctl
2) Monitor 기동 및 정보 조회
[postgres@localhost data]$ pg_autoctl run --pgdata /postgres/pgsql/data &
[1] 3963
[postgres@localhost data]$ 17:45:30 3963 INFO Started pg_autoctl postgres service
with pid 3966
17:45:30 3963 INFO Started pg_autoctl listener service with pid 3967
17:45:30 3966 INFO /postgres/pgsql/bin/pg_autoctl do service postgres --pgdata
/postgres/pgsql/data -v
17:45:30 3967 INFO /postgres/pgsql/bin/pg_autoctl do service listener --pgdata
/postgres/pgsql/data -v
17:45:30 3967 INFO Managing the monitor at
postgres://autoctl_node@localhost.localdomain:5432/pg_auto_failover?sslmode=require
17:45:30 3967 INFO Reloaded the new configuration from
"/postgres/.config/pg_autoctl/postgres/pgsql/data/pg_autoctl.cfg"
17:45:30 3976 INFO /postgres/pgsql/bin/postgres -D /postgres/pgsql/data -p 5432 -h
*
17:45:30 3966 INFO Postgres is now serving PGDATA "/postgres/pgsql/data" on port
5432 with pid 3976
17:45:30 3967 INFO The version of extension "pgautofailover" is "2.0" on the
monitor
17:45:30 3967 INFO Contacting the monitor to LISTEN to its events.
[postgres@localhost data]$ pg_autoctl show uri
Type | Name | Connection String
-------------+---------+-------------------------------
monitor | monitor |
postgres://autoctl_node@localhost.localdomain:5432/pg_auto_failover?sslmode=require
formation | default |
참고사항
Citusdata PG_AUTO_FAILOVER의 저작권 및 라이선스는 아래의 링크를 참고 부탁드립니다.
https://github.com/hapostgres/pg_auto_failover/blob/main/LICENSE
https://github.com/hapostgres/pg_auto_failover/blob/main/NOTICE
또한, 해당 문서의 주요 목적은 테스트 환경 구현에 있습니다.
실제 환경에 적용 시 발생할 수 있는 문제에 대해서는 책임질 수 없다는 점 참고 부탁드립니다.