Centos 8 安装 PostgreSQL PGAdmin4

本文只讲PostgreSQL在 almalinux8.6或centos8.0 下的安装,其他系统请查看:https://www.postgresql.org/download

# Install the repository RPM:
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Disable the built-in PostgreSQL module:
sudo dnf -qy module disable postgresql

# Install PostgreSQL:
sudo dnf install -y postgresql12-server

# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
sudo systemctl enable postgresql-12
sudo systemctl start postgresql-12

6.配置防火墙

systemctl stop firewalld
systemctl disable firewalld
iptables -F
iptables -X
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT

7.修改用户密码

su - postgres  切换用户,执行后提示符会变为 '-bash-4.2$'
psql -U postgres 登录数据库,执行后提示符变为 'postgres=#'
ALTER USER postgres WITH PASSWORD 'postgres'  设置postgres用户密码为postgres
\q  退出数据库

8.开启远程访问

vim /var/lib/pgsql/12/data/postgresql.conf
修改#listen_addresses = 'localhost'  为  listen_addresses='*'
当然,此处‘*’也可以改为任何你想开放的服务器IP

9.信任远程连接

vim /var/lib/pgsql/12/data/pg_hba.conf
修改如下内容,信任指定服务器连接
# IPv4 local connections:
host    all            all      127.0.0.1/32      trust
host    all            all      192.168.157.1/32(需要连接的服务器IP,如果是所有则0.0.0.0/0)  trust

10.重启服务

systemctl restart postgresql-12

11.使用DBMS软件连接

这里使用的是Navicat

连接成功:

 

 安装 PGAdmin4:

1:yum -y install epel-release

2.yum install pgadmin4

3./usr/pgadmin4/bin/pgadmin4-web-setup.sh

4.

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

vim config_local.py
#设置你希望的IP,0.0.0.0表示不受限制,如果你只希望局域网内访问,请使用适当的局域网ip
DEFAULT_SERVER = '0.0.0.0'
#设置你希望的端口
DEFAULT_SERVER_PORT = 8080
 
5.python /usr/lib/python2.7/site-packages/pgadmin4-web/pgAdmin4.py
posted @ 2018-05-16 21:23  littlewrong  阅读(2697)  评论(0编辑  收藏  举报