Linux安装postgresql+postgis流程

1.     postgresql的下载安装

        (1)解压,tar -zxvf   XXXX

          (2) ./configure

          (3) make

          (4) make install

  error处理:
        报错readline library not found,执行 yum -y install -y readline-devel
        报错zlib not found, 执行 yum install zlib-devel
    

2.  添加用户
     useradd postgres    #新增用户
     passwd postgres    #为用户设置密码

3.  添加数据管理,并init数据库
    mkdir /usr/local/pgsql/data   
    chown postgres /usr/local/pgsql/data    #设置data文件加属性
    chmod 700 /usr/local/pgsql/data    #设置data文件夹权限
    /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data    #初始化数据库
    /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &  #设置日志输出位置    root用户
    
4. 数据库的启动,停止,重启
    ./pg_ctl start\stop\restart -D /usr/local/pgsql/data/   #启动\停止\重启数据库 
    
    
5.创建数据库
     createdb postgis_24_sample
    
6.远程连接
    vi /etc/profile  
    添加:
        LD_LIBRARY_PATH=/usr/local/pgsql/lib  
        export LD_LIBRARY_PATH  
        PATH=/usr/local/pgsql/bin:$PATH  
        export PATH  
    
    //开放端口
    service iptables start  
    iptables -I INPUT 7 -p tcp –dport 5432:5438 -j ACCEPT  
    service iptables save  
    service iptables restart  
    
       
7.安装geos-3.6.3.tar.bz2

    tar jxvf geos-3.5.0.tar.bz2  
    cd geos-3.6.3
    ./configure  
    make  
    make install 
    
8.安装proj-5.1.0.tar.gz

    tar xzvf proj-5.1.0.tar.gz
    cd proj-5.1.0  
    ./configure  
    make  
    make install
      
9.安装gdal-2.3.1.tar.gz
    tar xzvf gdal-2.3.1.tar.gz
    cd gdal-2.3.1 
    ./configure  
    make  
    make install
    
    错误:缺少libgdal.so.5
    处理: yum install postgresql*
    

10.安装LibXML2

    //先安装python-devel插件
    yum -y install python-devel
    
    tar xzvf libxml2-2.9.0.tar.gz  
    cd libxml2-2.9.0  
    ./configure  
    make  
    make install  
    
    安装默认路径/usr/local
    安装后可能需要重新定义:
    export LD_LIBRARY_PATH=/usr/local/lib
    export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
        
        
11.安装json-c

    yum install json-c json-c-devel
    
    
12.安装postgis

    tar zxvf postgis-2.2.2.tar.gz  
    cd postgis-2.2.2  
    ./configure
    make  
    make install
    
    
13.安装完成后连接并添加扩展
    //服务器问题特有的问题
    (1)libgeos_c.so.1缺少
        //解决:执行命令
        echo /usr/local/lib > /etc/ld.so.conf.d/local.conf  
        /sbin/ldconfig 

14. 连接数据库后添加Postgis扩展

   CREATE EXTENSION postgis;    # 仅此项扩展便支持geometry类型

   CREATE EXTENSION pgrouting;

   CREATE EXTENSION postgis_topology;

   CREATE EXTENSION fuzzystrmatch;

   CREATE EXTENSION postgis_tiger_geocoder;

   CREATE EXTENSION address_standardizer;

 

 

 

转载自:https://blog.csdn.net/helloworld_xwb/article/details/82257087

You may also like...