1、安装前环境,postgresql=9.6.3,版本最好在9.6-10.0之间
源码安装postgresql链接:https://blog.csdn.net/a13568hki/article/details/105431663
2.安装Proj4
wget http://download.osgeo.org/proj/proj-4.9.3.tar.gz
tar -xf proj-4.9.3.tar.gz
cd proj-4.9.3
./configure --prefix=/usr/proj
make
make install
echo "/usr/proj/lib" > /etc/ld.so.conf.d/proj-4.9.3.conf
ldconfig
3.安装GEOS
wget http://download.osgeo.org/geos/geos-3.6.1.tar.bz2
tar -jxf geos-3.6.1.tar.bz2
cd geos-3.6.1
./configure --prefix=/usr/geos
make
make install
echo "/usr/geos/lib" > /etc/ld.so.conf.d/geos-3.6.1.conf
ldconfig
4.安装GDAL
wget http://download.osgeo.org/gdal/2.1.2/gdal-2.1.2.tar.gz
tar -xf gdal-2.1.2.tar.gz
cd gdal-2.1.2
./configure --prefix=/usr/gdal
make
make install
echo "/usr/gdal/lib" > /etc/ld.so.conf.d/gdal-2.1.2.conf
ldconfig
4、安装postgis依赖
yum -y install perl-devel
yum -y install libxml2-devel
5.安装postgis
wget http://download.osgeo.org/postgis/source/postgis-2.2.5.tar.gz
tar -xf postgis-2.2.5.tar.gz
cd postgis-2.2.5
./configure --with-pgconfig=/opt/postgresql/bin/pg_config --with-geosconfig=/usr/geos/bin/geos-config --with-gdalconfig=/usr/gdal/bin/gdal-config --with-projdir=/usr/proj --prefix=/opt/postgresql/share/contrib/postgis
make
make install
6、使PostGIS可用
想要在PostgreSQL中使用PostGIS插件,安装只是第一步。每个数据库想要使用PostGIS必须先在该数据库中使PostGIS可用。假设我们想在gisdb这个数据库中使用PostGIS,先进入gisdb数据库,执行以下步骤:
[postgres@c3349c483e7c postgis-2.2.5]$ psql
proxydb=# create extension postgis;
CREATE EXTENSION
proxydb=# create extension postgis_topology ;
CREATE EXTENSION
proxydb=#
7 查看是否安装成功
在gisdb数据库中输入\dx,查看已安装的插件
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
------------------+---------+------------+---------------------------------------------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
postgis | 2.2.5 | public | PostGIS geometry, geography, and raster spatial types and functions
postgis_topology | 2.2.5 | topology | PostGIS topology spatial types and functions
(3 rows)
可以看到已经安装了postgis和postgis_topology。