美文网首页
CentOS 7 安装PostgreSQL

CentOS 7 安装PostgreSQL

作者: H_H_H_H_H | 来源:发表于2018-11-28 11:53 被阅读0次

    1、安装yum源。
    到Postgres官网,选择合适的版本,复制其链接
    https://yum.postgresql.org/repopackages.php

    2、以root模式进入CentOS 7,进行安装客户端

    yum install -y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm  -->链接地址为第一步复制的地址
    

    3、安装Postgres

    yum install -y postgresql96-server postgresql96-contrib 
    #(如果使用其他版本的PostgreSQL则需要把其中的两个96换成对应的数字)
    

    4、初始化数据库

    /usr/pgsql-9.6/bin/postgresql96-setup initdb
    #(如果使用其他版本的PostgreSQL则需要把其中的9.6和96换成对应的数字)
    

    5、启动服务

    systemctl start postgresql-9.6  #启动服务
    systemctl enable postgresql-9.6  #设为开机自启 
    #(如果使用其他版本的PostgreSQL则需要把其中的两个9.6换成对应的版本)
    

    6、关闭防火墙

    firewall-cmd --add-service=postgresql --permanent  #开放防火墙。 
    firewall-cmd --reload  #重启防火墙。
    

    7、修改默认密码

    su postgres #切换postgres账户
    psql -U postgres  #登录数据库
    ALTER USER postgres with encrypted password '123456';  #修改数据库密码
    \q  #退出登录的数据库
    exit  #退出用户
    

    8、配置远程访问,配置文件postgresql.conf、pg_hba.conf

    vim /var/lib/pgsql/9.6/data/postgresql.conf
    #listen_addresses字段改为*即为所有IP开放,多个IP用, (逗号+空格)隔开
    
    vim /var/lib/pgsql/9.6/data/pg_hba.conf
    #添加:host all all 0.0.0.0/0 md5
    #如果想允许所有IPv4地址,则加入一行host all all 0.0.0.0/0 md5。IPv6方法类似。 
    

    9、重启服务,测试访问

    systemctl restart postgresql-9.6.service
    

    相关文章

      网友评论

          本文标题:CentOS 7 安装PostgreSQL

          本文链接:https://www.haomeiwen.com/subject/hgsaqqtx.html