centos7下如何安装pgadmin4
环境:
Centos 7
1.下载阿里的 repo 资源配置
[root@pgadmin ~]# cd /etc/yum.repos.d/
[root@pgadmin yum.repos.d]# wget https://mirrors.aliyun.com/repo/epel-7.repo
2.安装 pgdg 资源文件 pgdg-centos11-11-2.noarch.rpm
[root@pgadmin ~]# yum -y install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
或者
[root@pgadmin ~]# wget https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
[root@pgadmin ~]# rpm -ivh ./rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
3.查看可安装版本
[root@localhost ~]# yum search pgadmin
4.安装 pgadmin4
[root@pgadmin ~]# yum install -y pgadmin4
5.复制并配置pgadmin4.conf文件
[root@pgadmin ~]# mv /etc/httpd/conf.d/pgadmin4.conf.sample /etc/httpd/conf.d/pgadmin4.conf
[root@pgadmin ~]# vi /etc/httpd/conf.d/pgadmin4.conf
加入内容:
<VirtualHost *:80>
ServerName pgadmin.cn
# 自带内容
</VirtualHost>
[root@localhost yum.repos.d]# more /etc/httpd/conf.d/pgadmin4.conf
<VirtualHost *:80>
LoadModule wsgi_module modules/mod_wsgi.so
WSGIDaemonProcess pgadmin processes=1 threads=25
WSGIScriptAlias /pgadmin4 /usr/lib/python2.7/site-packages/pgadmin4-web/pgAdmin4.wsgi
<Directory /usr/lib/python2.7/site-packages/pgadmin4-web/>
WSGIProcessGroup pgadmin
WSGIApplicationGroup %{GLOBAL}
<IfModule mod_authz_core.c>
# Apache 2.4
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
</VirtualHost>
6.创建目录
[root@pgadmin ~]# mkdir /var/lib/pgadmin4
[root@pgadmin ~]# mkdir /var/log/pgadmin4
7.给目录授权
[root@pgadmin ~]# chown -R apache:apache /var/log/pgadmin4
[root@pgadmin ~]# chown -R apache:apache /var/lib/pgadmin4
8.修改配置文件config_distro.py
[root@pgadmin ~]# vi /usr/lib/python2.7/site-packages/pgadmin4-web/config_distro.py
写入内容:
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'
9.把服务http加入防火墙白名单(条件允许可关闭防火墙)
也可以关闭防火墙
[root@pgadmin ~]# firewall-cmd --permanent --add-service=http
[root@pgadmin ~]# firewall-cmd --reload
10.初始化pgadmin
[root@localhost yum.repos.d]# python /usr/lib/python2.7/site-packages/pgadmin4-web/setup.py
NOTE: Configuring authentication for SERVER mode.
Enter the email address and password to use for the initial pgAdmin user account:
Email address: slnngk@163.com
Password:
Retype password:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/pgadmin4-web/setup.py", line 413, in <module>
setup_db()
File "/usr/lib/python2.7/site-packages/pgadmin4-web/setup.py", line 347, in setup_db
app = create_app()
File "/usr/lib/python2.7/site-packages/pgadmin4-web/pgadmin/__init__.py", line 711, in create_app
from flask_compress import Compress
ImportError: No module named flask_compress
待解决
11.浏览器访问服务
http://192.168.1.130/pgadmin4