2016/06/25

Virtualbox上のUbuntu16.4にPostgresql 9.5をインストールする

MACのVirtualbox上のUbuntu16.4にPostgresql9.5をインストールする。
以下のSTEPをサーバー上で行う。(SSHでも可能)
#1# インストール
#2# Postgresqlを開始する
#3# postgresの初期パスワードを設定する
#4# postgres でログインして、DB作成と別userでもログインできるようにする

#5# クライアントからの接続を許可する

# POSTGRESQLのインストールからクライアント接続するまで(ubuntu 16.4 LTS on VIRTUALBOX with MAC)
#1# INSTALL
$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
$ wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install postgresql postgresql-contrib
#2# START
$ sudo /etc/init.d/postgresql start
$ sudo /etc/init.d/postgresql status
#3# SET initial password for postgres
$ sudo passwd postgres
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
#4# login as postgres and create DB and user
$ su - postgres ## userをpostgresに変更する
$ createdb <dbname> ## dbを作成する
$ psql <dbname> ## dbにpostgresでログインする
psql (9.5.3)
"help" でヘルプを表示します.
<dbname>=# create role <username> with login; ## <username>でログインできるようにする
CREATE ROLE
<dbname>=# \q
$ su - <username> ## userを変更する
$ psql <dbname> ## dbに<username>でログインする
psql (9.5.3)
"help" でヘルプを表示します.
<dbname>=>
#5# Allow to access from client
$ vi /etc/postgresql/9.5/main/postgresql.conf ## postgresql.conf のセッティングを変更する
##以下抜粋##
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
listen_addresses = '*' ##初期は、クライアントからの接続を許可していないので
##'*’に変更する
##編集終了##
$ /etc/init.d/postgresql restart ## リスタートする
$ vi /etc/postgresql/9.5/main/pg_hba.conf ## pg_hba.conf のセッティングを変更する
##以下抜粋##
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all all trust
## これは、ADDRESSにALLをセット、MethodにTrustをセット。これはどの端末からでも
## どのDBへの接続も許可している。
##編集終了##
$ /etc/init.d/postgresql restart ## リスタートする
## このあとクライアントソフトからテストして確認する ##
view raw postgresql.sh hosted with ❤ by GitHub

## pg_hba.confのセッティングについては、以下参考
-postgresqlのページ
https://www.postgresql.jp/document/9.5/html/auth-pg-hba-conf.html

0 件のコメント:

コメントを投稿