devlog_zz

postgreSQL 설치 - centos7 인터넷 안되는 환경 본문

DB

postgreSQL 설치 - centos7 인터넷 안되는 환경

YJ_SW 2022. 5. 10. 09:18
728x90

1. 사용자계정 추가 (root 계정에서)

adduser postgres
passwd postgres
password12#
su - postgres

https://www.postgresql.org/ftp/source/v12.0/

url에서 tar 다운로드하기

2. tar 압축해제

tar xvfz postgresql-12.0.tar.gz
cd postgresql-12.0

3. configure 파일 설정

sudo ./configure --prefix=/home/postgres/postgresql --without-readline --without-zlib

--prefix 로 설치할 디렉토리 경로 설정

4. postgresql 설치

sudo make
sudo make install

5. DB 설치

 cd /home/postgres/postgresql/bin
./initdb -D /home/postgres/postgresql/data
./postgres -D /home/postgres/postgresql/data >logfile 2>&1 & 
./psql test

/home/postgres/postgresql/data 경로에 DB 설치

6. DB 기동

./pg_ctl status -D /home/postgres/postgresql/data   //상태확인
./pg_ctl restart -D /home/postgres/pgsql/data   // 재기동 start,stop 가능

7. 외부 접속 허용

root계정으로 로그인해서

iptables -I INPUT 1 -p tcp --dport 5432 -j ACCEPT
iptables -I OUTPUT 1 -p tcp --dport 5432 -j ACCEPT

다시 postgrs 계정 로그인

vi /home/postgres/postgresql/data/postgresql.conf
listen_addresses = 'localhost' -> listen_addresses='*' 주석풀고 수정
( :/listen으로 검색 )
vi /home/postgres/postgresql/data/pg_hba.conf
host all all 0.0.0.0/0 password 추가

8. psql 접속

 cd /home/postgres/postgresql/bin
./psql

9. 접속 한뒤 database 생성 및 user 생성

postgres=# CREATE DATABASE {DBname};
postgres=# CREATE USER {UserName};
postgres=# ALTER USER {UserName}  WITH PASSWORD '{Password}';

해당 데이터 베이스 접속

\\connect {databaseName};

 

 

참고 : https://hyeonyeee.tistory.com/78  [hyeoneee's blog]

728x90
Comments