Install required packages:
apt install build-essential libssl-dev libffi-dev virtualenv python-pip libpq-dev python-dev
Create directories/permissions:
- mkdir -p /var/lib/pgadmin4/sessions
- mkdir /var/lib/pgadmin4/storage
- mkdir /var/log/pgadmin4
- chown -R user:(当前用户) /var/lib/pgadmin4/
- chown -R user:(当前用户) /var/log/pgadmin4/
Enable virtualenv and install pgadmin (at this time 4.4.11):
- virtualenv .pgadmin4
- cd .pgadmin4/
- source bin/activate
- wget https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v4.11/pip/pgadmin4-4.11-py2.py3-none-any.whl
- pip install pgadmin4-4.11-py2.py3-none-any.whl
Configure server environment:
vi nano lib/python2.7/site-packages/pgadmin4/config_local.py
- ---
- DEFAULT_SERVER = '0.0.0.0'
- DEFAULT_SERVER_PORT = 5050
- LOG_FILE = '/var/log/pgadmin4/pgadmin4.log'
- SQLITE_PATH = '/var/lib/pgadmin4/pgadmin4.db'
- SESSION_DB_PATH = '/var/lib/pgadmin4/sessions'
- STORAGE_DIR = '/var/lib/pgadmin4/storage'
- SERVER_MODE = True
-
---
Setup pgadmin4:
- python lib/python2.7/site-packages/pgadmin4/setup.py
- NOTE: Configuring authentication for SERVER mode.
- Enter the email address and password to use for the initial pgAdmin user account:
- Email address: youremail@address
- Password:
- Retype password:
- pgAdmin 4 - Application Initialisation
- ======================================
Change permission to nginx access:
- chown -R www-data:www-data /var/lib/pgadmin4/
- chown -R www-data:www-data /var/log/pgadmin4/
Create script to start pgadmin:
- vim /usr/local/bin/pgadmin.sh
- #!/bin/bash . /home/webapps/.pgadmin4/bin/activate
- # virtualenv is now active.
- #
- nohup python /home/webapps/.pgadmin4/lib/python2.7/site-packages/pgadmin4/pgAdmin4.py &
chmod +x /usr/local/bin/pgadmin.sh
Run script:
- [~/.pgadmin4]: pgadmin.sh
- [~/.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
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 版本太高了
- pip install werkzeug==0.16.0
ImportError: cannot import name url_encode
Check:
- [~/.pgadmin4]: netstat -anlp |grep 5050
- 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
没有评论