회원가입

PostgreSQL 구축 방법 Amazon Linux 2 EC2

NULL 2022-03-26

 

1. 서버로 SSH 터널링

# 서버로 ssh 터널링
ssh -i 비밀키.pem 유저명@서버주소

 

2. PostgreSQL 13 다운로드

# RHEL 7용 EPEL 릴리스 패키지를 설치하고 EPEL 리포지토리를 활성화합니다.
sudo amazon-linux-extras install epel -y

# pgdg13 다운로드 설정
sudo tee /etc/yum.repos.d/pgdg.repo<<EOF
[pgdg13]
name=PostgreSQL 13 for RHEL/CentOS 7 - x86_64
baseurl=http://download.postgresql.org/pub/repos/yum/13/redhat/rhel-7-x86_64
enabled=1
gpgcheck=0
EOF

# postgresql 설치
sudo yum install postgresql13 postgresql13-server

# 데이터베이스 설정
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb

# systemctl enable 설정
sudo systemctl enable --now postgresql-13

# 설치한 postgresql 확인
systemctl status postgresql-13

 

3. 데이터베이스 접속 및 DB 생성

# postgresql 유저로 로그인
sudo su - postgres

# postgresql 접속
psql

# 데이터베이스 생성
postgres=# CREATE DATABASE testdb;
CREATE DATABASE

 

4. 데이터베이스 유저 생성

# 유저 생성
create user careerwallet with encrypted password '1q2w3e4r!';

# 유저 권한
grant all privileges on database 디비명 to 유저명;

# 디비 owner 변경
ALTER DATABASE 디비명 OWNER TO 계정명

 

5. postgresql 외부에서 접근 가능하게 만들기

cd /var/lib/pgsql/13/data
vi postgresql.conf

# 아래 사진 처럼 수정 마치고 서비스 재시작
sudo systemctl restart postgresql-13

CONNECTIONS AND AUTHENTICATION 부분 수정

postgresql.conf

 

6. postgresql 외부에서 해당 비밀번호로 접근할 수 있도록 설정

cd /var/lib/pgsql/13/data
vi pg_hba.conf

# 아래 사진 처럼 수정 마치고 서비스 재시작
sudo systemctl restart postgresql-13

method 부분은 위에 자주 사용되는 method로 변경

0 0
뼈와 살
프로젝트를 혹은 직장에서 일하면서 겪게 되는 Blocker, 문제 등 나에게 뼈와 살이 되어 성장시켜주게 한 문제점을 어떻게 해결했는지를 기록하는 게시판이다.
Yesterday: 750
Today: 558