インストール
最新パッケージの確認
# yum search postgresql
# yum install -y postgresql-server
最新が9.3(2014/7現在)が存在しないので、手動でダウンロードする
Linuxで起動
# chmod a+x postgresql-9.3.0-1-linux.run
# ./postgresql-9.3.0-1-linux.run
画面に沿ってインストールする
/opt/PostgreSQL/9.3
自動起動設定
# chkconfig postgresql-9.3 --list
postgresql-9.3 0:off 1:off 2:on 3:on 4:on 5:on 6:off
データベースの作り直し
PG_DATAフォルダ以下を空にしないとinitdbできないので、rm -rfとかで消しておくこと。
# su - postgres
$ rm -rf /opt/PostgreSQL/9.3/data/*
$ /opt/PostgreSQL/9.3/bin/initdb -D /opt/PostgreSQL/9.3/data --encoding=UTF8 --no-locale
証明書の作成(オレオレ版)
# su -
# cd /opt/PostgreSQL/9.3/data
# openssl genrsa -out server.key 2048
Generating RSA private key, 2048 bit long modulus
......+++
...............................+++
e is 65537 (0x10001)
# openssl req -new -key server.key -out server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:
State or Province Name (full name) []:
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
# openssl x509 -days 3650 -req -signkey server.key < server.csr > server.crt
Signature ok
subject=/C=XX/L=Default City/O=Default Company Ltd
Getting Private key
パーミッションの変更
# chmod og-rwx server.key
SSL設定
# vi postgresql.conf
以下の4行を追加
ssl = on
ssl_ciphers = 'DEFAULT'
ssl_cert_file = 'server.crt'
ssl_key_file = 'server.key'
再起動
# service postgresql-9.3 restart
Restarting PostgreSQL 9.3:
waiting for server to shut down.... done
server stopped
waiting for server to start.... done
server started
PostgreSQL 9.3 restarted successfully
postgreSQLの設定
ユーザ作成
# useradd postgres
# passwd postgres
postgresにスイッチユーザする
# su - postgres
パスを設定しておく
# vi ~/.bashrc
下記を追加
export PATH=$PATH:/opt/PostgreSQL/9.3/bin/
ログインしなおして、パスの確認を行う。
-bash-4.1$ which createuser
/opt/PostgreSQL/9.3/bin/createuser
データベースアクセスユーザを作成
-bash-4.1$ createuser -U postgres -P hoge
Enter password for new role: hogeのパス
Enter it again: hogeのパス
Password: postgres
データベース作成
-bash-4.1$ createdb -U postgres -O hogeuser -E UTF8 hogedb
作成確認
-bash-4.1$ psql -l
データベース一覧
名前 | 所有者 | エンコーディング | 照合順序 | Ctype(変換演算子) | アクセス権
-----------+----------+------------------+-------------+-------------------+-----------------------
hogedb | hogeuser | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
postgres | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
template0 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres: postgres=CTc/postgres
template1 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres: postgres=CTc/postgres
(4 行)
接続確認
-bash-4.1$ psql hogedb
psql (8.4.20)
"help" でヘルプを表示します.
hogedb=# select * from user;
current_user
--------------
postgres
(1 行)
hogedb=# \q
-bash-4.1$
最終更新:2014年07月14日 18:34