DBDBDEEP

CentOS8 버전에서 Postgre DB설치를 진행한 이력을 정리

 

굵은색으로 강조된 부분이 커맨드이고 별도의 주석으로 설명을 첨부했습니다.

설치된 환경은 아래와 같습니다.

CentOS Linux release 8.2.2004 (Core) 
Derived from Red Hat Enterprise Linux 8.2 (Source)
NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"

[root@192 ~]# yum install -y postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs
마지막 메타 데이터 만료 확인 : 1 day, 2:50:17 전에 2020년 07월 26일 (일) 오후 09시 03분 58초.
Dependencies resolved.
================================================================================
Package Arch Version Repo Size
================================================================================
Installing:
libpq-devel x86_64 12.1-3.el8 AppStream 98 k
postgresql x86_64 10.6-1.module_el8.0.0+15+f57f353b AppStream 1.5 M
postgresql-contrib x86_64 10.6-1.module_el8.0.0+15+f57f353b AppStream 805 k
postgresql-docs x86_64 10.6-1.module_el8.0.0+15+f57f353b AppStream 12 M
postgresql-server x86_64 10.6-1.module_el8.0.0+15+f57f353b AppStream 5.1 M
Installing dependencies:
libpq x86_64 12.1-3.el8 AppStream 195 k
uuid x86_64 1.6.2-42.el8 AppStream 63 k
Enabling module streams:
postgresql 10

Transaction Summary

설치 7 Packages

Total download size: 20 M
Installed size: 63 M
패키지 다운로드중:
(1/7): libpq-devel-12.1-3.el8.x86_64.rpm 121 kB/s | 98 kB 00:00
(2/7): libpq-12.1-3.el8.x86_64.rpm 178 kB/s | 195 kB 00:01
(3/7): postgresql-contrib-10.6-1.module_el8.0.0 709 kB/s | 805 kB 00:01
(4/7): postgresql-10.6-1.module_el8.0.0+15+f57f 624 kB/s | 1.5 MB 00:02
(5/7): uuid-1.6.2-42.el8.x86_64.rpm 577 kB/s | 63 kB 00:00
(6/7): postgresql-docs-10.6-1.module_el8.0.0+15 4.2 MB/s | 12 MB 00:02
(7/7): postgresql-server-10.6-1.module_el8.0.0+ 1.0 MB/s | 5.1 MB 00:05


합계 2.4 MB/s | 20 MB 00:08
트랜잭션 점검 실행 중
트랜잭션 검사가 성공했습니다.
트랜잭션 테스트 실행 중
트랜잭션 테스트가 완료되었습니다.
거래 실행 중
준비 중입니다 : 1/1
Installing : libpq-12.1-3.el8.x86_64 1/7
Installing : postgresql-10.6-1.module_el8.0.0+15+f57f353b.x86_64 2/7
Installing : uuid-1.6.2-42.el8.x86_64 3/7
스크립틀릿 실행: uuid-1.6.2-42.el8.x86_64 3/7
Installing : postgresql-contrib-10.6-1.module_el8.0.0+15+f57f353b.x 4/7
Installing : postgresql-docs-10.6-1.module_el8.0.0+15+f57f353b.x86_ 5/7
스크립틀릿 실행: postgresql-server-10.6-1.module_el8.0.0+15+f57f353b.x8 6/7
Installing : postgresql-server-10.6-1.module_el8.0.0+15+f57f353b.x8 6/7
스크립틀릿 실행: postgresql-server-10.6-1.module_el8.0.0+15+f57f353b.x8 6/7
Installing : libpq-devel-12.1-3.el8.x86_64 7/7
스크립틀릿 실행: libpq-devel-12.1-3.el8.x86_64 7/7
확인 중 : libpq-12.1-3.el8.x86_64 1/7
확인 중 : libpq-devel-12.1-3.el8.x86_64 2/7
확인 중 : postgresql-10.6-1.module_el8.0.0+15+f57f353b.x86_64 3/7
확인 중 : postgresql-contrib-10.6-1.module_el8.0.0+15+f57f353b.x 4/7
확인 중 : postgresql-docs-10.6-1.module_el8.0.0+15+f57f353b.x86_ 5/7
확인 중 : postgresql-server-10.6-1.module_el8.0.0+15+f57f353b.x8 6/7
확인 중 : uuid-1.6.2-42.el8.x86_64 7/7
Installed products updated.

