CentOS 7 源码安装PostGIS

本文认为已安装PostgreSQL9.6,安装步骤如 Centos7安装PostgreSQL9.6。 注意,作者将Pg9.6直接安装到了postgres用户下如下图:

Postgresql数据库安装全目录 下文其他依赖编译到pg的目录下最好,自行对照自己的修改下。 从源码安装,需要安装/编译GEOSProj.4GDAL,LibXML2 和JSON-C,所以一步步安装。

一 编译GEOS

$ cd ~    
$ wget http://download.osgeo.org/geos/geos-3.5.0.tar.bz2    
$ tar -jxvf geos-3.5.0.tar.bz2     
$ cd geos-3.5.0    
$ ./configure --prefix=/home/postgres/geos    --安装到PostgreSQL的账户里
$ make -j 32    
$ make install    

作者在执行make -j 32时报错如下:

g++: command not found

于是直接yum先装上再说:

yum install gcc-c++

但是执行make -j 32时仍然报错,报错显示:

error:#error "Can not compile without isnan function or macro"

报错截图.png 经过网友指点如下:

# 在geos解压的文件中,找到/include/config.h
# 编辑该文件,取消#undef HAVE_ISNAN的注释,保存退出
#然后重新配置geos如下:
$ ./configure --prefix=/home/postgres/geos
$ make -j 32     #等待编译完成时间蛮长的。
$ make install    #正常编译完成

config.h文件目录位置取消对HAVE_ISNAN的注释

二 编译Proj

$ cd ~    
$ wget http://download.osgeo.org/proj/proj-4.9.2.tar.gz    
$ tar -zxvf proj-4.9.2.tar.gz    
$ cd proj-4.9.2    
$ ./configure --prefix=/home/postgres/proj4    
$ make -j 32    
$ make install   

三 编译GDAL

$ cd ~    
$ wget http://download.osgeo.org/gdal/2.1.1/gdal-2.1.1.tar.gz    
$ tar -zxvf gdal-2.1.1.tar.gz    
$ cd gdal-2.1.1    
#以下编译安装要花很长时间,想死
$ ./configure --prefix=/home/postgres/gdal --with-pg=/home/postgres/bin/pg_config    
$ make -j 32    
$ make install    

四 LibXML2 json-c 等等

# yum install -y libtool libxml2 libxml2-devel libxslt libxslt-devel json-c json-c-devel cmake gmp gmp-devel mpfr mpfr-devel boost-devel pcre-devel

五 安装PostGIS

看PostGIS官网的描述很简单,直接就典型的make makeinstall编译安装,很简洁,但是实际安就装会发现很多依赖库根本找不到如下图某个could not find GDAL这样,即使明明安装了,也找不到。 会报各种配置依赖找不到错误,典型的是gdal.png 这种问题一般都是链接库找不到,需要手动进行软连接等各种配置,正确配置后才能正确编译。

5.1 配置依赖库软连接

#编辑ld.so.conf文件。
[root@pg1 postgres]# vim /etc/ld.so.conf
#边界内容如下
/home/postgres/lib
/home/postgres/geos/lib
/home/postgres/proj4/lib
/home/postgres/gdal/lib
#编辑完成后wq!保存退出

[root@pg1 postgres]# ldconfig    #保存配置生效

5.2 配置Postgres用户环境变量

[root@pg1 postgres]#  su - postgres
[root@pg1 postgres]#  vim .bashrc
#原先这个用户环境变量配置了Postgres的东西,现在加进一些依赖进来
PGHOME=/home/postgres
export PGHOME
PGDATA=$PGHOME/data
export PGDATA

export LD_LIBRARY_PATH=/home/postgres/geos/lib:/home/postgres/proj4/lib:/home/postgres/gdal/lib::$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin
export PATH
#编辑完成wq!保存退出。

[root@pg1 postgres]# source .bashrc #重启配置生效

5.3 编译安装PostGIS

$ wget http://download.osgeo.org/postgis/source/postgis-2.3.0.tar.gz    
$ tar -zxvf postgis-2.3.0.tar.gz    
$ cd postgis-2.3.0 
$ ./configure --prefix=/home/postgres   
--with-gdalconfig=/home/postgres/gdal/bin/gdal-config   
--with-pgconfig=/home/postgres/bin/pg_config    
--with-geosconfig=/home/postgres/geos/bin/geos-config  
--with-projdir=/home/postgres/proj4    
$  make
$ make install

六 创建postgis扩展

[root@pg1 postgres]# psql Test
Test=# create extension postgis;
CREATE EXTENSION
#在测试数据库中创建扩展成功。

转载于:https://my.oschina.net/freegis/blog/781657

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值