一、准备工作: 1.postgresql官网:https://www.postgresql.org 2.下载页面:https://www.postgresql.org/download/ 3.Red Hat家族Linux(包括CentOS/Fedora/Scientific/Oracle)下载页面:https://www.postgresql.org/download/linux/redhat/ 4.本文使用系统为:centos 7.5 1804 5.可以使用一下网址找到对应的postgresql yum安装版本 页面: https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm 二、系统执行命令:
yum install -y 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
/usr/pgsql-11/bin/postgresql-11-setup initdb
systemctl enable postgresql-11
systemctl start postgresql-11
三、开通PostgreSQL端口(如果防火墙关闭可以忽略此步骤)
firewall-cmd --zone=public --add-port=5432/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-ports
四、设置postgres的密码
Last login: Fri Jul 19 17:13:49 CST 2019 on pts/0
-bash-4.2$ psql -U postgres
psql (11.4)
Type "help" for help
postgres=# ALTER USER postgres with encrypted password 'welcome1';
ALTER ROLE
postgres=# \q
-bash-4.2$ exit
logout
. 五、设置远程访问 命令:
vim /var/lib/pgsql/11/data/postgresql.conf
打开后找到:listen_addresses修改为: listen_addresses = '' 要监听的IP地址;以逗号分隔的地址列表;默认为'localhost';对所有人使用''。修改完毕后保存关闭。
命令:
vim /var/lib/pgsql/11/data/pg_hba.conf
打开后文本新增内容如下:
host all all 0.0.0.0/0 md5
修改完成后保存关闭编辑。
六.重启postgres 数据库
systemctl restart postgresql-11