【CentOS7安装postgresql-9.6.X及配置远程访问】

通过官网获取下载地址,选择自己所需要的版本: https://www.postgresql.org/download/
开始安装:
1.安装存储库
2.安装客户端
yum install postgresql96
3.安装服务端
yum install postgresql96-server
4.验证是否安装成功
rpm -aq| grep postgres
5.初始化数据库
/usr/pgsql-9.6/bin/postgresql96-setup initdb
6.启用开机自启动
systemctl enable postgresql-9.6
systemctl start postgresql-9.6
7.配置防火墙(阿里云ECS不需要执行此项)
firewall-cmd --permanent --add-port=5432/tcp 
firewall-cmd --permanent --add-port=80/tcp 
firewall-cmd --reload
8.修改用户密码
    su - postgres  切换用户,执行后提示符会变为 '-bash-4.2$'     psql -U postgres 登录数据库,执行后提示符变为 'postgres=#'     ALTER USER postgres WITH PASSWORD 'postgres'  设置postgres用户密码为postgres     \q  退出数据库
9.开启远程访问
    vi /var/lib/pgsql/9.6/data/postgresql.conf     修改#listen_addresses = 'localhost'  为  listen_addresses='*'
10.信任远程连接
    vi /var/lib/pgsql/9.6/data/pg_hba.conf         修改如下内容,信任指定服务器连接     # IPv4 local connections:     host    all            all      127.0.0.1/32      trust     host    all            all     (你的服务器IP)/32(需要连接PGSQL的服务器IP)  trust
11.重启服务
systemctl restart postgresql-9.6
12.阿里云ECS配置允许外网访问PGSQL
 

猜你喜欢

转载自www.cnblogs.com/zuixinxian/p/11532383.html
今日推荐