LoginSignup
2
5

More than 3 years have passed since last update.

CentOS7にPgadmin4をインストールする。

Posted at

仮想環境にPgadmin4をインストールしてみる。

環境

OS : CentOS7
DB : Postgresq11.3
Server :Apache.2.4.6

準備

Apacheのインストール
Postgres11のインストール

インストール

yumにepelリポジトリを追加する

yum install epel-release

Pgadmin4のインストール

yum install pgadmin4

Pgadmin4用フォルダを作成

mkdir /var/www/pgadmin4

設定ファイルの場所へ移動

cd /usr/lib/python2.7/site-packages/pgadmin4-web

Pgadminの設定を追加

※設定内容については公式ドキュメントを参考にしてください。
公式ドキュメント

vi config_local.py

※以下を追加
SERVER_MODE = True
LOG_FILE = '/var/www/pgadmin4/pgadmin4.log'
SQLITE_PATH = '/var/www/pgadmin4/pgadmin4.db'
SESSION_DB_PATH = '/var/www/pgadmin4/sessions'
STORAGE_DIR = '/var/www/pgadmin4/storage'

Pgadmin4のセットアップ

python setup.py

ここで設定したアドレス、パスワードはログイン時に必要となります。
address : XXXXXXXX
password : XXXXXXXX

サービス自動起動設定

systemctl enable pgadmin4.service

サービス起動

systemctl start pgadmin4.service

サービスステータスを確認する。

※Activeと表示されていれば起動しています。

systemctl status pgadmin4.service

pgadmin4の所有権をApahceに変更

chown -R apache:apache /var/www/pgadmin4

Apacheの設定ファイル場所へ移動

cd /etc/httpd/conf.d

Pgadminの設定ファイルをサンプルから作成

cp pgadmin4.conf.sample pgadmin4.conf
vi pgadmin4.conf

※先頭行のみコメントアウトしてください

Postgresqlの設定を変更

vi /var/lib/pgsql/11/data/postgresql.conf

※デフォルト
#listen_addresses = 'localhost'
#port = 5432

※変更後
listen_address = '*'
port = 5432

postgresユーザにパスワードを設定していない場合はついでに
パスワードを設定しておきます。

su - postgres
psql
alter role postgres with password 'postgres';

Postgresqlの認証設定を変更

cd /var/lib/pgsql/11/data/
vi pg_hba.conf

# IPv4 local connections:
変更前:host all all 127.0.0.1/32  ident
変更後:host all all   0.0.0.0/0   md5

設定反映のために各サービスを再起動

systemctl restart postgresql-11
systemctl restart httpd
systemctl restart pgadmin4.service

下記URLにアクセスし、ログインできればOK
http://サーバのIPアドレス/pgadmin4

以上でPgadmin4のインストールは完了です。

2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5