安装postgresql步骤:
1、yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm
2、yum install postgresql95-server postgresql95-contrib
3、/usr/pgsql-9.5/bin/postgresql95-setup initdb
4、systemctl enable postgresql-9.5.service
5、 systemctl start postgresql-9.5.service
6、自此,PostgreSQL 9.5 安装完成,此过程中注意安装权限,我在安装过程中一直使用的是root用户进行的安装。
接下来,进行一下简单的配置。
PostgreSQL 安装完成后,会建立一下‘postgres’用户,用于执行PostgreSQL,数据库中也会建立一个'postgres'用户,默认密码为自动生成,需要在系统中改一下。
7、修改用户密码
su - postgres 切换用户,执行后提示符会变为 '-bash-4.2$'
psql -U postgres 登录数据库,执行后提示符变为 'postgres=#'
ALTER USER postgres WITH PASSWORD 'abc123' 设置postgres用户密码
\q 退出数据库
8、系统管理用的帐号和密码变更完成,现在配置一下远程连接。
.开启远程访问
vi /var/lib/pgsql/9.5/data/postgresql.conf
修改#listen_addresses = 'localhost' 为 listen_addresses='*'
当然,此处‘*’也可以改为任何你想开放的服务器IP
9、信任远程连接
vi /var/lib/pgsql/9.5/data/pg_hba.conf
修改如下内容,信任指定服务器连接
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 10.211.55.6/32(需要连接的服务器IP) trust
10、远程连接配置完成,由于系统原因,还需要在防火墙中打开相应的端口。
CentOS 防火墙中内置了PostgreSQL服务,配置文件位置在/usr/lib/firewalld/services/postgresql.xml,我们只需以服务方式将PostgreSQL服务开放即可。
firewall-cmd --add-service=postgresql --permanent 开放postgresql服务
firewall-cmd --reload 重载防火墙
11、最后一步,不能忘记的,是重启数据库服务,使配置生效。
重启PostgreSQL数据服务
systemctl restart postgresql-9.5.service