zoukankan      html  css  js  c++  java
  • Centos7在线安装PostgreSQL和PostGIS


    一、版本信息:

    CentOS版本:CentOS-7-x86_64-Minimal-1810

    PostgreSQL版本: PostgreSQL 12.0

    PostGIS版本:postgis31

    二、PostgresSQL + PostGIS 安装

    1、官网安装链接:

    PostgreSQL: Linux downloads (Red Hat family)

    2、升级所有包同时也升级软件和系统内核

    yum -y update

    3、安装rpm文件

    sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

    4、安装PostgreSQL客户端

    使用 yum search postgresql* 命令可以看到多个版本的PostgreSQL,这里我选择了PostgreSQL12。

    yum install -y postgresql12

    5、安装PostgreSQL服务端

    yum install -y postgresql12-server

    6、初始化

    /usr/pgsql-12/bin/postgresql-12-setup initdb

    7、设置自动启动并且启动postgresql服务

    systemctl enable postgresql-12
    systemctl start postgresql-12

    8、postgresql官网上有明确的操作步骤

    image

    三、创建用户和数据库

    1、使用postgres用户登录(PostgresSQL安装后会自动创建postgres用户,无密码)

    su postgres

    image

    2、登录postgresql数据库

    image

    3、创建用户和数据库并授权

    create user test_user with password '123456';            // 创建用户
    create database test_db owner test_user;                 // 创建数据库
    grant all privileges on database test_db to test_user;   // 授权

    image

    4、退出psql(输入 \q 再按回车键即可)

    \q

    四、开启远程访问

    1、修改/var/lib/pgsql/12/data/postgresql.conf文件,取消 listen_addresses 的注释,将参数值改为“*”

    image

    image

    2、修改/var/lib/pgsql/12/data/pg_hba.conf文件,增加下图红框部分内容

    image

    image

    文件分为5列,分别是TYPE、DATABASE、USER、ADDRESS、METHOD,可以对不同IP地址的用户设置不同数据库的访问权限。最后一列METHOD的解析如下:
    trust 任何连接都允许,不需要密码
    reject 拒绝符合条件(前面几个条件)的请求
    MD5 接收一个MD5加密过的密码
    password 接收一个密码来登陆,只在可信的网络使用这种方式
    gss 使用gssapi认证,只在tcp/ip连接可用
    sspi 只在windows可用的一种方式
    krb5 不常用,只在TCP/IP可用
    ident 使用操作系统用户名认证,验证它是否符合请求的的数据库用户名
    ldap 使用LDAP服务器认证
    cert 使用ssl客户端认证
    pam 使用操作系统的pam模块服务
    如果要求所有IP都是使用密码登录,则配置为host all all 0.0.0.0/0 md5

    3、切换到root用户,重启postgresql服务

    systemctl restart postgresql-12.service

    4、关闭防火墙

    查看防火墙状态
    firewall-cmd --state
    
    停止firewall
    systemctl stop firewalld.service
    
    开启firewall
    firewall-cmd --state
    
    禁止firewall 开机启动
    systemctl disable firewalld.service

    5、使用数据库连接工具测试连接

    image

    image

    五、额外补充

    1、修改默认生成的 postgres 用户密码(此postgres非上面的postgres用户,此为数据库的用户,上面的为操作系统的用户)

    su - postgres
    psql -U postgres
    alter user postgres with encrypted password '123456';

    2、服务启动、关闭、重启、查看状态命令

    systemctl start postgresql-12.service     // 启动服务
    systemctl stop postgresql-12.service      // 关闭服务
    systemctl restart postgresql-12.service   // 重启服务
    systemctl status postgresql-12.service    // 查看状态


    六、安装postgis和pgRouting

    1、安装postgis的依赖包

    rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

    2、安装postgis

    yum install postgis31_12.x86_64

    3、安装完毕后切换为postgres用户,开启扩展

    // 开启插件  
    # su postgres  
    # psql  
    // 开启pgsql的插件  
    postgres=# create extension postgis;  
    postgres=# create extension postgis_topology;  
    postgres=# create extension fuzzystrmatch;  
    postgres=# create extension address_standardizer;  
    postgres=# create extension address_standardizer_data_us;  
    postgres=# create extension postgis_tiger_geocoder; 
    //查看版本,验证安装是否成功
    postgres=# SELECT PostGIS_full_version();

    4、安装pgRouting

    使用 yum search pgrouting 命令可以看到多个版本的pgrouting,这里我选择了pgrouting12。

    yum install pgrouting_12

    image

    5、最终已安装扩展如下:

    image

  • 相关阅读:
    Flutter Icons 内置图标库,全套Material图标
    解决cannot connect to daemon at tcp:5037: cannot connect to 127.0.0.1:5037: 由于目标计算机积极拒绝,无法连接。 (10061).
    mavenCentral()、jcenter()、google()仓库
    flutter doctor检查出现多个Android Studio解决办法
    Oracle trunc 函数用法详解
    将博客搬至CSDN
    Yii2 高级模板不使用Apache配置目录,将前后台入口移到根目录
    报警告session_regenerate_id(): Failed to create(read) session ID: files (path: N;/path)
    yii2GridView的简单使用
    yii 表单如何写,action指向哪里?
  • 原文地址:https://www.cnblogs.com/haolb123/p/15775141.html
Copyright © 2011-2022 走看看