설치됨:
libpq-12.1-3.el8.x86_64
libpq-devel-12.1-3.el8.x86_64
postgresql-10.6-1.module_el8.0.0+15+f57f353b.x86_64
postgresql-contrib-10.6-1.module_el8.0.0+15+f57f353b.x86_64
postgresql-docs-10.6-1.module_el8.0.0+15+f57f353b.x86_64
postgresql-server-10.6-1.module_el8.0.0+15+f57f353b.x86_64
uuid-1.6.2-42.el8.x86_64

완료되었습니다!
[root@192 ~]#
[root@192 ~]# service postgresql initdb
Hint: the preferred way to do this is now "/usr/bin/postgresql-setup --initdb --unit postgresql"

  • Initializing database in '/var/lib/pgsql/data'
  • Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log
    [root@192 ~]#
    [root@192 ~]#
    [root@192 ~]#
    [root@192 ~]# systemctl start postgresql //DB 기동
    [root@192 ~]# systemctl enable postgresql //OS재시작시 DB기동 등록
    Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service.
    [root@192 ~]#
    [root@192 ~]#
    [root@192 ~]#
    [root@192 ~]# sudo -u postgres psql //DB접속
    could not change directory to "/root": 허가 거부
    psql (10.6)
    Type "help" for help.

postgres=# ALTER USER postgres WITH PASSWORD 'pwd3033'; //postgres 암호변경**
ALTER ROLE
postgres=#  CREATE USER test1 SUPERUSER; //별도 유저 생성

CREATE ROLE
postgres=# ALTER USER test1 WITH PASSWORD 'pwd3033'; //별도 유저 암호 설정
ALTER ROLE
postgres=# create database postdev with owner test1 encoding 'UTF8' template template0;
CREATE DATABASE     //UTF8이 널리쓰이므로 DB생성시 UTF8로 만들어준다.
postgres=#
postgres=# \l   //확인해본다.
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileg
es
-----------+----------+----------+-------------+-------------+------------------


postdev | test1 | UTF8 | ko_KR.UTF-8 | ko_KR.UTF-8 |
postgres | postgres | UTF8 | ko_KR.UTF-8 | ko_KR.UTF-8 |
template0 | postgres | UTF8 | ko_KR.UTF-8 | ko_KR.UTF-8 | =c/postgres

  • | | | | | postgres=CTc/post
    gres
    template1 | postgres | UTF8 | ko_KR.UTF-8 | ko_KR.UTF-8 | =c/postgres
  • | | | | | postgres=CTc/post
    gres
    (4 rows)

postgres=#

#참고

postgre 포트는 5432

 

#postgre 서비스 재시작 명령어

systemctl restart postgresql

 

#외부에서 접속 안될때

/var/lib/pgsql/data/postgresql.conf 파일내용중
listen_addresses = '*'로 설정한다.

postgresql.conf

/var/lib/pgsql/data/pg_hba.conf 파일을 아래와 같이 설정한다.

pg_hba.conf

 

systemctl restart postgresql 서비스 재시작

[root@192 /]# netstat -nltp | grep 5432

postgre 외부접속 상태확인

위 그림과 같이 뜨면 외부에서 접속될수 있다.

 

그래도 외부에서 접속이 안된다면?

1. 방화벽 제거나 요청을 진행한다.

systemctl stop firewalld      //CentOS 방화벽 서비스 해제

systemctl disable firewalld  //CentOS 재기동시에도 방화벽 서비스 해제

서버 재부팅

2. selinux 보안 규칙제거(보안 관리가 높은 환경에서는 비추하지만 해제 안하면 제약이 너무많다.)

 /etc/sysconfig/selinux
SELINUX=enforcing 을 #으로 주석처리한다.

SELINUX=disabled 로 변경후 저장

Centos selinux 끄기

서버 재부팅한다.

 

외부접속확인 되었다면

CentOS8 PostgreSQL 설치를 마친다.

이 글을 공유합시다

facebook twitter googleplus kakaoTalk kakaostory naver band