CentOS7.4安装配置PostgreSQL

PostgreSQL安装过程 详情请参考官方文档

1.添加RPM

yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

2.安装PostgreSQL

yum install postgresql10 postgresql10-server

3.初始化数据库并设置开机自启动

/usr/pgsql-10/bin/postgresql-10-setup initdb
systemctl enable postgresql-10
systemctl start postgresql-10

《CentOS7.4安装配置PostgreSQL》 初始化并开机自启

4.修改默认PostgreSQL用户密码
PostgreSQL的默认用户为“postgres”。

//切换用户
su  postgres

//登录数据库
psql -U postgres

//修改默认用户的密码(不要漏了“;”)
ALTER USER postgres with encrypted password '123456';

//退出数据库
\q

//退出用户
exit

《CentOS7.4安装配置PostgreSQL》 修改密码

5.配置远程访问

//禁用SELinux
vi /etc/selinux/config
SELINUX=disabled  //将其他项注释掉,添加这一行

//配置防火墙
firewall-cmd --set-default-zone=trusted
firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --reload

//允许数据库远程连接
vi /var/lib/pgsql/10/data/postgresql.conf
将#listen_addresses = 'localhost'  为  listen_addresses='*'

//信任远程连接
vi /var/lib/pgsql/10/data/pg_hba.conf
//在“IPv4 local connections”下方添加允许连接的IP。 
//如果想允许所有IPv4地址,则加入一行“host all all 0.0.0.0/0 md5”。IPv6方法类似。 

《CentOS7.4安装配置PostgreSQL》 配置远程访问

《CentOS7.4安装配置PostgreSQL》 配置远程访问

《CentOS7.4安装配置PostgreSQL》 配置远程访问

6.测试远程连接

《CentOS7.4安装配置PostgreSQL》 测试远程连接

    原文作者:码侬小柯
    原文地址: https://www.jianshu.com/p/935168d54d9c
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