Skip to content

Instantly share code, notes, and snippets.

@yokawasa
Last active May 9, 2018 09:36
Show Gist options
  • Save yokawasa/baca793d60ca976be38a475902d9a1ff to your computer and use it in GitHub Desktop.
Save yokawasa/baca793d60ca976be38a475902d9a1ff to your computer and use it in GitHub Desktop.
TicketMonster App Setup Memo - Database (PostgreSQL)

TicketMonster App Setup Memo - Database: PostgreSQL

Environment:

  • CentOS based 7.4
  • PostgreSQL 9.6
$ cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

Installation

# pgdg96リポジトリを追加する
$ sudo yum install -y https://yum.postgresql.org/9.6/redhat/rhel-7-x86_64/pgdg-redhat96-9.6-3.noarch.rpm

# PostgreSQLサーバーをインストールする
$ sudo yum install -y postgresql96-server postgresql96-contrib

# version check
$ psql --version
psql (PostgreSQL) 9.6.8

Initializae database

sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb

Start postgresql

sudo systemctl start postgresql-9.6.service

Configure postgresql to auto-start in OS loading

sudo systemctl enable postgresql-9.6.service

Create user

$ psql -l
    psql: FATAL:  role "azureuser" does not exist  ###ログインユーザーがazureuser�だから

# DBの初期化時に postgres というユーザーが作成されるので、パスワードを設定してログインし、先ほどまでログインしていたユーザーと同名のロールを作成します。
# `postgres` ユーザーにパスワードを設定する
$ sudo passwd postgres       # ”postgres�”に設定

# `postgres` ユーザーでログインする
$ su - postgres

# `postgres` へ接続する
$ psql
psql (9.6.3)
"help" でヘルプを表示します.

# ロールを作成する
# postgres=# create role {ユーザー名} login createdb password '{パスワード}';
postgres=# create role azureuser login createdb password 'P@ssw0rd';

ロールを作成したら、作成したユーザーでDBを操作できるようになったか確認

$ psql -U azureuser --password postgres

ticketmonsterという名前のデータベースを作成する

psql> create database ticketmonster
psql> \q

Rmoete access Configuration - postgresql.conf

sudo  vi /var/lib/pgsql/9.6/data/postgresql.conf

# Open postgresql.conf file and replace line
# listen_addresses = 'localhost'
# with
# listen_addresses = '*'
listen_addresses = '*'

Rmoete access Configuration - pg_hpa.conf

sudo vi  /var/lib/pgsql/9.6/data/pg_hba.conf

host    all             all              0.0.0.0/0                       md5
host    all             all              ::/0                            md5

Restart postgreSQL server! Then you can check if you are able to access from remote

psql -h <dbhost> -U azureuser --password ticketmonster

Operations

Access via psql command

psql -h <dbhost> -U azureuser --password ticketmonster

Stop & Start postgresQL

sudo systemctl stop postgresql-9.6.service
sudo systemctl start postgresql-9.6.service

Configuration

sudo  vi /var/lib/pgsql/9.6/data/postgresql.conf

LINKS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment