Ubuntu 18.04 + nginx + pgadmin4 (server mode + reverse proxy)

2020年4月17日

 

Install required packages:

apt install build-essential libssl-dev libffi-dev virtualenv python-pip libpq-dev python-dev


Create directories/permissions:

  1. mkdir -p /var/lib/pgadmin4/sessions
  2. mkdir /var/lib/pgadmin4/storage
  3. mkdir /var/log/pgadmin4
  4. chown -R user:(当前用户) /var/lib/pgadmin4/
  5. chown -R user:(当前用户) /var/log/pgadmin4/


Enable virtualenv and install pgadmin (at this time 4.4.11):

  1. virtualenv .pgadmin4
  2. cd .pgadmin4/
  3. source bin/activate
  4. wget https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v4.11/pip/pgadmin4-4.11-py2.py3-none-any.whl
  5. pip install pgadmin4-4.11-py2.py3-none-any.whl


Configure server environment:

vi nano lib/python2.7/site-packages/pgadmin4/config_local.py

 

 

 

 

 

  1. ---
  2. DEFAULT_SERVER = '0.0.0.0'
  3. DEFAULT_SERVER_PORT = 5050
  4. LOG_FILE = '/var/log/pgadmin4/pgadmin4.log'
  5. SQLITE_PATH = '/var/lib/pgadmin4/pgadmin4.db'
  6. SESSION_DB_PATH = '/var/lib/pgadmin4/sessions'
  7. STORAGE_DIR = '/var/lib/pgadmin4/storage'
  8. SERVER_MODE = True
  9. ---

     

     

     

     

     


Setup pgadmin4:

  1. python lib/python2.7/site-packages/pgadmin4/setup.py
  2. NOTE: Configuring authentication for SERVER mode.
  3. Enter the email address and password to use for the initial pgAdmin user account:
  4. Email address: youremail@address
  5. Password:
  6. Retype password:
  7. pgAdmin 4 - Application Initialisation
  8. ======================================


Change permission to nginx access:

  1. chown -R www-data:www-data /var/lib/pgadmin4/
  2. chown -R www-data:www-data /var/log/pgadmin4/


Create script to start pgadmin:

  1. vim /usr/local/bin/pgadmin.sh
  2. #!/bin/bash . /home/webapps/.pgadmin4/bin/activate
  3. # virtualenv is now active.
  4. #
  5. nohup python /home/webapps/.pgadmin4/lib/python2.7/site-packages/pgadmin4/pgAdmin4.py &

 chmod +x /usr/local/bin/pgadmin.sh


Run script:

  1. [~/.pgadmin4]: pgadmin.sh
  2. [~/.pgadmin4]: nohup: appending output to 'nohup.out'

尝试运行可能报错

(.pgadmin4) [admin@SH-MyVps:.pgadmin4]$ python lib/python2.7/site-packages/pgadmin4/setup.py
Traceback (most recent call last):
  File "lib/python2.7/site-packages/pgadmin4/setup.py", line 17, in <module>
    from pgadmin.model import db, User, Version, ServerGroup, Server, \
  File "/home/webapps/.pgadmin4/lib/python2.7/site-packages/pgadmin4/pgadmin/__init__.py", line 25, in <module>
    from flask_security import Security, SQLAlchemyUserDatastore, current_user
  File "/home/webapps/.pgadmin4/local/lib/python2.7/site-packages/flask_security/__init__.py", line 13, in <module>
    from .core import Security, RoleMixin, UserMixin, AnonymousUser, current_user
  File "/home/webapps/.pgadmin4/local/lib/python2.7/site-packages/flask_security/core.py", line 28, in <module>
    from .forms import ChangePasswordForm, ConfirmRegisterForm, \
  File "/home/webapps/.pgadmin4/local/lib/python2.7/site-packages/flask_security/forms.py", line 17, in <module>
    from flask_wtf import FlaskForm as BaseForm
  File "/home/webapps/.pgadmin4/local/lib/python2.7/site-packages/flask_wtf/__init__.py", line 17, in <module>
    from .recaptcha import *
  File "/home/webapps/.pgadmin4/local/lib/python2.7/site-packages/flask_wtf/recaptcha/__init__.py", line 2, in <module>
    from .fields import *
  File "/home/webapps/.pgadmin4/local/lib/python2.7/site-packages/flask_wtf/recaptcha/fields.py", line 3, in <module>
    from . import widgets
  File "/home/webapps/.pgadmin4/local/lib/python2.7/site-packages/flask_wtf/recaptcha/widgets.py", line 5, in <module>
    from werkzeug import url_encode
ImportError: cannot import name url_encode

解决办法 卸载Werkzeug 版本太高了

  1. pip install werkzeug==0.16.0

ImportError: cannot import name url_encode

 

Check:

  1. [~/.pgadmin4]: netstat -anlp |grep 5050
  2. tcp 0 0 0.0.0.0:5050 0.0.0.0:* LISTEN 27749/python


Configure nginx domain (attached)

 

https://github.com/rbernardes/nginx-pgadmin

How To Install pgAdmin 4 on Debian 10 / Debian 9

没有评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注