centos7上PostgreSQL11安装与配置

限于喜欢 提交于 2020-01-13 01:20:51

1、安装epel

yum -y install epel-release

2、安装PostgreSQL11

yum -y install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
yum -y install postgresql11
yum -y install postgresql11-server
# 附带安装
yum -y install postgresql11-libs postgresql11-contrib postgresql11-devel
# 初始化数据,并设置开机自启动
/usr/pgsql-11/bin/postgresql-11-setup initdb
systemctl enable postgresql-11
systemctl start postgresql-11

3、修改PostgreSQL创建的linux用户 postgres

passwd postgres

4、配置可以访问PostgreSQL的ip(更多参考此处

sudo vim /var/lib/pgsql/11/data/postgresql.conf
# '192.168.1.188' 是本机ip
listen_addresses = 'localhost'  ==> '192.168.1.188'
sduo vim /var/lib/pgsql/11/data/pg_hba.conf
# # 修改前
# IPv4 local connections:
host    all             all             127.0.0.1/32            ident
# # 修改后
# # 192.168.1.0/24 表明 192.168.1.* 都能访问PostgreSQL
# IPv4 local connections:
host    all             all             192.168.1.0/24          trust

5、重启服务,并测试是否能够正常访问到PostgreSQL

sudo systemctl restart postgresql-11
# 测试访问是否正常
curl 192.168.1.188:5432
# 正常返回如下
curl: (52) Empty reply from server

6、若无法访问,修改防火墙设置(更多设置参考此处

# 查看防火墙状态
sudo firewall-cmd --state
# 添加可以访问该主机的ip
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="5432" accept"
# 重启服务
sudo systemctl restart firewalld.service
# 查看
sudo firewall-cmd --list-all

修改防火墙设置之后,一定要记得重启服务!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!