您的位置:首页 > 运维架构 > Linux

Centos7下安装postgresql-9.5

2016-12-21 17:42 357 查看
1.添加RPM

    yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm
2.安装PostgreSQL 9.5

    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



自此,PostgreSQL 9.5 安装完成,此过程中注意安装权限,我在安装过程中一直使用的是root用户进行的安装。

接下来,进行一下简单的配置。

PostgreSQL 安装完成后,会建立一下‘postgres’用户,用于执行PostgreSQL,数据库中也会建立一个'postgres'用户,默认密码为自动生成,需要在系统中改一下。

6.修改用户密码

    su - postgres  切换用户,执行后提示符会变为 '-bash-4.2$'

    psql -U postgres 登录数据库,执行后提示符变为 'postgres=#'

    ALTER USER postgres WITH PASSWORD 'abc123'  设置postgres用户密码

    \q  退出数据库



系统管理用的帐号和密码变更完成,现在配置一下远程连接。

7.开启远程访问

    vi /var/lib/pgsql/9.5/data/postgresql.conf

    修改#listen_addresses = 'localhost'  为  listen_addresses='*'

    当然,此处‘*’也可以改为任何你想开放的服务器IP



8.信任远程连接

    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



远程连接配置完成,由于系统原因,还需要在防火墙中打开相应的端口。

9.打开防火墙

    CentOS 防火墙中内置了PostgreSQL服务,配置文件位置在/usr/lib/firewalld/services/postgresql.xml,我们只需以服务方式将PostgreSQL服务开放即可。

    firewall-cmd --add-service=postgresql --permanent  开放postgresql服务

    firewall-cmd --reload  重载防火墙



最后一步,不能忘记的,是重启数据库服务,使配置生效。

10. 重启PostgreSQL数据服务

    systemctl restart postgresql-9.5.service

至此,PostgreSQL 9.5 在CentOS 7上完成基本安装和配置。

文/lasko(简书作者)

原文链接:http://www.jianshu.com/p/7e95fd0bc91a

远程连接设置:
修改pg_hba.conf中ipv4的设置
# IPv4 local connections:

host    all             all             0.0.0.0/0            trust
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: