• 2020. 8. 28.

    by. 윈썸지니

    반응형

    포스팅의 목적은 PostgreSQL 데이터베이스 이중화 구성을 하려는 과정으로 PostgreSQL DB 설치 과정부터 순서대로 진행합니다.

    따라서 본 포스팅은 첫번째로 PosgreSQL DB의 설치 과정을 내용을 담고 있습니다.

     

    PostgreSQL은 라이선스가 무료이기 때문에 요즘 기업에서도 많이 사용되고 있습니다.

     

    본 테스트 환경은 아래와 같습니다.

    OS : Red Hat Linux 7.x

    PostgreSQL version : 10

    이중화 구성은 Active-Standby 로 구성합니다.

     

    1. 설치 이미지 다운로드

    먼저 설치를 위해서 이미지를 다운로드 합니다.

    https://www.postgresql.org/download/

    에서 설치 이미지를 다운로드 해 주세요.

    다운로드 홈페이지는 자주 변경되니 아래 사진과 동일하지 않을 수 있습니다.

     

    Linux를 선택하면 아래 리눅스 종류 들이 보입니다. 선택해 주세요.

     

    위에서 Red Hat을 선택하면 아래의 화면으로 이동하는데 설치 버전 및 설치된 OS 에 대한 내용인 1, 2, 3을 선택하면 4번에 설치하는 스크립트(명령어)를 보여줍니다.

     

    위에서 "copy script"를 하여 메모장등에 저장해 놓으세요.

     

    2. 설치할 OS 환경 설정

     - hostname 설정하기

       서버명이 hosts 파일에 설정이 안되어 있으면 설정해 주세요.

       이중화이므로 2대를 설정해 줍니다.  

        sudo vi /etc/hosts 로 서버명과 IP를 설정 합니다.

     

    아래는 예제 입니다. 각각 구성해 주세요.

    # Primary(Active) Server

    192.168.137.101 postgres1    postgres1.itmsg.co.kr

     

    # Secondary (Standby) Server

    192.168.137.102 postgres2    postgres2.itmsg.co.kr

     

     - SELinux 해제

    각 서버에서 다음과 같이 하여 SELinux를 해제해 주세요.

    # sudo vi /etc/sysconfig/selinux

    SELINUX=disabled

    # reboot

     

    3. PostgreSQL DB 설치하기

     

    이제 설치할 준비가 되었으니 이전에 복사해 둔 스크립트를 이용하여 설치합니다.

     

    3.1 RPM 레파지토리 설치

     

    sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

     

    Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager

    This system is not registered with an entitlement server. You can use subscription-manager to register.

    pgdg-redhat-repo-latest.noarch.rpm                                                                       | 5.8 kB  00:00:00

    Examining /var/tmp/yum-root-XcgV4p/pgdg-redhat-repo-latest.noarch.rpm: pgdg-redhat-repo-42.0-5.noarch

    Marking /var/tmp/yum-root-XcgV4p/pgdg-redhat-repo-latest.noarch.rpm to be installed

    Resolving Dependencies

    --> Running transaction check

    ---> Package pgdg-redhat-repo.noarch 0:42.0-5 will be installed

    --> Finished Dependency Resolution

    file:///run/media/root/RHEL-7.6%20Server.x86_64/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /run/media/root/RHEL-7.6%20Server.x86_64/repodata/repomd.xml"

    Trying other mirror.

     

    Dependencies Resolved

     

    =====================================================================================================

     Package            Arch             Version             Repository                    Size

    =====================================================================================================

    Installing:

     pgdg-redhat-repo  noarch             42.0-5    /pgdg-redhat-repo-latest.noarch         7.5 k

     

    Transaction Summary

    =====================================================================================================

    Install  1 Package

     

    Total size: 7.5 k

    Installed size: 7.5 k

    Is this ok [y/d/N]: y

    Downloading packages:

    Running transaction check

    Running transaction test

    Transaction test succeeded

    Running transaction

    Warning: RPMDB altered outside of yum.

      Installing : pgdg-redhat-repo-42.0-5.noarch                                                                               1/1

    file:///run/media/root/RHEL-7.6%20Server.x86_64/repodata/ba86625b825e4bea5f6ab2b3e83c2cb076087507815be7e35da6d8bf697829dd-productid.gz: [Errno 14] curl#37 - "Couldn't open file /run/media/root/RHEL-7.6%20Server.x86_64/repodata/ba86625b825e4bea5f6ab2b3e83c2cb076087507815be7e35da6d8bf697829dd-productid.gz"

    Trying other mirror.

      Verifying  : pgdg-redhat-repo-42.0-5.noarch                                                                               1/1

     

    Installed:

      pgdg-redhat-repo.noarch 0:42.0-5

     

    Complete!

     

    3.2 PostgreSQL 설치

    sudo yum install -y postgresql10-server

     

    [sudo] user1 암호:

    Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager

    This system is not registered with an entitlement server. You can use subscription-manager to register.

    file:///run/media/root/RHEL-7.6%20Server.x86_64/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /run/media/root/RHEL-7.6%20Server.x86_64/repodata/repomd.xml"

    Trying other mirror.

    Resolving Dependencies

    --> Running transaction check

    ---> Package postgresql10-server.x86_64 0:10.11-1PGDG.rhel7 will be installed

    --> Finished Dependency Resolution

     

    Dependencies Resolved

     

    =====================================================================================================

     Package                     Arch           Version                  Repository               Size

    =====================================================================================================

    Installing:

     postgresql10-server        x86_64     10.11-1PGDG.rhel7             pgdg10                  4.5 M

     

    Transaction Summary

    =====================================================================================================

    Install  1 Package

     

    Total download size: 4.5 M

    Installed size: 18 M

    Is this ok [y/d/N]: y

    Downloading packages:

    postgresql10-server-10.11-1PGDG.rhel7.x86_64.rpm                                                         | 4.5 MB  00:00:03

    Running transaction check

    Running transaction test

    Transaction test succeeded

    Running transaction

      Installing : postgresql10-server-10.11-1PGDG.rhel7.x86_64                              1/1

    file:///run/media/root/RHEL-7.6%20Server.x86_64/repodata/ba86625b825e4bea5f6ab2b3e83c2cb076087507815be7e35da6d8bf697829dd-productid.gz: [Errno 14] curl#37 - "Couldn't open file /run/media/root/RHEL-7.6%20Server.x86_64/repodata/ba86625b825e4bea5f6ab2b3e83c2cb076087507815be7e35da6d8bf697829dd-productid.gz"

    Trying other mirror.

      Verifying  : postgresql10-server-10.11-1PGDG.rhel7.x86_64                              1/1

     

    Installed:

      postgresql10-server.x86_64 0:10.11-1PGDG.rhel7

     

    Complete!

     

    3.3 DB 초기화, 서비스 등록, PostgreSQL 기동

    이 항목은 선택 사항입니다. 하지만 편한 기능이므로 해 주시는 것이 좋습니다.

    아래 명령어들을 실행해 주세요.

    /usr/pgsql-10/bin/postgresql-10-setup initdb

    systemctl enable postgresql-10

    systemctl start postgresql-10

     

    3.4 client 설치

    스크립트에는 없지만 client도 설치 합니다.

    sudo yum install postgresql10

     

    [sudo] user1 암호:

    Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager

    This system is not registered with an entitlement server. You can use subscription-manager to register.

    pgdg10                                                                                                   | 3.6 kB  00:00:00   pgdg11                                                                                                   | 3.6 kB  00:00:00   pgdg12                                                                                                   | 3.6 kB  00:00:00   pgdg94                                                                                                   | 3.6 kB  00:00:00   pgdg95                                                                                                   | 3.6 kB  00:00:00   pgdg96                                                                                                   | 3.6 kB  00:00:00

    file:///run/media/root/RHEL-7.6%20Server.x86_64/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /run/media/root/RHEL-7.6%20Server.x86_64/repodata/repomd.xml"

    Trying other mirror.

    (1/12): pgdg12/7Server/x86_64/group_gz                                      |  245 B  00:00:01

    (2/12): pgdg11/7Server/x86_64/group_gz                                      |  245 B  00:00:01

    (3/12): pgdg10/7Server/x86_64/group_gz                                      |  245 B  00:00:01

    (4/12): pgdg94/7Server/x86_64/group_gz                                      |  247 B  00:00:00

    (5/12): pgdg95/7Server/x86_64/group_gz                                      |  249 B  00:00:00

    (6/12): pgdg12/7Server/x86_64/primary_db                                    | 127 kB  00:00:01

    (7/12): pgdg96/7Server/x86_64/group_gz                                      |  249 B  00:00:00

    (8/12): pgdg94/7Server/x86_64/primary_db                                    | 384 kB  00:00:01

    (9/12): pgdg10/7Server/x86_64/primary_db                                    | 396 kB  00:00:03

    (10/12): pgdg11/7Server/x86_64/primary_db                                   | 351 kB  00:00:03

    (11/12): pgdg96/7Server/x86_64/primary_db                                   | 404 kB  00:00:00

    (12/12): pgdg95/7Server/x86_64/primary_db                                   | 394 kB  00:00:01

    Resolving Dependencies

    --> Running transaction check

    ---> Package postgresql10.x86_64 0:10.11-1PGDG.rhel7 will be installed

    --> Processing Dependency: postgresql10-libs(x86-64) = 10.11-1PGDG.rhel7 for package: postgresql10-10.11-1PGDG.rhel7.x86_64

    --> Processing Dependency: libpq.so.5()(64bit) for package: postgresql10-10.11-1PGDG.rhel7.x86_64

    --> Running transaction check

    ---> Package postgresql10-libs.x86_64 0:10.11-1PGDG.rhel7 will be installed

    --> Finished Dependency Resolution

     

    Dependencies Resolved

     

    =====================================================================================================

     Package                Arch            Version                      Repository               Size

    =====================================================================================================

    Installing:

     postgresql10           x86_64       10.11-1PGDG.rhel7                pgdg10                  1.6 M

    Installing for dependencies:

     postgresql10-libs      x86_64       10.11-1PGDG.rhel7                 pgdg10                  356 k

     

    Transaction Summary

    =====================================================================================================

    Install  1 Package (+1 Dependent package)

     

    Total download size: 1.9 M

    Installed size: 9.7 M

    Is this ok [y/d/N]: y

    Downloading packages:

    경고: /var/cache/yum/x86_64/7Server/pgdg10/packages/postgresql10-libs-10.11-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY

    Public key for postgresql10-libs-10.11-1PGDG.rhel7.x86_64.rpm is not installed

    (1/2): postgresql10-libs-10.11-1PGDG.rhel7.x86_64.rpm                            | 356 kB  00:00:02

    (2/2): postgresql10-10.11-1PGDG.rhel7.x86_64.rpm                                 | 1.6 MB  00:00:02

    -----------------------------------------------------------------------------------------------------

    Total                                                                                           772 kB/s | 1.9 MB  00:00:02

    Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG

    Importing GPG key 0x442DF0F8:

     Userid     : "PostgreSQL RPM Building Project <pgsqlrpms-hackers@pgfoundry.org>"

     Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8

     Package    : pgdg-redhat-repo-42.0-5.noarch (installed)

     From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG

    Is this ok [y/N]: y

    Running transaction check

    Running transaction test

    Transaction test succeeded

    Running transaction

      Installing : postgresql10-libs-10.11-1PGDG.rhel7.x86_64                               1/2

      Installing : postgresql10-10.11-1PGDG.rhel7.x86_64                                    2/2

    file:///run/media/root/RHEL-7.6%20Server.x86_64/repodata/ba86625b825e4bea5f6ab2b3e83c2cb076087507815be7e35da6d8bf697829dd-productid.gz: [Errno 14] curl#37 - "Couldn't open file /run/media/root/RHEL-7.6%20Server.x86_64/repodata/ba86625b825e4bea5f6ab2b3e83c2cb076087507815be7e35da6d8bf697829dd-productid.gz"

    Trying other mirror.

      Verifying  : postgresql10-10.11-1PGDG.rhel7.x86_64                                     1/2

      Verifying  : postgresql10-libs-10.11-1PGDG.rhel7.x86_64                                2/2

     

    Installed:

      postgresql10.x86_64 0:10.11-1PGDG.rhel7

     

    Dependency Installed:

      postgresql10-libs.x86_64 0:10.11-1PGDG.rhel7

     

    Complete!

     

    이중화 구성을 위한 PostgreSQL DB 를 설치하는 과정 입니다.

    내용이 길어져서 다음 포스팅에서 이중화 구성을 하는 내용과 장애 발생시 복구하는 failback에 대한 내용을 다룹니다.

    반응형