일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- SWIFT
- kitura
- ubuntu
- ssh
- perfect
- rethinkdb
- appium server
- 실행권한
- Materials
- ftp
- appium
- nmap
- nohup
- STF_PortForwarding
- Jupyter Notebook
- 28015
- port forwarding
- nGrinder
- insert
- centos
- GoCD
- STF
- openpyxl
- Jupyter
- PYTHON
- sshpass
- create table
- postgresql
- postgres
- mysql
- Today
- Total
don't stop believing
PostgreSQL 설치 (on CentOS7) 본문
CentOS7에 PostgreSQL을 설치하겠습니다.
OS 버전부터 확인하고 가겠습니다.
12345678910$ cat /etc/os-releaseNAME="Amazon Linux"VERSION="2"ID="amzn"ID_LIKE="centos rhel fedora"VERSION_ID="2"PRETTY_NAME="Amazon Linux 2"ANSI_COLOR="0;33"CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"HOME_URL="https://amazonlinux.com/"
AWS EC2 인스턴스 입니다. centos rhel fedora네요.
먼저 yum update를 해줍니다.
1$ sudo yum update -y
Postgresql을 설치합니다.
1$ sudo yum install -y postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs
Postgresql을 초기화해 줍니다.
1$ sudo service postgresql initdb
Postgresql을 시작해줍니다. 그리고 서버 재시작 후에도 자동으로 실행될 수 있도록 설정해 줍니다.
12$ sudo systemctl start postgresql$ sudo systemctl enable postgresql
이제 postgres계정으로 postgresql에 접속합니다.
123456$ sudo -u postgres psqlcould not change directory to "/home/ec2-user"psql (9.2.24)Type "help" for help.postgres=#
먼저 해줄것은 postgresql 기본 계정인 postgres의 비번을 설정하는 것입니다.
저는 ngle123456이라고 비번을 정했습니다.
12postgres=# ALTER USER postgres WITH PASSWORD 'ngle123456';ALTER ROLE
이제 실제 사용할 계정과 database를 만들어 줍니다.
계정은 ngle이라고 하고 superuser 권한을 줍니다. 그리고 비번도 정해줍니다.
1234postgres=# CREATE USER ngle SUPERUSER;CREATE ROLEpostgres=# ALTER USER ngle WITH PASSWORD 'ngle123456';ALTER ROLE
database를 만들고 ngle계정에 권한을 줍니다. 저는 ngledb라는 database를 만들었습니다.
database를 만들때 한가지 주의할 점은 encoding입니다. 기본 encoding은 SQL_ASCII입니다. UTF8로 지정하려면 database를 생성할 때 설정해 줘야 합니다. 그렇지 않으면 database를 삭제하고 다시 만들어야하는 귀찮음이 발생합니다. 그리고 UTF8로 지정하려면 template을 template0으로 지정해야 합니다.
12postgres=# create database ngledb with owner ngle encoding 'UTF8' template template0;CREATE DATABASE
database 생성과 권한(소유권)변경이 잘 되었는지 \l 명령으로 확인해 봅니다.
1234567891011postgres=# \lList of databasesName | Owner | Encoding | Collate | Ctype | Access privileges------------+----------+-----------+---------+-------+-----------------------ngledb | ngle | UTF8 | C | C |postgres | postgres | SQL_ASCII | C | C |template0 | postgres | SQL_ASCII | C | C | =c/postgres +| | | | | postgres=CTc/postgrestemplate1 | postgres | SQL_ASCII | C | C | =c/postgres +| | | | | postgres=CTc/postgres(4 rows)
이번에는 외부에서 postgresql에 접속할 수 있도록 설정합니다.
먼저 pg_hba.conf 파일을 수정하겠습니다. 파일을 열고 아래쪽에 있는 # IPv4 local connections: 부분을 아래와 같이 수정합니다.
1234567# "local" is for Unix domain socket connections onlylocal all all peer# IPv4 local connections:host all ngle 0.0.0.0/0 md5host all postgres 0.0.0.0/0 md5# IPv6 local connections:host all all ::1/128 ident
다음으로 postgresql.conf 파일을 수정합니다.
postgresql.conf 파일의 59라인의 내용(#listen_addresses = 'localhost')을 아래와 같이 어디에서든 접속할 수 있도록 수정합니다.
1listen_addresses = '*'
두 개의 conf 파일이 수정되었다면 postgresql을 재시작해 줍니다.
1$ sudo systemctl restart postgresql
여기까지 CentOS에 postgresql 설치였습니다.
'Database > PostgreSQL' 카테고리의 다른 글
Query를 Log 파일에 남겨 봅시다. (0) | 2018.03.06 |
---|---|
외부 서버에서 postgresql 접속하기 (2) | 2017.09.27 |
sql 파일 실행시키기 (0) | 2017.09.27 |
alter table 사용하기 (0) | 2017.09.26 |
Table 관련 기본 다루기 (0) | 2017.09.26 |