PostgreSQL/PostgreSQLをソースからCentOSにインストール
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* CentOSにPostgreSQL9.1.4をソースからインストール [#fde2c...
CentOS5.8にPostgreSQL9.1.4をソースからインストールしまし...
RPMパッケージからインストールしても良いのですが、特定ユー...
(特定のユーザしかPostgreSQLを使用しない環境を構築したかっ...
#contents
#htmlinsertpcsp(db-top.html,db-sp.html)
* 関連記事 [#b4f05b39]
-[[flexのインストール>PostgreSQL/flexのインストール]]
-[[CentOSでPostgreSQLをソースからコンパイルする手順>Postg...
-[[PostgreSQLコミュニティーベースのリポジトリを設定し最新...
* PostgreSQLのソースを入手 [#i846b507]
PostgreSQL9.1.4のソースを以下のサイトからダウンロードしま...
http://www.postgresql.jp/
ダウンロードしたファイル名は postgresql-9.1.4.tar.gz にな...
* PostgreSQLのユーザを作成 [#dbb9ba6d]
PostgreSQLユーザを以下のコマンドで作成しました。
useradd postgres
# useradd postgres
# id postgres
uid=502(postgres) gid=503(postgres) 所属グループ=503(pos...
尚、パスワードの設定はおこないませんでした。
# cat /etc/passwd | grep postgres
postgres:x:502:503::/home/postgres:/bin/bash
# cat /etc/shadow | grep postgres
postgres:!!:15510:0:99999:7:::
''!!''になっているのでパスワードロック状態なのが確認でき...
* PostgreSQLソースのコンパイル [#wa05420d]
今回は、PostgreSQLをインストールすることにより、他のユー...
尚、本資料はダウンロードしたPostgreSQLのソースアーカイブ...
+ su - コマンドで root にスイッチユーザします。
[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
+ su - postgres で postgres にスイッチユーザします。
[root@centos ~]# su - postgres
[postgres@centos ~]$
+ tar コマンドでダウンロードしたpostgresql-9.1.4.tar.gzを...
[postgres@centos ~]$ tar zxvf /tmp/postgresql-9.1.4.tar.gz
+ tarballが展開されていること確認します。
[postgres@centos ~]$ pwd
/home/postgres
[postgres@centos ~]$ ls -l
合計 4
drwxrwxr-x 6 postgres postgres 4096 6月 1 08:25 postgr...
+ 展開したディレクトリにcdします。
[postgres@centos ~]$ cd postgresql-9.1.4/
[postgres@centos postgresql-9.1.4]$ pwd
/home/postgres/postgresql-9.1.4
+ configureを実行します。~
インストール先は/opt/pgsqlなのでprefixに/opt/pgsqlを指定...
[postgres@centos postgresql-9.1.4]$ ./configure --prefix...
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>
+ configureでerrorなどが出力された場合
ライブラリが不足している場合、以下のようなエラーが出力さ...
*** The installed version of Flex, /usr/bin/flex, is too...
*** Flex version 2.5.31 or later is required, but this i...
configure: error: readline library not found
#br
-- flexのバージョンが古いと出力された場合
以下の記事を参考にflexをインストールしてください。~
---[[flexのインストール>PostgreSQL/flexのインストール]]
#br
-- configure: error: readline library not found と出力さ...
以下のコマンドでreadlineのライブラリをインストールしてく...
yum install readline-devel
#br
-- configure: error: zlib library not found と出力された...
以下のコマンドでzlibのライブラリをインストールしてくださ...
yum install zlib-devel
+ makeコマンドを実行します。
[postgres@centos postgresql-9.1.4]$ make
make -C src all
make[1]: ディレクトリ `/home/postgres/postgresql-9.1.4/s...
make -C port all
make[2]: ディレクトリ `/home/postgres/postgresql-9.1.4/s...
<snip>
+ makeが完了したらインストール前に動作確認をしてみます。(...
[postgres@centos postgresql-9.1.4]$ make check
<snip>
../../../src/test/regress/pg_regress --inputdir=. --temp...
============== creating temporary installation ==...
<snip>
============== shutting down postmaster ==...
=======================
All 126 tests passed.
=======================
+ make installでコンパイルしたPostgreSQLをインストールし...
上記までの操作では、まだインストールされていません。~
$ ls -ltr /opt/pgsql/
合計 0
make 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 '/op...
make[1]: ディレクトリ `/home/postgres/postgresql-9.1.4/c...
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ユーザの.bashrcを編集~
postgresユーザの.bashrcにインストールしたPostgreSQLを使用...
本記事では、viを使って追記しました。
[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"
+ 起動スクリプトの設置~
展開したPostgreSQLソース内にcontribディレクトリがあります...
contribディレクトリ内のstart-scriptsにlinuxというファイル...
(本記事の場合は /home/postgres/postgresql-9.1.4/contrib/s...
このファイルをrootユーザで/etc/rc.d/init.d/にpostgresとフ...
[postgres@centos postgresql-9.1.4]$ su -c "cp contrib/st...
パスワード:
[postgres@vmbuildfarm postgresql-9.1.4]$ su -c "chmod 75...
パスワード:
[postgres@centos postgresql-9.1.4]$ ls -l /etc/init.d/po...
-rwxr-xr-x 1 root root 3019 6月 19 13:51 /etc/init.d/po...
+ コピーしたpostgresファイルの修正
rootユーザでコピーした/etc/init.d/postgresを修正します。~
修正箇所はprefixとPGDATAです。
<snip>
## EDIT FROM HERE
# Installation prefix
prefix=/opt/pgsql
# Data directory
PGDATA="/opt/pgsql/data"
<snip>
+ chkconfigコマンドにて起動スクリプトの登録
以下のコマンドで上記で編集した起動スクリプトを登録します...
[root@centos ~]# chkconfig --add postgres
checkconfig --list で確認できました。
[root@centos ~]# chkconfig --list | grep postgres
postgres 0:off 1:off 2:on 3:on 4:on ...
+ PGDATAで設定したディレクトリを作成します。(initdbします...
postgresユーザにスイッチユーザします。~
上記で.bashrc設定をした環境変数が反映されていることを確認...
尚、ロケールは--no-localeでinitdbします。
[root@vmbuildfarm ~]# su - postgres
[postgres@vmbuildfarm ~]$ initdb --no-locale -D /opt/pgs...
The files belonging to this database system will be owne...
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 t...
The default text search configuration will be set to "en...
<snip>
+ 必要に応じて/opt/pgpsql/dataのpostgresql.conf, pg_hba.c...
当方、localhostのみで運用するつもりなので、デフォルトまま...
+ serviceコマンドにてインストールしたpostgresqlを起動して...
[root@vmbuildfarm ~]# service postgres start
Starting PostgreSQL: ok
+ postgresユーザで接続してみます。(postgresユーザで実施)
[postgres@vmbuildfarm data]$ psql template1
psql (9.1.4)
Type "help" for help.
template1=#
+ マシン再起動による自動起動
上記のchkconfig -addで登録したとき既にランレベル2, 3, 4, ...
もし全てoffの場合は、以下のコマンドで自動起動するように設...
chkconfig postgres on
これで、他のユーザアカウントにインストールしたPostgreSQL...
* 今回実施しなかっとこと [#a327281c]
今回は、特定ユーザのみPostgreSQLを使用できるようにし、現...
設定したい場合は、/etc/ld.so.conf.dディレクトリにpostgres...
-設定例(rootで以下のコマンドを実行すれば設定が完了です)
echo /opt/pgsql/lib > /etc/ld.so.conf.d/postgresql.conf
#htmlinsertpcsp(db-btm.html,db-sp.html)
終了行:
#navi(../)
* CentOSにPostgreSQL9.1.4をソースからインストール [#fde2c...
CentOS5.8にPostgreSQL9.1.4をソースからインストールしまし...
RPMパッケージからインストールしても良いのですが、特定ユー...
(特定のユーザしかPostgreSQLを使用しない環境を構築したかっ...
#contents
#htmlinsertpcsp(db-top.html,db-sp.html)
* 関連記事 [#b4f05b39]
-[[flexのインストール>PostgreSQL/flexのインストール]]
-[[CentOSでPostgreSQLをソースからコンパイルする手順>Postg...
-[[PostgreSQLコミュニティーベースのリポジトリを設定し最新...
* PostgreSQLのソースを入手 [#i846b507]
PostgreSQL9.1.4のソースを以下のサイトからダウンロードしま...
http://www.postgresql.jp/
ダウンロードしたファイル名は postgresql-9.1.4.tar.gz にな...
* PostgreSQLのユーザを作成 [#dbb9ba6d]
PostgreSQLユーザを以下のコマンドで作成しました。
useradd postgres
# useradd postgres
# id postgres
uid=502(postgres) gid=503(postgres) 所属グループ=503(pos...
尚、パスワードの設定はおこないませんでした。
# cat /etc/passwd | grep postgres
postgres:x:502:503::/home/postgres:/bin/bash
# cat /etc/shadow | grep postgres
postgres:!!:15510:0:99999:7:::
''!!''になっているのでパスワードロック状態なのが確認でき...
* PostgreSQLソースのコンパイル [#wa05420d]
今回は、PostgreSQLをインストールすることにより、他のユー...
尚、本資料はダウンロードしたPostgreSQLのソースアーカイブ...
+ su - コマンドで root にスイッチユーザします。
[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
+ su - postgres で postgres にスイッチユーザします。
[root@centos ~]# su - postgres
[postgres@centos ~]$
+ tar コマンドでダウンロードしたpostgresql-9.1.4.tar.gzを...
[postgres@centos ~]$ tar zxvf /tmp/postgresql-9.1.4.tar.gz
+ tarballが展開されていること確認します。
[postgres@centos ~]$ pwd
/home/postgres
[postgres@centos ~]$ ls -l
合計 4
drwxrwxr-x 6 postgres postgres 4096 6月 1 08:25 postgr...
+ 展開したディレクトリにcdします。
[postgres@centos ~]$ cd postgresql-9.1.4/
[postgres@centos postgresql-9.1.4]$ pwd
/home/postgres/postgresql-9.1.4
+ configureを実行します。~
インストール先は/opt/pgsqlなのでprefixに/opt/pgsqlを指定...
[postgres@centos postgresql-9.1.4]$ ./configure --prefix...
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>
+ configureでerrorなどが出力された場合
ライブラリが不足している場合、以下のようなエラーが出力さ...
*** The installed version of Flex, /usr/bin/flex, is too...
*** Flex version 2.5.31 or later is required, but this i...
configure: error: readline library not found
#br
-- flexのバージョンが古いと出力された場合
以下の記事を参考にflexをインストールしてください。~
---[[flexのインストール>PostgreSQL/flexのインストール]]
#br
-- configure: error: readline library not found と出力さ...
以下のコマンドでreadlineのライブラリをインストールしてく...
yum install readline-devel
#br
-- configure: error: zlib library not found と出力された...
以下のコマンドでzlibのライブラリをインストールしてくださ...
yum install zlib-devel
+ makeコマンドを実行します。
[postgres@centos postgresql-9.1.4]$ make
make -C src all
make[1]: ディレクトリ `/home/postgres/postgresql-9.1.4/s...
make -C port all
make[2]: ディレクトリ `/home/postgres/postgresql-9.1.4/s...
<snip>
+ makeが完了したらインストール前に動作確認をしてみます。(...
[postgres@centos postgresql-9.1.4]$ make check
<snip>
../../../src/test/regress/pg_regress --inputdir=. --temp...
============== creating temporary installation ==...
<snip>
============== shutting down postmaster ==...
=======================
All 126 tests passed.
=======================
+ make installでコンパイルしたPostgreSQLをインストールし...
上記までの操作では、まだインストールされていません。~
$ ls -ltr /opt/pgsql/
合計 0
make 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 '/op...
make[1]: ディレクトリ `/home/postgres/postgresql-9.1.4/c...
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ユーザの.bashrcを編集~
postgresユーザの.bashrcにインストールしたPostgreSQLを使用...
本記事では、viを使って追記しました。
[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"
+ 起動スクリプトの設置~
展開したPostgreSQLソース内にcontribディレクトリがあります...
contribディレクトリ内のstart-scriptsにlinuxというファイル...
(本記事の場合は /home/postgres/postgresql-9.1.4/contrib/s...
このファイルをrootユーザで/etc/rc.d/init.d/にpostgresとフ...
[postgres@centos postgresql-9.1.4]$ su -c "cp contrib/st...
パスワード:
[postgres@vmbuildfarm postgresql-9.1.4]$ su -c "chmod 75...
パスワード:
[postgres@centos postgresql-9.1.4]$ ls -l /etc/init.d/po...
-rwxr-xr-x 1 root root 3019 6月 19 13:51 /etc/init.d/po...
+ コピーしたpostgresファイルの修正
rootユーザでコピーした/etc/init.d/postgresを修正します。~
修正箇所はprefixとPGDATAです。
<snip>
## EDIT FROM HERE
# Installation prefix
prefix=/opt/pgsql
# Data directory
PGDATA="/opt/pgsql/data"
<snip>
+ chkconfigコマンドにて起動スクリプトの登録
以下のコマンドで上記で編集した起動スクリプトを登録します...
[root@centos ~]# chkconfig --add postgres
checkconfig --list で確認できました。
[root@centos ~]# chkconfig --list | grep postgres
postgres 0:off 1:off 2:on 3:on 4:on ...
+ PGDATAで設定したディレクトリを作成します。(initdbします...
postgresユーザにスイッチユーザします。~
上記で.bashrc設定をした環境変数が反映されていることを確認...
尚、ロケールは--no-localeでinitdbします。
[root@vmbuildfarm ~]# su - postgres
[postgres@vmbuildfarm ~]$ initdb --no-locale -D /opt/pgs...
The files belonging to this database system will be owne...
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 t...
The default text search configuration will be set to "en...
<snip>
+ 必要に応じて/opt/pgpsql/dataのpostgresql.conf, pg_hba.c...
当方、localhostのみで運用するつもりなので、デフォルトまま...
+ serviceコマンドにてインストールしたpostgresqlを起動して...
[root@vmbuildfarm ~]# service postgres start
Starting PostgreSQL: ok
+ postgresユーザで接続してみます。(postgresユーザで実施)
[postgres@vmbuildfarm data]$ psql template1
psql (9.1.4)
Type "help" for help.
template1=#
+ マシン再起動による自動起動
上記のchkconfig -addで登録したとき既にランレベル2, 3, 4, ...
もし全てoffの場合は、以下のコマンドで自動起動するように設...
chkconfig postgres on
これで、他のユーザアカウントにインストールしたPostgreSQL...
* 今回実施しなかっとこと [#a327281c]
今回は、特定ユーザのみPostgreSQLを使用できるようにし、現...
設定したい場合は、/etc/ld.so.conf.dディレクトリにpostgres...
-設定例(rootで以下のコマンドを実行すれば設定が完了です)
echo /opt/pgsql/lib > /etc/ld.so.conf.d/postgresql.conf
#htmlinsertpcsp(db-btm.html,db-sp.html)
ページ名: