1、首先安装PostgreSQL的rpm
yum install http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-redhat95-9.5-2.noarch.rpm -y
2.安装客户端
yum install postgresql11
3、(可选)安装服务器包:
yum install postgresql11-server
4、初始化数据并启用自动启动
/usr/pgsql-11/bin/postgresql-11-setup initdb
systemctl enable postgresql-11
systemctl start postgresql-11
5、查看数据库状态
systemctl status postgresql-11
6、配置防火墙
firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
7、修改用户密码
su - postgres 切换用户,执行后提示符会变为 ‘-bash-4.2$’
psql -U postgres 登录数据库,执行后提示符变为 ‘postgres=#’
ALTER USER postgres WITH PASSWORD ‘postgres’ 设置postgres用户密码为postgres
\q 退出数据库
8、开启远程访问
vim /var/lib/pgsql/11/data/postgresql.conf
修改#listen_addresses = ‘localhost’ 为 listen_addresses='',并去掉#,当然,此处‘’也可以改为任何你想开放的服务器IP。
修改完毕后,Esc退出,输入“:wq”,保存并退出文本编辑。
9、信任远程连接
vim /var/lib/pgsql/11/data/pg_hba.conf
修改如下内容,信任指定服务器连接
IPv4 local connections:
host all all 127.0.0.1/32 ident
host all all 0.0.0.0/0(需要连接的服务器IP) trust
10、重启服务
systemctl restart postgresql-11