环境:
centos7
postgresql12
postgis3.0.1
posgis3.0.1 依赖
https://postgis.net/2020/02/20/postgis-3.0.1/
The PostGIS Team is pleased to release PostGIS 3.0.1.
Best served with PostgreSQL 12.2, GEOS 3.8.0, SFCGAL 1.3.7, GDAL 3.0.4, PROJ 6.3.1, protobuf-c 1.3.3, json-c 0.13.1.
1.cmake安装
wget https://github.com/Kitware/CMake/releases/download/v3.16.8/cmake-3.16.8.tar.gz
tar -zxvf cmake-3.16.8.tar.gz
cd cmake-3.16.8
./bootstrap --prefix=/usr/local/cmake
gmake
gmake install
wget https://github.com/Kitware/CMake/releases/download/v3.16.8/cmake-3.16.8.tar.gz
tar -zxvf cmake-3.16.8.tar.gz
cd cmake-3.16.8
./bootstrap --prefix=/usr/local/cmake
gmake
gmake install
2.安装GEOS
wget https://download.osgeo.org/geos/geos-3.8.1.tar.bz2
tar -jxf geos-3.8.1.tar.bz2
cd geos-3.8.1
./configure --prefix=--prefix=/data/apps/pgsql/12/plus/geos-3.8.1
make && make install
wget https://download.osgeo.org/geos/geos-3.8.1.tar.bz2
tar -jxf geos-3.8.1.tar.bz2
cd geos-3.8.1
./configure --prefix=--prefix=/data/apps/pgsql/12/plus/geos-3.8.1
make && make install
3.安装proj
wget http://download.osgeo.org/proj/proj-6.3.2.tar.gz
tar -zxvf proj-6.3.2.tar.gz
cd proj-6.3.2
./configure --prefix=/usr/local/proj-6.3.2
# 编译时遇到下面的问题,说是sqlite版本太低!编译成功再进行下一步!
make && make install
wget http://download.osgeo.org/proj/proj-6.3.2.tar.gz
tar -zxvf proj-6.3.2.tar.gz
cd proj-6.3.2
./configure --prefix=/usr/local/proj-6.3.2
# 编译时遇到下面的问题,说是sqlite版本太低!编译成功再进行下一步!
make && make install
3.1安装sqlite3
wget http://www.sqlite.org/2020/sqlite-autoconf-3320200.tar.gz
wget http://www.sqlite.org/2020/sqlite-autoconf-3320200.tar.gz
[root@localhost ~]#yum remove sqlite-devel
[root@localhost ~]# tar zxvf sqlite-autoconf-3320200.tar.gz -C /usr/src
[root@localhost ~]#yum remove sqlite-devel
[root@localhost ~]# tar zxvf sqlite-autoconf-3320200.tar.gz -C /usr/src
[root@localhost ~]#cd sqlite-autoconf-3320200/ ./configure --prefix=/usr/local/sqlite
[root@localhost ~]#cd sqlite-autoconf-3320200/ ./configure --prefix=/usr/local/sqlite
替换版本
mv /usr/bin/sqlite3 /usr/bin/sqlite3_old
cd /usr/local/sqlite/bin/
ln -s /usr/local/sqlite/bin/sqlite3 /usr/bin/sqlite3
mv /usr/bin/sqlite3 /usr/bin/sqlite3_old
cd /usr/local/sqlite/bin/
ln -s /usr/local/sqlite/bin/sqlite3 /usr/bin/sqlite3
共享库修改,注意sqlite的安装路径
vim /etc/profile
export LD_LIBRARY_PATH="/usr/local/sqlite/lib"
vim /etc/profile
export LD_LIBRARY_PATH="/usr/local/sqlite/lib"
查看sqlite版本信息
[root@beta postgis-3.0.1]# sqlite3 --version
3.32.2 2020-06-04 12:58:43 ec02243ea6ce33b090870ae55ab8aa2534b54d216d45c4aa2fdbb00e86861e8c
[root@beta postgis-3.0.1]# sqlite3 --version
3.32.2 2020-06-04 12:58:43 ec02243ea6ce33b090870ae55ab8aa2534b54d216d45c4aa2fdbb00e86861e8c
find / -name sqlite3.pc
/usr/local/sqlite/lib/pkgconfig/sqlite3.pc
复制
cp /usr/local/lib/pkgconfig/sqlite3.pc /usr/lib64/pkgconfig/
find / -name sqlite3.pc
/usr/local/sqlite/lib/pkgconfig/sqlite3.pc
复制
cp /usr/local/lib/pkgconfig/sqlite3.pc /usr/lib64/pkgconfig/
3.2安装proj
wget http://download.osgeo.org/proj/proj-6.3.2.tar.gz
tar -zxvf proj-6.3.2.tar.gz
cd proj-6.3.2
./configure --prefix=/data/apps/pgsql/12/plus/proj-6.3.2
make && make install
wget http://download.osgeo.org/proj/proj-6.3.2.tar.gz
tar -zxvf proj-6.3.2.tar.gz
cd proj-6.3.2
./configure --prefix=/data/apps/pgsql/12/plus/proj-6.3.2
make && make install
4.安装GDAL
wget https://download.osgeo.org/gdal/3.0.4/gdal-3.0.4.tar.gz
tar -zxvf gdal-3.0.4.tar.gz
cd gdal-3.0.4
[root@beta gdal-3.0.4]# ./configure --prefix=/data/apps/pgsql/12/plus/gdal-3.0.4 --with-proj=/data/apps/pgsql/12/plus/proj-6.3.2 --with-pg=/data/apps/pgsql/12
[root@beta gdal-3.0.4]# make && make install
wget https://download.osgeo.org/gdal/3.0.4/gdal-3.0.4.tar.gz
tar -zxvf gdal-3.0.4.tar.gz
cd gdal-3.0.4
[root@beta gdal-3.0.4]# ./configure --prefix=/data/apps/pgsql/12/plus/gdal-3.0.4 --with-proj=/data/apps/pgsql/12/plus/proj-6.3.2 --with-pg=/data/apps/pgsql/12
[root@beta gdal-3.0.4]# make && make install
5.安装protubuf
./configure: No such file or directory
yum install automake
autoreconf -i
下载地址
https://github.com/protocolbuffers/protobuf/issues/6599
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.15.3/protobuf-all-3.15.3.tar.gz
[root@beta protobuf-3.15.2]#./configure --prefix=/data/apps/pgsql/12/plus/protobuf-3.15.2
make && make install
export PKG_CONFIG_PATH=/data/apps/pgsql/12/plus/protobuf-3.15.2/lib/pkgconfig
./configure: No such file or directory
yum install automake
autoreconf -i
下载地址
https://github.com/protocolbuffers/protobuf/issues/6599
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.15.3/protobuf-all-3.15.3.tar.gz
[root@beta protobuf-3.15.2]#./configure --prefix=/data/apps/pgsql/12/plus/protobuf-3.15.2
make && make install
export PKG_CONFIG_PATH=/data/apps/pgsql/12/plus/protobuf-3.15.2/lib/pkgconfig
6.安装protobuf-c
wget https://github.com/protobuf-c/protobuf-c/releases/download/v1.3.3/protobuf-c-1.3.3.tar.gz
tar -xzvf protobuf-c-1.3.3.tar.gz
cd protobuf-c-1.3.3
export PKG_CONFIG_PATH=/usr/local/protobuf-3.11.4/lib/pkgconfig
./configure --prefix=/data/apps/pgsql/12/plus/protobuf-c-1.3.3
make && make install
wget https://github.com/protobuf-c/protobuf-c/releases/download/v1.3.3/protobuf-c-1.3.3.tar.gz
tar -xzvf protobuf-c-1.3.3.tar.gz
cd protobuf-c-1.3.3
export PKG_CONFIG_PATH=/usr/local/protobuf-3.11.4/lib/pkgconfig
./configure --prefix=/data/apps/pgsql/12/plus/protobuf-c-1.3.3
make && make install
7.安装SFCGAL 1.3.7
由于SFCGAL需要依赖Boost、CGAL、GMP、MPFR这四个软件,所以具体总共需要安装以下四个软件
boost-devel.x86_64
gmp-devel.x86_64
mpfr-devel.x86_64
CGAL-4.14
为了安装pgrouting3.0.2
需要安装boost1.53
以上,使用yum install boost boost-devel
只能安装版本1.53
, 我使用源码安装的是1.68
安装boost
wget https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.gz
tar -xzvf boost_1_68_0.tar.gz
cd boost_1_68_0
./bootstrap.sh
./b2 install --with=all
yum install gmp-devel.x86_64
yum install mpfr-devel.x86_64
wget https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.gz
tar -xzvf boost_1_68_0.tar.gz
cd boost_1_68_0
./bootstrap.sh
./b2 install --with=all
yum install gmp-devel.x86_64
yum install mpfr-devel.x86_64
安装CGAL
wget https://git
hub.com/CGAL/cgal/releases/download/releases%2FCGAL-4.14.3/CGAL-4.14.3.tar.xz
[root@beta plus]# cd CGAL-4.14.3/
[root@beta CGAL-4.14.3]#mkdir build && cd build
[root@beta build]#cmake -DCGAL_HEADER_ONLY=OFF -DCMAKE_BUILD_TYPE=Release ..
[root@beta build]#make && make install
wget https://git
hub.com/CGAL/cgal/releases/download/releases%2FCGAL-4.14.3/CGAL-4.14.3.tar.xz
[root@beta plus]# cd CGAL-4.14.3/
[root@beta CGAL-4.14.3]#mkdir build && cd build
[root@beta build]#cmake -DCGAL_HEADER_ONLY=OFF -DCMAKE_BUILD_TYPE=Release ..
[root@beta build]#make && make install
安装pcre
wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
tar -xzvf pcre-8.44.tar.gz
cd pcre-8.44
./configure --enable-utf8 --prefix=/data/apps/pgsql/12/plus/pcre-8.44
make && make intall
echo "/data/apps/pgsql/12/plus/pcre-8.44/lib" > /etc/ld.so.conf.d/pcre-8.44.conf
ldconfig
wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
tar -xzvf pcre-8.44.tar.gz
cd pcre-8.44
./configure --enable-utf8 --prefix=/data/apps/pgsql/12/plus/pcre-8.44
make && make intall
echo "/data/apps/pgsql/12/plus/pcre-8.44/lib" > /etc/ld.so.conf.d/pcre-8.44.conf
ldconfig
遇到以下这个问题:
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report
解决方式:
sudo dd if=/dev/zero of=/swapfile bs=64M count=16
#count的大小就是增加的swap空间的大小,64M是块大小,所以空间大小是bs*count=1024MB
sudo mkswap /swapfile
#把刚才空间格式化成swap格式
chmod 0600 /swapfile
#该目录权限,不改的话,在下一步启动时会报“swapon: /swapfile: insecure permissions 0644, 0600 suggested.”错误
sudo swapon /swapfile
#使用刚才创建的swap空间
sudo dd if=/dev/zero of=/swapfile bs=64M count=16
#count的大小就是增加的swap空间的大小,64M是块大小,所以空间大小是bs*count=1024MB
sudo mkswap /swapfile
#把刚才空间格式化成swap格式
chmod 0600 /swapfile
#该目录权限,不改的话,在下一步启动时会报“swapon: /swapfile: insecure permissions 0644, 0600 suggested.”错误
sudo swapon /swapfile
#使用刚才创建的swap空间
SFCGAL-1.3.7
wget https://github.com/Oslandia/SFCGAL/archive/v1.3.7.tar.gz
tar -zxvf SFCGAL-1.3.7.tar.gz
cd SFCGAL-1.3.7
mkdir build && cd build
/usr/local/cmake/bin/cmake -DCMAKE_INSTALL_PREFIX=/data/apps/pgsql/12/plus/sfcgal-1.3.7 ..
make && make install
swapoff -a
#详细的用法可以:swapoff --help
[root@beta json-c-json-c-0.13.1-20180305]# ./configure --prefix=/data/apps/pgsql/12/plus/json0.13.1
wget https://github.com/Oslandia/SFCGAL/archive/v1.3.7.tar.gz
tar -zxvf SFCGAL-1.3.7.tar.gz
cd SFCGAL-1.3.7
mkdir build && cd build
/usr/local/cmake/bin/cmake -DCMAKE_INSTALL_PREFIX=/data/apps/pgsql/12/plus/sfcgal-1.3.7 ..
make && make install
swapoff -a
#详细的用法可以:swapoff --help
[root@beta json-c-json-c-0.13.1-20180305]# ./configure --prefix=/data/apps/pgsql/12/plus/json0.13.1
8.安装PostGIS
./configure --prefix=/data/apps/pgsql/12/plus/postgis-3.1.1 --with-gdalconfig=/data/apps/pgsql/12/plus/gdal-3.0.4/bin/gdal-config --with-pgconfig=/data/apps/pgsql/12/bin/pg_config --with-geosconfig=/data/apps/pgsql/12/plus/geos-3.8.1/bin/geos-config --with-projdir=/data/apps/pgsql/12/plus/proj-6.3.2 --with-xml2config=/data/apps/pgsql/12/plus/libxml2/bin/xml2-config --with-jsondir=/data/apps/pgsql/12/plus/json0.13.1 --with-protobufdir=/data/apps/pgsql/12/plus/protobuf-3.15.2 --with-sfcgal=/data/apps/pgsql/12/plus/sfcgal-1.3.7/bin/sfcgal-config --with-pcredir=/data/apps/pgsql/12/plus/pcre-8.44
./configure --prefix=/data/apps/pgsql/12/plus/postgis-3.1.1 --with-gdalconfig=/data/apps/pgsql/12/plus/gdal-3.0.4/bin/gdal-config --with-pgconfig=/data/apps/pgsql/12/bin/pg_config --with-geosconfig=/data/apps/pgsql/12/plus/geos-3.8.1/bin/geos-config --with-projdir=/data/apps/pgsql/12/plus/proj-6.3.2 --with-xml2config=/data/apps/pgsql/12/plus/libxml2/bin/xml2-config --with-jsondir=/data/apps/pgsql/12/plus/json0.13.1 --with-protobufdir=/data/apps/pgsql/12/plus/protobuf-3.15.2 --with-sfcgal=/data/apps/pgsql/12/plus/sfcgal-1.3.7/bin/sfcgal-config --with-pcredir=/data/apps/pgsql/12/plus/pcre-8.44
9.安装PgRouting
wget https://github.com/pgRouting/pgrouting/releases/download/v3.0.2/pgrouting-3.0.2.tar.gz
tar -zxvf pgrouting-3.0.2.tar.gz
cd pgrouting-3.0.2
mkdir build && cd build
cmake ..
make
make install
wget https://github.com/pgRouting/pgrouting/releases/download/v3.0.2/pgrouting-3.0.2.tar.gz
tar -zxvf pgrouting-3.0.2.tar.gz
cd pgrouting-3.0.2
mkdir build && cd build
cmake ..
make
make install
[root@beta json-c-json-c-0.13.1-20180305]# cat /etc/ld.so.conf
#添加如下东西
/data/apps/pgsql/12/plus/geos-3.8.1/lib
/data/apps/pgsql/12/lib
/data/apps/pgsql/12/plus/proj-6.3.2/lib
/data/apps/pgsql/12/plus/json0.13.1/lib
/data/apps/pgsql/12/plus/protobuf-c-1.3.3/lib
/data/apps/pgsql/12/plus/sfcgal-1.3.7/lib
/data/apps/pgsql/12/plus/sfcgal-1.3.7/lib64
[root@beta json-c-json-c-0.13.1-20180305]#ldconfig
[root@beta json-c-json-c-0.13.1-20180305]# cat /etc/ld.so.conf
#添加如下东西
/data/apps/pgsql/12/plus/geos-3.8.1/lib
/data/apps/pgsql/12/lib
/data/apps/pgsql/12/plus/proj-6.3.2/lib
/data/apps/pgsql/12/plus/json0.13.1/lib
/data/apps/pgsql/12/plus/protobuf-c-1.3.3/lib
/data/apps/pgsql/12/plus/sfcgal-1.3.7/lib
/data/apps/pgsql/12/plus/sfcgal-1.3.7/lib64
[root@beta json-c-json-c-0.13.1-20180305]#ldconfig
10.创建postgis扩展
create database gistest;
\c gistest
create extension postgis;
#如果安装了sfcgal,创建扩展测试下
create extension postgis_sfcgal;
create extension pgrouting;
gistest=# select ST_distance(point(111.11,22.2)::geometry,point(111.11,22.4)::geometry);
st_distance
--------------------
0.1999999999999993
(1 row)
显示上面结果,插件安装成功
create database gistest;
\c gistest
create extension postgis;
#如果安装了sfcgal,创建扩展测试下
create extension postgis_sfcgal;
create extension pgrouting;
gistest=# select ST_distance(point(111.11,22.2)::geometry,point(111.11,22.4)::geometry);
st_distance
--------------------
0.1999999999999993
(1 row)
显示上面结果,插件安装成功