LoginSignup
12
7

More than 5 years have passed since last update.

CentOS6にpgAdmin4をインストール

Last updated at Posted at 2016-10-11

概要

PostgreSQL9.6リリースおめでとうございます!

日ごろMySQL使いの同僚から「(MySQLと違って)postgresってリッチなクライアント無いよね?」
ってディスられてて悔しかったので、
PostgreSQL9.6と同日に正式リリースされたpgAdmin4を見せびらかそうとしてCentOS6にインストールした際に、
結構ハマったのでメモです。
#試すまではyumで簡単インストールだと思ってましたよ(><)/

※Windows版は簡単インストールらしいので、手軽に試すならそちらをおススメいたします。以下nuko_yokohamaさんの記事
「pgAdmin4 + PostgreSQL 9.6beta3」
http://qiita.com/nuko_yokohama/items/5052c858bf58ea713144

手順

postgresをインストール ここでは当然9.6をチョイス

rpm -ivh https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm
yum -y install postgresql96.x86_64 postgresql96-server.x86_64 postgresql96-devel.x86_64 

pg_configのpathを通す

PATH=$PATH:/usr/pgsql-9.6/bin/
export PATH

細かいエラーをつぶすのは面倒なので開発ツール一式インストール

yum groupinstall "Development tools"

python 2.7 インストール

# yum install centos-release-SCL ←2017/07/12エラーとなることを確認
rpm -ivh http://mirror.centos.org/centos/6/extras/x86_64/Packages/centos-release-scl-rh-2-3.el6.centos.noarch.rpm

yum install scl-utils python27 python27-scldevel
scl enable python27 bash

easy_install pip
pip install --upgrade pip

pgadmin4 インストール ※2017/07/12時点の最新版

cd /tmp
wget https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v1.5/pip/pgadmin4-1.5-py2.py3-none-any.whl
pip install pgadmin4-1.5-py2.py3-none-any.whl

pgadmin4 設定

cd /opt/rh/python27/root/usr/lib/python2.7/site-packages/pgadmin4
cp -p config.py config.py.org

vi config.py
---
DEFAULT_SERVER = '0.0.0.0'  # とりあえずlocalhost以外からも許可
---

touch config_local.py  # 存在しないと怒られるので作成しておく

pgadmin4 起動

scl enable python27 bash
cd /opt/rh/python27/root/usr/lib/python2.7/site-packages/pgadmin4
python pgAdmin4.py

初回はログインユーザの作成プロンプトが表示されるので、ユーザ名、パスワードを入力します。

pgAdmin 4 - Application Initialisation
======================================


The configuration database - '/root/.pgadmin/pgadmin4.db' does not exist.
Entering initial setup mode...
NOTE: Configuring authentication for SERVER mode.


    Enter the email address and password to use for the initial pgAdmin user     account:

Email address: ←ユーザ名を入力
Password:   ←パスワードを入力
Retype password:    ←パスワードを入力


The configuration database has been created at /root/.pgadmin/pgadmin4.db
Starting pgAdmin 4. Please navigate to http://0.0.0.0:5050 in your browser.

接続

config.pyでポート番号を変えていなければ"5050"で接続できます。
本当はapacheかましてWSGI起動すべきらしいんですが、そちらは公式ドキュメントをどうぞ。
「pgAdmin 4 1.0 documentation」
https://www.pgadmin.org/docs4/1.x/server_deployment.html#apache-httpd-configuration-linux-unix

WS000008.JPG

01.png

ハマったこと列挙

  • いきなり"yum install pgadmin4.x86_64"を実行したところ大量のエラーに圧倒される
~省略~
Error: Package: pgadmin4-web-1.0-2.rhel6.noarch (pgdg95)
           Requires: python-beautifulsoup4 >= 4.4.1
Error: Package: python-flask-babel-0.11.1-1.rhel6.noarch (pgdg95)
           Requires: python-speaklater
Error: Package: pgadmin4-web-1.0-2.rhel6.noarch (pgdg95)
           Requires: python-importlib >= 1.0.3
Error: Package: pgadmin4-web-1.0-2.rhel6.noarch (pgdg95)
           Requires: python-crypto >= 2.6.1
           Available: python-crypto-2.0.1-22.el6.x86_64 (base)
               python-crypto = 2.0.1-22.el6
~省略~
  • 頑張って必要なpythonモジュールを入れようとする、がダメ
  • そもそもCentOS6のデフォルトがpython2.6で、pgAdmin4にはpython2.7が必要らしいことに"Requires"で表示されたパッケージから気づく
  • python2.7を入れても"yum install pgadmin4.x86_64"が同じエラーで通らないことに絶望
  • "Python wheel (PIP)"というパッケージフォーマットがあることに気づく → Pythonで怒られるならPythonで入れてやろう
  • "pip install pgadmin4-xxx.whl"がpg_configが見えなくて怒られる → PATH変数に追加してやる
Error: pg_config executable not found.

Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
  • pg_configにパスを通してもBuild周りでエラーが発生する → 半分やけっぱちで開発ツールをyumでインストール
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/pip-build-nhCv2a/pycrypto':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
  • pgAdmin4インストール成功したけど、インストール先ディレクトリが不明 → findで無理やり見つけた
  • pgAdmin4起動したけど接続できない → config.pyのDEFAULT_SERVERを0.0.0.0へ

所感

ちょっと使ってみたかっただけなのにあちこち躓きました。。
こういうのを"yak shaving"って言うんでしょうか。
pgAdmin4についてはもうすこしまじめに利用しつつ、機能紹介を書けたらなぁと考えています。

12
7
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
12
7