postgreSQLがインストールされているかの確認。
$ rpm -qa | grep postgres
PostgreSQLがインストールされている場合は一旦削除。
$ rpm -e postgresql
1.PostgreSQLをインストールするディレクトリを作成。
$ mkdir /usr/local/pgsql
次にPostgreSQLを管理するユーザを作成し、パスワードを設定。
$ useradd -d /usr/local/pgsql postgres $ passwd postgres
PostgreSQLをダウンロードし、ファイルの所有者をpostgresに変更した後、postgresユーザで解凍。
postgresql
$ ftp -d ftp2.jp.postgresql.org ftp> cd /pub/postgresql/source ftp> ls # lsでリスト一覧を表示し、必要なバージョンにディレクトリに移動してファイルを取得。 ftp> cd postgresql-9.0.0 ftp> get postgresql-9.0.0.tar.gz ftp> exit $ chown postgres.postgres postgresql-9.0.0.tar.gz $ mv postgresql-9.0.0.tar.gz /usr/local/pgsql/ $ su - postgres $ tar xvfz postgresql-9.0.0.tar.gz $ cd postgresql-9.0.0
postgresユーザでコンパイルし、インストールします。
$ ./confiugre //状況にあわせてOPTION追加 $ make all $ make install
次にpostgresユーザのホームディレクトリ(/usr/local/pgsql)にある.bashrcファイルのに環境変数を設定する文を追加します。
$ vi /usr/local/pgsql/.bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
#追加部分
export POSTGRES_HOME=/usr/local/pgsql
export PATH="$PATH":$POSTGRES_HOME/bin
export PGLIB=$POSTGRES_HOME/lib
export PGDATA=$POSTGRES_HOME/data
export MANPATH="$MANPATH":$POSTGRES_HOME/man
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$PGLIB"
設定されたか確認。
$. /usr/local/pgsql/.bashrc $env
postgresユーザからデータベースの初期化を行います。
#su - postgres $initdb
以上でデータベースを利用することはできるが、ネットワークから利用できるようにする設定が必要である。
/usr/local/pgsql/data/postgresql.confを開き編集します。
$vi /usr/local/pgsql/data/postgresql.conf
tcpip_socket = on ←#を外しfalseをonに書き換える。 silent_mode = on ←#を外しfalseをonに書き換える。
localhost以外からのアクセスを許可するために/usr/local/pgsql/data/pg_hba.confの末尾に下線部を追記します。
$vi /usr/local/pgsql/data/pg_hba.conf
# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
local all all trust
# IPv4-style local connections:
host all all 127.0.0.1 255.255.255.255 trust
# IPv6-style local connections:
host all all ::1 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff trust
host all all 0.0.0.0 0.0.0.0 trust
以上で全ホストからのアクセスを許可します。
次に自動起動できるようにPostgreSQLの起動スクリプトを作成します。(ファイル名はpostgres)
#vi /etc/rc.d/init.d/postgres
#! /bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
prefix=/usr/local/pgsql
PGDATA="/usr/local/pgsql/data"
PGUSER=postgres
PGLOG="$PGDATA/serverlog"
DAEMON="$prefix/bin/pg_ctl"
if echo '\c' | grep -s c >/dev/null 2>&1 ; then
ECHO_N="echo -n"
ECHO_C=""
else
ECHO_N="echo"
ECHO_C='\c'
fi
set -e
test -f $DAEMON || exit 0
case $1 in
start)
$ECHO_N "Starting PostgreSQL: "$ECHO_C
su - $PGUSER -c "$DAEMON start -D '$PGDATA' -s -l $PGLOG"
echo "ok"
;;
stop)
echo -n "Stopping PostgreSQL: "
su - $PGUSER -c "$DAEMON stop -D '$PGDATA' -s -m fast"
echo "ok"
;;
restart)
echo -n "Restarting PostgreSQL: "
su - $PGUSER -c "$DAEMON restart -D '$PGDATA' -s -m fast -l $PGLOG"
echo "ok"
;;
reload)
echo -n "Reload PostgreSQL: "
su - $PGUSER -c "$DAEMON reload -D '$PGDATA' -s"
echo "ok"
;;
status)
su - $PGUSER -c "$DAEMON status -D '$PGDATA'"
;;
*)
# Print help
echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2
exit 1
;;
esac
exit 0
この起動スクリプトのパーミッションを変更します。
#chmod 755 /etc/rc.d/init.d/postgres
そして起動するランレベルにシンボリックリンクを張ります。
#cd /etc/rc.d/rc3.d/ #ln -s ../init.d/postgres ./S90postgres
そしてデータベースを起動させます。
#./S90postgres start
Apacheと連携させるため、インターネットからデータベースにアクセスするユーザをPostgreSQLのユーザとして登録します。
$createuser netuser Shall the new user be allowed to create databases?(y/n) n Shall the new user be allowed to create more new users?(y/n) n CREATE USER
以上で完了です。
WordPress
ポケットリファレンス (POCKET REFERENCE)