개발 D/Postgresql

[Postgresql] postgresql 이중화 Master-Slave 구축 - 설치 (1)

마음닝 2023. 12. 8. 15:28

 

이번 프로젝트에서 DB 가용성을 위해 이중화를 해야한다고 해서 Postgresql의 Master - Slave 기능을 이용하여 이중화 구성을 해보려고 한다.

 

OS : Redhat8
DB : Postgresql-15
Server : 2대

 

 

 

OS는 프로젝트 하는곳이 Redhat을 사용했어서 Redhat8 로 진행하였지만 Ubuntu도 상관 없다.

 

테스트를 위하여 Oracle VM VirtualBox을 이용하여 

 

Redhat8 서버를 2개 구축하여 동시에 진행하였다.

 

SMALL

 

Postgresql-15 설치 ( Master / Slave 두 서버 설치)

  • Redhat
# Install the repository RPM:
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Disable the built-in PostgreSQL module:
sudo dnf -qy module disable postgresql

# Install PostgreSQL:
sudo dnf install -y postgresql15-server

 

  • Ubuntu
# Create the file repository configuration:
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# Import the repository signing key:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

# Update the package lists:
sudo apt-get update

# Install the latest version of PostgreSQL.
# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql':
sudo apt-get -y install postgresql-15

 

 

 

패키지 설치가 잘된거 같다.

 

Master 서버 에서만 DB을 init 시키자 ( Slave는 추후 복제할 예정)

sudo /usr/pgsql-15/bin/postgresql-15-setup initdb

 

이렇게 하면 Default 경로에 DB 가 init이 되지만 (Default 경로 = /var/lib/pgsql/15/data)

프로젝트에서 요구한 내용은 DB 폴더가 다른경로에 있기를 원했다.

그래서 새로운 폴더를 만들고 그안에 initdb를 적용 하겠다. ( Default 경로 쓰실분은 폴더 생성 안하시면 됩니다.)

 

 

새로운 폴더 경로 /database/postgres/data로 만들고

권한 설정을 하였다.

 

우선 루트 폴더에 /database 폴더를 만든다.

 

postgres 계정으로 접속한다.

처음 접속할 때 비밀번호를 설정해야한다.

sudo passwd postgres

 

postgres 계정 접속

su - postgres

 

마저 폴더를 만들었다.

 

이제 이 폴더 경로에 initdb를 한다.

/usr/pgsql-15/bin/pg_ctl -D /database/postgres/data initdb

 

/usr/pgsql-15/bin/pg_ctl -D /database/postgres/data start

# Default 경로로 설정 하신 분
/usr/pgsql-15/bin/pg_ctl -D /var/lib/pgsql/15/data start

 

이제 이 명령어로 postgresql 을 실행하면 DB가 실행된다.

 

 

 

postgresql.conf 설정과 Master - Slave 구성은 다음 글에 이어서 하겠다.

 

https://0409kdk.tistory.com/3

 

Postgresql-15 Master - Slave 설정 및 구축- (2)

Postgresql 설치 후 Postgresql.conf 설정 및 Master - Slave 구축 지난 글에 이어서 postgresql Master - Slave를 구축해보겟다. 지난 글 : https://0409kdk.tistory.com/2 Postgresql-15 Master - Slave 설정 및 구축- (1) 이번 프로젝

0409kdk.tistory.com

 

300x250
LIST