CentOS5.8にPostgreSQL9.1.4をソースからインストールしました。
RPMパッケージからインストールしても良いのですが、特定ユーザ以外はPostgreSQLの各種コマンド等のPATHが通らないようにしたかったため、ソースから手動でインストールしました。
(特定のユーザしかPostgreSQLを使用しない環境を構築したかったため)
PostgreSQL9.1.4のソースを以下のサイトからダウンロードしました。
http://www.postgresql.jp/
ダウンロードしたファイル名は postgresql-9.1.4.tar.gz になります。
PostgreSQLユーザを以下のコマンドで作成しました。
useradd postgres
# useradd postgres # id postgres uid=502(postgres) gid=503(postgres) 所属グループ=503(postgres)
尚、パスワードの設定はおこないませんでした。
# cat /etc/passwd | grep postgres postgres:x:502:503::/home/postgres:/bin/bash # cat /etc/shadow | grep postgres postgres:!!:15510:0:99999:7:::
!!になっているのでパスワードロック状態なのが確認できます。
今回は、PostgreSQLをインストールすることにより、他のユーザ環境に影響をあたえたくないので /opt/pgsql にインストールすることにします。
尚、本資料はダウンロードしたPostgreSQLのソースアーカイブは/tmpにあることにします。
[buildfarm@centos ~]$ su - パスワード: [root@centos ~]#
[root@centos /]# mkdir /opt/pgsql [root@centos /]# chown postgres:postgres /opt/pgsql [root@centos /]# chmod 755 /opt/pgsql [root@centos /]# ls -l /opt/ 合計 4 drwxr-xr-x 2 postgres postgres 4096 6月 19 12:28 pgsql
[root@centos ~]# su - postgres [postgres@centos ~]$
[postgres@centos ~]$ tar zxvf /tmp/postgresql-9.1.4.tar.gz
[postgres@centos ~]$ pwd /home/postgres [postgres@centos ~]$ ls -l 合計 4 drwxrwxr-x 6 postgres postgres 4096 6月 1 08:25 postgresql-9.1.4
[postgres@centos ~]$ cd postgresql-9.1.4/ [postgres@centos postgresql-9.1.4]$ pwd /home/postgres/postgresql-9.1.4
[postgres@centos postgresql-9.1.4]$ ./configure --prefix=/opt/pgsql checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking which template to use... linux <snip>
*** The installed version of Flex, /usr/bin/flex, is too old to use with PostgreSQL. *** Flex version 2.5.31 or later is required, but this is /usr/bin/flex version 2.5.4. configure: error: readline library not found
yum install readline-devel
yum install zlib-devel
[postgres@centos postgresql-9.1.4]$ make make -C src all make[1]: ディレクトリ `/home/postgres/postgresql-9.1.4/src' に入ります make -C port all make[2]: ディレクトリ `/home/postgres/postgresql-9.1.4/src/port' に入ります <snip>
[postgres@centos postgresql-9.1.4]$ make check <snip> ../../../src/test/regress/pg_regress --inputdir=. --temp-install=./tmp_check --top-builddir=../../.. --dlpath=. --schedule=./parallel_schedule ============== creating temporary installation ============== <snip> ============== shutting down postmaster ============== ======================= All 126 tests passed. =======================
$ ls -ltr /opt/pgsql/ 合計 0make install をすることによりPostgreSQLがインストールされます。
[postgres@centos postgresql-9.1.4]$ make install <snip> /bin/mkdir -p '/opt/pgsql/lib/pgxs/config' /bin/sh ../config/install-sh -c -m 755 ./install-sh '/opt/pgsql/lib/pgxs/config/install-sh' make[1]: ディレクトリ `/home/postgres/postgresql-9.1.4/config' から出ます PostgreSQL installation complete.インストールされたか確認してみます。
$ ls -ltr /opt/pgsql/ 合計 16 drwxrwxr-x 6 postgres postgres 4096 6月 19 13:34 include drwxrwxr-x 6 postgres postgres 4096 6月 19 13:34 share drwxrwxr-x 3 postgres postgres 4096 6月 19 13:34 lib drwxrwxr-x 2 postgres postgres 4096 6月 19 13:34 bin
[postgres@centos ~]$ vi ~/.bashrc追記した内容は以下の通りです。
export PATH=/opt/pgsql/bin:$PATH export POSTGRES_HOME=/opt/pgsql export PGLIB=$POSTGRES_HOME/lib export PGDATA=$POSTGRES_HOME/data export MANPATH="$MANPATH":$POSTGRES_HOME/man export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$PGLIB"
[postgres@centos postgresql-9.1.4]$ su -c "cp contrib/start-scripts/linux /etc/init.d/postgres" パスワード: [postgres@vmbuildfarm postgresql-9.1.4]$ su -c "chmod 755 /etc/init.d/postgres" パスワード: [postgres@centos postgresql-9.1.4]$ ls -l /etc/init.d/postgres -rwxr-xr-x 1 root root 3019 6月 19 13:51 /etc/init.d/postgres
<snip> ## EDIT FROM HERE # Installation prefix prefix=/opt/pgsql # Data directory PGDATA="/opt/pgsql/data" <snip>
[root@centos ~]# chkconfig --add postgrescheckconfig --list で確認できました。
[root@centos ~]# chkconfig --list | grep postgres postgres 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@vmbuildfarm ~]# su - postgres [postgres@vmbuildfarm ~]$ initdb --no-locale -D /opt/pgsql/data The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale C. The default database encoding has accordingly been set to SQL_ASCII. The default text search configuration will be set to "english". <snip>
[root@vmbuildfarm ~]# service postgres start Starting PostgreSQL: ok
[postgres@vmbuildfarm data]$ psql template1 psql (9.1.4) Type "help" for help. template1=#
chkconfig postgres on
これで、他のユーザアカウントにインストールしたPostgreSQLの環境変数を設定すれば、設定したユーザのみ使用可能となります。
今回は、特定ユーザのみPostgreSQLを使用できるようにし、現在の環境に影響をあたえたくないのでPostgreSQLのシェアードライブラリをldconfigに設定しませんでした。
設定したい場合は、/etc/ld.so.conf.dディレクトリにpostgresql.confのようにファイルを作成しシェアードライブラリのディレクトリを設定すればOKです。
echo /opt/pgsql/lib > /etc/ld.so.conf.d/postgresql.conf