[Postgresql] Pgpool-II 설정 (4)
Pgpool 수정하여 실행까지
지난 pgpool 설치 후 conf 수정하여 pgpool을 동작 해보는거 까지 해보겠다!
# pgpool 설치
Pgpool-II + postgresql 이중화 Master-Slave 구축 (3)
PostgreSQL의 기능으로 Master-Slave 이중화 구현의 단점을 Pgpool을 이용하여 극복해보자 # PostgreSQL 이중화가 안되어있다면 https://0409kdk.tistory.com/2 Postgresql-15 Master - Slave 설정 및 구축- (1) 이번 프로젝트
0409kdk.tistory.com
1.Pgpool-II conf 수정
먼저 postgres 계정으로 접속한다.
su - postgres
pgpool.conf 파일을 수정한다
vi /etc/pgpool-II/pgpool.conf
수정할 내용
backend_clustering_mode = 'streaming_replication'
listen_addresses = '*'
port = 5432
unix_socket_directories = '/var/run/postgresql'
pcp_listen_addresses = '*'
pcp_port = 9898
pcp_socket_dir = '/var/run/postgresql'
backend_hostname0 = 'Master IP'
backend_port0 = Master Port
backend_weight0 = 1
backend_data_directory0 = '/database/postgres/data' -- DB_1번 db 디렉토리 경로
backend_flag0 = 'ALLOW_TO_FAILOVER'
backend_hostname1 = 'Slave IP'
backend_port1 = Slave Port
backend_weight1 = 1
backend_data_directory1 = '/database/postgres/data' -- DB_2번 db 디렉토리 경로
backend_flag1 = 'ALLOW_TO_FAILOVER'
sr_check_user = 'replication'
sr_check_password = 'replica'
enable_pool_hba = on
num_init_children = 32
max_pool = 4
log_destination = 'stderr'
logging_collector = on
log_directory = '/var/log/pgpool_log'
log_filename = 'pgpool-%Y-%m-%d_%H%M%S.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 10MB
load_balance_mode = on
failover_command = '/etc/pgpool-II/failover.sh %d %h %p %D %m %H %M %P %r %R %N %S'
follow_primary_command = '/etc/pgpool-II/follow_primary.sh %d %h %p %D %m %H %M %P %r %R'
failback_command = ' '
health_check_period = 5
health_check_timeout = 30
health_check_user = 'replication'
health_check_password = 'replica'
health_check_max_retries = 3
2. pool_hba.conf 수정
vi /etc/pgpool-II/pool_hba.conf
맨밑줄에 작성한다.
host all all 0.0.0.0/32 trust
전체다 허용해줬다.
이설정이 귀찮다면 위 pgpool.conf 에서 enable_pool_hba = off 로 설정한다.
3. pgpool-II 실행
pgpool -f /etc/pgpool-II/pgpool.conf -F /etc/pgpool-II/pcp.conf -n -D -d
pgpool 옵션
-f : pgpool.conf 파일의 위치
-F : pcp.conf 파일의 위치
-n : 백그라운드 실행 x
-d : Debug mode
-D : pgpool_status file Discard
conf 파일들이 기본경로인 /etc/pgool-II 경로에 있다면 굳이 -f -F 옵션은 안주어도 된다.
pgpool이 정상 동작하는지 체크해보자
psql -c "show pool_nodes;"
# 위 명령어는 default을 이용해서 한것 아래는 풀 버전
# psql -h pgpool_IP -p pgpool_Port -U postgres -c "show pool_nodes;"
node id 0 -> Master
node id 1 -> Slave
둘다 up 상태로 정상적으로 동작하고 있다!
4. log파일
cd /var/log/pgpool_log
이 경로에
로그파일이 존재한다.
tail -f /var/log/pgpool_log/pgpool-2023-12-11.log
로그 확인 하는법
pgpool로 이중화 구성을 완료하였다!
하지만 이거로 만족하기엔 아쉽다.
다음 글에는 failover을 이용하여 primary (master) 가 다운됐을 때 standby(Slave)가 승격 되어 primary(master) 가 되게끔 해보겠다!