안녕하십니까 이제 막 사회에 입문하게된 초년생입니다.
처음으로 postgresql을 배우고 있습니다.
그래서 pgpool을 이용한 이중화라는 예제를 따라하고 있습니다.
pgpool-II install #
192.168.56.101 서버에 install
rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-1.noarch.rpm
yum update
yum install pgpool-II-pg94
4 postgresql9.4 install #
192.168.56.102, 192.168.56.103 서버에 install
rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-1.noarch.rpm
yum update
yum install postgresql94-server postgresql94-contrib
/usr/pgsql-9.4/bin/postgresql94-setup initdb
systemctl enable postgresql-9.4
systemctl start postgresql-9.4
firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
setsebool -P httpd_can_network_connect_db 1
su - postgres
psql
\password postgres
5 master 설정 #
.conf 파일이 있는 디렉토리로 이동
#locate pg_hba.conf
#/var/lib/pgsql/9.4/data/pg_hba.conf
cd /var/lib/pgsql/9.4/data/
pg_hba.conf파일에 replication 서버ip 등록
{{
vi pg_hba.conf
}}}
host replication postgres 192.168.56.102/32 trust
host replication postgres 192.168.56.103/32 trust
host all all 192.168.56.101/32 trust
host all all 192.168.56.1/32 trust
postgesql.conf 수정
vi postgresql.conf
wal_level=host_standby #archive로 설정하면 slave에 접근이 안됨
max_wal_senders=10 #multi slave node 수 설정
listen_addresses = '*'
archive_mode = on
archive_command = 'cp %p /var/lib/pgsql/9.4/ARCHIVE/%f'
# synchronous_standby_names = 'slave1' # 동기방식으로 복제할 경우
archive 로그 디렉토리 생성
mkdir /var/lib/pgsql/9.4/ARCHIVE
권한 변경
chown -R postgres.postgres /var/lib/pgsql
postgresql restart
su - postgres
cd /usr/pgsql-9.4/bin
./pg_ctl -D /var/lib/pgsql/9.4/data stop -m fast
./pg_ctl start -l /var/lib/pgsql/9.4/data/pg_log/postgres.log -D /var/lib/pgsql/9.4/data
or
systemctl restart postgresql-9.4
systemctl stop postgresql-9.4
6 slave 설정 #
master 복사
cd /
systemctl stop postgresql-9.4
mv /var/lib/pgsql/9.4/data /var/lib/pgsql/9.4/data_old
su - postgres
pg_basebackup -h 192.168.56.102 -p 5432 -U postgres -D /var/lib/pgsql/9.4/data --xlog --checkpoint=fast --progress
ls /var/lib/pgsql/9.4/data
exit
postgesql.conf 수정
cd /var/lib/pgsql/9.4/data/
vi postgresql.conf
wal_level = minimal
hot_standby = on
#archive_mode = on
#archive_command = 'cp %p /var/lib/pgsql/9.4/ARCHIVE/%f'
recovery.conf 생성
cd /var/lib/pgsql/9.4/data/
vi recovery.conf
restore_command = 'cp /var/lib/pgsql/9.4/ARCHIVE/%f %p'
archive_cleanup_command = 'pg_archivecleanup /var/lib/pgsql/9.4/ARCHIVE/ %r'
recovery_target_timeline = 'latest'
standby_mode = on
primary_conninfo = 'host=192.168.56.102 port=5432'
#application_name=slave1' # 동기방식으로 복제할 경우
권한 변경
chown -R postgres.postgres /var/lib/pgsql
postgresql restart
systemctl restart postgresql-9.4
7 동기화 확인 #
master 서버에서..
su - postgres
psql -x -c "create table replication_test(id int)"
psql -x -c "insert into replication_test(id) values(1)"
psql -x -c "select * from replication_test"
slave 서버에서..
su - postgres
psql -x -c "select * from replication_test"
master 서버에서..
su - postgres
이 내용이 제가 하고 있는 예제입니다.
그런데 이대로 실행하다 보니 슬레이브 서버를 실행하는데 계속 오류가 나서
혹시 제가 설정을 잘 못 한것인지 서버 옵션을 설정하는데 빠진 부분이나 추가할 부분이 있는 것인지
잘 모르겠어서 이렇게 질문하게 되었습니다.
마스터 서버 설정이 끝나고 stop start 해서 서버가 실행되는 부분 확인하고
슬레이브 서버에서 마스터 서버의 data를 복제받아
슬레이브 서버에서 바꾸라는 옵션을 바꾸고 서버를 stop하고 start 했더니
Job for postgresql.service failed because the control process exited with error code. See "systemctl status postgresql.service" and "journalctl -xe" for details.
[root@localhost ~]# systemctl status postgresql.service
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 화 2017-02-14 13:27:55 KST; 5s ago
Process: 2384 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=1/FAILURE)
Process: 2378 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
2월 14 13:27:54 localhost.localdomain systemd[1]: Starting PostgreSQL database server...
2월 14 13:27:54 localhost.localdomain pg_ctl[2384]: FATAL: WAL streaming (max_wal_senders > 0)...y"
2월 14 13:27:55 localhost.localdomain systemd[1]: postgresql.service: control process exited, c...=1
2월 14 13:27:55 localhost.localdomain systemd[1]: Failed to start PostgreSQL database server.
2월 14 13:27:55 localhost.localdomain systemd[1]: Unit postgresql.service entered failed state.
2월 14 13:27:55 localhost.localdomain systemd[1]: postgresql.service failed.
이런 오류가 나왔습니다.
1. 어떤 부분이 잘못되어서 나는 오류인가요 ?
2. 이 방법대로 하면 이중화할 수 있는 것인가요?
3. 마지막 부분에 psql로 질의를 하는 건 어떤 부분을 보여주기 위함인가요?
제가 아직 서툴어서 글쓰는 것에도 부족한 모습이 많습니다만
열심히 하려고 노력하고 있습니다! 작은 코멘트라도 주신다면 정말 감사하겠습니다!
혹시 몰라서 제가 설정한 부분을 올려 보겠습니다.
master ip 192.168.43.34/24
master pg_hba.conf 설정
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 192.168.43.34/24 trust
# IPv6 local connections:
host all all 192.168.43.1/24 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
host replication postgres 192.168.43.92/24 trust
host replication postgres 192.168.43.30/24 trust
master postgresql.conf 부분에서는
아카이브 부분 경로에 /var/lib/pgsql/ARCHIVE 로 바꾼거 외엔 똑같이 설정했습니다.
그리고 나서 서버를 stop 시키고 start 해서 정상 구동 확인 하고
slave pg_hba.conf 부분은
마스터 data에서 복제해오고 옵션을 바꾸지 않았기 때문에 master와 동일했습니다.
slave postgresql.conf 부분은
wal_level = minimal
hot_standby = on
#archive_mode = on
#archive_command = 'cp %p /var/lib/pgsql/ARCHIVE/%f'
동일하게 바꿨습니다.
slave recovery.conf 는
/usr/share/pgsql/recovery.conf.sample 을 cp로 복사해서 data안에 넣고 옵션을 바꿨습니다.
restore_command = 'cp /var/lib/pgsql/ARCHIVE/%f %p'
archive_cleanup_command = 'pg_archivecleanup /var/lib/pgsql/ARCHIVE/ %r'
recovery_target_timeline = 'latest'
standby_mode = on
primary_conninfo = 'host=192.168.43.92 port=5432'
끝마치고 chown으로 실행권한 주고 서버를 stop 하고 start 시켰습니다.
부족한 설명이지만 혹시 더 보고싶으신 부분은 댓글 남겨주시면 보여드리겠습니다.
부탁드리겠습니다. ㅠㅠ
|