Info |
---|
本ページでは、RHEL 9 で PostgreSQL 11 をインストールし、Atlassian 製品用のデータベースを作成する手順を説明します。 |
...
PostgreSQL のインストール
1. サーバのターミナルウィンドウを開く
PostgreSQL をインストールするサーバに root 権限でログインし、ターミナルウィンドウを開きます。
2. リポジトリをインストールする
以下のコマンドを実行し、PostgreSQL のリポジトリをインストールします。
Code Block | ||||
---|---|---|---|---|
| ||||
$ yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm |
途中でインストールしてよいか確認されるので、内容に問題がなければ "y" を入力して Enter キーを押下してください。
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
読み込んだプラグイン:fastestmirror pgdg-redhat-repo-latest.noarch.rpm ... (中略) ... 合計容量: 10 k インストール容量: 10 k Is this ok [y/d/N]: ← 問題なければ、"y" を入力し Enter を押下する。 |
...
Code Block | ||||
---|---|---|---|---|
| ||||
$ yum install postgresql11postgresql13-server |
途中でインストールしてよいか確認されるので、内容に問題がなければ "y" を入力して Enter キーを押下してください。
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
読み込んだプラグイン:fastestmirror Loading mirror speeds from cached hostfile ... (中略) ... 総ダウンロード容量: 14 M インストール容量: 53 M Is this ok [y/d/N]: ← 問題なければ、"y" を入力し Enter を押下する。 |
...
Code Block | ||||
---|---|---|---|---|
| ||||
psql --version |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
psql (PostgreSQL) 1113.1513 |
データベース領域の初期化
1. 初期化ファイルを修正する
パフォーマンス悪化防止のため、初期化で使うコマンドのファイル (/usr/pgsql-11/bin/postgresql-11-setup) を修正し、initdb コマンドのオプションとして "--no-locale -E UTF-8" を追加します。
以下のコマンドを実行し、/usr/pgsql-11/bin/postgresql-11-setup ファイルをテキストエディタで開きます。
Code Block language bash theme RDark vi /usr/pgsql-1113/bin/postgresql-1113-setup
下記の行を探します。
Code Block language bash theme RDark initdbcmd+="$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident'"
の行を以下のように変更します。
code
$PGSETUP_INITDB_OPTIONS"
の行を以下のように変更します。--no-locale の前には忘れずにスペースを挿入して下さい。
Code Block language bash theme RDark initdbcmd="$PGENGINE/initdb --pgdata='$PGDATA' --auth='ident' --no-locale -E UTF-8" initdbcmd+=" --no-locale -E UTF-8" $PGSETUP_INITDB_OPTIONS"
- ファイルを保存して終了します。
2. データベース領域を初期化する
以下のコマンドを実行し、データベース領域を初期化します。
Code Block | ||||
---|---|---|---|---|
| ||||
/usr/pgsql-1113/bin/postgresql-1113-setup initdb |
下記の出力が出る事を確認します。
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
Initializing database ... OK |
上記の出力がされない場合はエラーが発生している事が考えられますので、ログファイルを確認します。
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
cat /var/lib/pgsql/13/initdb.log
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.UTF-8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
initdb: error: could not open file "/dev/zero--no-locale" for reading: No such file or directory
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
|
設定ファイルの修正
1. パフォーマンスを調整する
/var/lib/pgsql/1113/data/postgresql.conf ファイル内の値を変更し、PostgreSQL のパフォーマンスを調整します。
以下のコマンドを実行し、/var/lib/pgsql/1113/data/postgresql.conf ファイルをテキストエディタで開きます。
Code Block language bash theme RDark vi /var/lib/pgsql/1113/data/postgresql.conf
以下の行を見つけ、それぞれ変更していきます。
shared_buffers の値を変更し、メモリバッファで使用するメモリ量を設定します。
この値はご利用のサーバの環境にも左右されてしまいますが、今回は 512MB を指定します。Code Block title 変更前 shared_buffers = 128MB
Code Block title 変更後 shared_buffers = 512MB
work_mem のコメントアウトを解除し、ソート用のメモリバッファを指定します。
Code Block title 変更前 #work_mem = 4MB
Code Block title 変更後 work_mem = 4MB
wal_buffers のコメントアウトを解除し、トランザクションログを書き出す際に使用されるメモリバッファを指定します。
Code Block title 変更前 #wal_buffers = -1
Code Block title 変更後 wal_buffers = 64kB
- ファイルを保存して終了します。
2. 接続クライアントを設定する
/var/lib/pgsql/1113/data/postgresql.conf ファイルを編集し、localhost や特定の IP アドレスから接続できるように設定します。
以下のコマンドを実行し、/var/lib/pgsql/11/data/postgresql.conf ファイルをテキストエディタで開きます。
Code Block language bash theme RDark vi /var/lib/pgsql/11/data/postgresql.conf
listen_addresses の部分のコメントアウトを解除します。
Code Block title 変更前 #listen_addresses = 'localhost'
Code Block title 変更後 listen_addresses = 'localhost'
localhost 以外からもアクセスが発生する場合は、以下のように接続を許可するインターフェースの IP アドレスをカンマ区切りで追加してください。
Code Block title 変更後 listen_addresses = 'localhost,192.168.0.1,192.168.0.2'
- ファイルを保存して終了します。
3. 認証方法を設定する
/var/lib/pgsql/11/data/pg_hba.conf ファイルを編集し、認証方法を指定します。
デフォルトでは ident 方式となっていますが、パスワード認証を行う md5 方式に変更します。
以下のコマンドを実行し、/var/lib/pgsql/11/data/pg_hba.conf ファイルをテキストエディタで開きます。
Code Block language bash theme RDark vi /var/lib/pgsql/1113/data/pg_hba.conf
以下の行を探します。
Code Block title 変更前 host all all 127.0.0.1/32 identscram-sha-256
の行を以下のように変更します。
Code Block title 変更後 host all all 127.0.0.1/32 md5
localhost 以外からもアクセスが発生する場合は、以下のような接続元の IP アドレスの認証方法を指定した行を追加してください。Code Block title 変更後 host all all 192.168.0.10/24 md5
ファイルを保存して終了します。
設定ファイルを修正したら、以下のコマンドを実行し、PostgreSQL を起動します。
Code Block | ||||
---|---|---|---|---|
| ||||
systemctl start postgresql-1113 |
自動起動設定
以下のコマンドを実行し、サーバの起動時に PostgreSQL が自動的に起動するように設定します。
Code Block | ||||
---|---|---|---|---|
| ||||
systemctl enable postgresql-1113 |
PostgreSQL の起動と停止は、以下のコマンドから行うことができます。
PostgreSQL の起動
Code Block language bash theme RDark systemctl start postgresql-1113
PostgreSQL の停止
Code Block language bash theme RDark systemctl stop postgresql-1113
ユーザとデータベースの作成
Jira や Confluence などの接続先 DB (データベース) として使用するため、専用のユーザとデータベースを用意します。
...
Code Block | ||||
---|---|---|---|---|
| ||||
su - postgres |
Info |
---|
postgres ユーザは、PostgreSQL のインストール時に作成されるユーザです。 |
2. PostgreSQL のターミナルへ切り替える
...
PostgreSQL を操作するターミナルを終了するには、"\q" コマンドを実行してください。
ポートの開放
localhost 以外からもアクセスが発生する場合は、以下のように ポート番号 5432 を開放して外部からアクセスする事を可能にします。
Code Block | ||||
---|---|---|---|---|
| ||||
firewall-cmd --permanent --zon=public --add-service=postgresql
firewall-cmd --reload |
以上で、PostgreSQL のインストールからデータベースの作成までは完了です。