postgres14.5+postgis3.3.2+pgRouting3.4.2源码安装

一、背景

本次安装操作系统为银河麒麟 Kylin-Server-V10-SP3-General-Release-2212-X86_64。所有软件安装采用postgres安装,非必要不用root用户,并且系统挂载的盘/data目录下,空间较大,故安装路径都将安装到/data/pgsql目录下

版本描述

postgresql 14
- postgis 3.3.0 
- This release supports PostgreSQL 11-16beta1, GEOS 3.6 and higher, and proj 5.2 and higher.
 -- cmake   //安装geos-3.11.2需要,并且>3.13
 -- geos-3.9.1  //太高版本会报错
 -- sqlite3   //安装proj需要  sqlite3 >= 3.7)
 -- proj-6.1.0.tar.gz  >6.0   //gdal版本要求
 -- gdal-3.5.2
 -- json-c-0.13.1
 -- libxml2-2.9.12
 -- protobuf-all-3.15.8   protobuf-c安装需求 (protobuf >= 2.6.0)
 -- protobuf-c-1.4.1
 -- cgal-releases-CGAL-4.13
 -- SFCGAL-1.3.8
 -- pgrouting-3.4.2

包目录

[root@localhost postgres]# ll
total 234220
-rw-r--r--   1 postgres postgres 131376953 Jun  2 21:45 cgal-releases-CGAL-4.13.tar.gz
-rw-r--r--   1 postgres postgres  16794019 Jun  2 21:18 CMake-3.21.1.zip
-rw-r--r--   1 postgres postgres  14302988 Jun  3 00:12 gdal-3.5.2.tar.gz
-rw-r--r--   1 postgres postgres   4761372 Jun  3 13:28 geos-3.9.1.tar.bz2
-rw-r--r--   1 postgres postgres    625036 Jun  3 11:12 json-c-json-c-0.13.1-20180305.tar.gz
-rw-r--r--   1 postgres postgres   5233674 Jun  3 11:01 libxml2-v2.9.12.tar.gz
-rw-r--r--   1 postgres postgres   3741763 Jun  2 21:39 pgrouting-3.4.2.tar.gz
-rw-r--r--   1 postgres postgres  17793976 Jun  2 21:19 postgis-3.3.2.tar.gz
-rw-r--r--   1 postgres postgres  28988974 Jun  1 22:16 postgresql-14.5.tar.gz
-rw-r--r--   1 postgres postgres   2453402 Jun  2 21:18 proj-6.1.0.tar.gz
-rw-r--r--   1 postgres postgres   7535306 Jun  2 21:19 protobuf-all-3.15.8.tar.gz
-rw-r--r--   1 postgres postgres    513596 Jun  2 21:17 protobuf-c-1.4.1.tar.gz
-rw-r--r--   1 postgres postgres   2480730 Jun  2 21:42 SFCGAL-1.3.8.tar.gz
-rw-r--r--   1 postgres postgres   3148813 Jun  2 23:40 sqlite-autoconf-3420000.tar.gz

安装包传送门:https://download.csdn.net/download/wujianyouhun/87858530

二、准备 【root干活】

a. 安装postgres依赖

[root@localhost postgis] yum install -y openssl openssl-devel pam pam-devel libxml2 libxml2-devel libxslt libxslt-devel perl perl-devel python-devel perl-ExtUtils-Embed readline readline-devel  zlib zlib-devel gettext gettext-devel bison flex  gcc gcc-c++

b. 创建用户

useradd postgres//创建账户
passwd postgres//设置账户密码

c. 创建目录

mkdir /data/pgsql/pg14 
mkdir /data/pgsql/pg14/data 
chown -R postgres:postgres /data/pgsql

d. 授权安装文件

chown -R postgres:postgres /home/software/postgres

三、安装postgresql 14

[postgres@localhost postgres] tar -zxvf postgresql-14.5.tar.gz
[postgres@localhost postgres] cd postgresql-14.5/
[postgres@localhost postgresql-14.5] ./configure --prefix=/data/pgsql/pg14 --with-pgport=6543 --with-openssl --with-perl --with-blocksize=16
[postgres@localhost postgresql-14.5] make && make install

注意

--with-blocksize=16  #根据业务需求选择编译的内容
--with-system #可注册成系统服务。

环境变量设置

注意现在已经是postgres用户,环境变量使用/home/postgres/.bashrc文件

vi /home/postgres/.bashrc

export PGHOME=/data/pgsql/pg14
export PGDATA=/data/pgsql/pg14/data
export LD_LIBRARY_PATH=$PGHOME/lib:lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export DATE='date +"%Y%m%d%H%M"'
export PATH=$PGHOME/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH

source /home/postgres/.bashrc

检查

[postgres@localhost postgres]$ psql --version //打印版本

初始化数据库

[postgres@localhost postgres]$ initdb -D /data/pgsql/pg14/data -E UTF8 --locale=zh_CN.utf8

配置远程访问

[postgres@local  postgres]$ vi/data/pgsql/pg14/data/pg_hba.conf
···

host    all             all             0.0.0.0/0               trust
···

配置端口

vim /data/pgsql/pg14/data/postgresql.conf
listen_addresses = '0.0.0.0'
prot = 5432
max_connections = 10000

启动postgresql

[postgres@local  pg14]$ mkdir logs
[postgres@local  pg14]$  /data/pgsql/pg14/bin/pg_ctl -D /data/pgsql/pg14/data -l /data/pgsql/pg14/logs/pgsql.log start

停止命令

post就可以远程访问并登录了,接下来开始安装postgis插件

四、安装postgis

1、不同包内容介绍

1 postgis 支持必装的几个包 geos proj libxml protobuf protobuf-c postgis

2 要进行栅格处理需要再安装 gdal

3 要进行网络分析需要再pgRouting

4 postgis_sfcga使空间数据库支持2D和3D的数据操作,需要再安装SFGAL库

2、安装geos

2.1 cmake安装

下载路径:https://codeload.github.com/Kitware/CMake/zip/refs/tags/v3.21.1

[postgres@localhost postgres]$ unzip CMake-3.21.1.zip
[postgres@localhost postgres]$ cd CMake-3.21.1/
[postgres@localhost CMake-3.21.1]$ ./configure --prefix=/data/pgsql/postgis/CMake321
//make编译
[postgres@localhost CMake-3.21.1]# make && make install

配置环境变量

[postgres@localhost CMake-3.21.1]# vi /home/postgres/.bashrc


# Source default setting
[ -f /etc/bashrc ] && . /etc/bashrc

# User environment PATH
export PGHOME=/data/pgsql/pg14
export PGDATA=/data/pgsql/pg14/data
export LD_LIBRARY_PATH=$PGHOME/lib:lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export DATE='date +"%Y%m%d%H%M"'
export CMAKE_HOME=/data/pgsql/postgis/CMake321
export PROTOBUF_HOME=/data/pgsql/postgis/protobufal
export PROTOBUFC_HOME=/data/pgsql/postgis/protobufc
PATH="$PGHOME/bin:$HOME/.local/bin:$HOME/bin:$CMAKE_HOME/bin:$PROTOBUF_HOME/bin:$PROTOBUFC_HOME/bin:$PATH"
export PKG_CONFIG_PATH=/data/pgsql/postgis/protobufal/lib/pkgconfig:/data/pgsql/postgis/sqlite/lib/pkgconfig:$PKG_CONFIG_PATH
export PATH
export MANPATH=$PGHOME/share/man:$MANPATH

//保存退出,生效文件

[postgres@localhost CMake-3.21.1]# source /home/postgres/.bashrc

2.2 geos-3.11.2

下载路径:http://download.osgeo.org/geos/geos-3.9.1.tar.bz2

[postgres@localhost postgres]$ tar -jxvf geos-3.9.1.tar.bz2
[postgres@localhost postgres]$ cd geos-3.9.1
[postgres@localhost geos-3.9.1]$  ./configure --prefix=/data/pgsql/postgis/geos
[postgres@localhost geos-3.9.1]$ make && make install

可以将路径添加 为环境变脸检查 geos-config --version

3、安装sqlite

下载路径:https://www.sqlite.org/2021/sqlite-autoconf-3420000.tar.gz

[postgres@localhost postgres]$ tar -zxvf sqlite-autoconf-3420000.tar.gz
[postgres@localhost postgres]$ cd sqlite-autoconf-3420000
[postgres@localhost sqlite-autoconf-3342100]$ ./configure --prefix=/data/pgsql/postgis/sqlite
//make编译
[postgres@localhost sqlite-autoconf-3342100]$ make  && make install

设置变量

 export PKG_CONFIG_PATH=/usr/local/sqlite/lib/pkgconfig:$PKG_CONFIG_PATH

4、安装proj

下载路径:http://download.osgeo.org/proj/proj-6.3.2.tar.gz

[postgres@localhost postgres]$ tar -zxvf proj-6.3.2.tar.gz
[postgres@localhost postgres]$ cd proj-6.3.2
[postgres@localhost proj-6.3.2]$  ./configure --prefix=/data/pgsql/postgis/proj6  
//make编译
[postgres@localhost proj-6.3.2]$# make  && make install

5、安装gdal

下载路径:https://download.osgeo.org/gdal/3.5.2/gdal-3.5.2.tar.gz

[postgres@localhost postgres]$ tar -zxvf gdal-3.5.2.tar.gz
[postgres@localhost postgres]$ gdal-3.5.2/

//编译指定安装路径且绑定proj
[postgres@localhost gdal-3.5.2]$ ./configure --prefix=/data/pgsql/postgis/gdal --with-proj=/data/pgsql/postgis/proj
//make编译
[postgres@localhost gdal-3.5.2]$ make && make install

6、安装json

下载路径:https://github.com/json-c/json-c/archive/json-c-0.13.1-20180305.tar.gz

[postgres@localhost postgres]$ tar -zxvf json-c-0.13.1.tar.gz
[postgres@localhost postgres]$ cd json-c-0.13.1
[postgres@localhost json-c-0.13.1]$ ./configure --prefix=/data/pgsql/postgis/jsonc
//make编译
[postgres@localhost json-c-0.13.1]$ make && make install

7、安装libxml

下载路径:https://gitlab.gnome.org/GNOME/libxml2/-/archive/v2.9.12/libxml2-v2.9.12.tar.gz

//我这里用的是2.9.9版本
[postgres@localhost postgres]$ tar -zxvf libxml2-2.9.12.tar.gz
[postgres@localhost postgres]$ cd libxml2-v2.9.12/
[postgres@localhost libxml2-2.9.12]$ ./configure --prefix=/data/pgsql/postgis/libxml 
//如果文件不存在,就使用./autogen.sh编译
[postgres@localhost libxml2-2.9.12]$ ./autogen.sh --prefix=/data/pgsql/postgis/libxml
//make编译
[postgres@localhost libxml2-2.9.12]$  make && make install

8、安装protobuf-c

8.1 安装protobuf

下载路径:https://github.com/protocolbuffers/protobuf/releases/download/v3.15.8/protobuf-all-3.15.8.tar.gz

[postgres@localhost postgres]$ tar -zxvf protobuf-all-3.15.8.tar.gz
[postgres@localhost postgres]$ cd protobuf-3.15.8/
//下面两个方式人选一种
[postgres@localhost protobuf-3.15.8]$ ./autogen.sh --prefix=/data/pgsql/postgis/protobuf
[postgres@localhost protobuf-3.15.8]$ ./configure --prefix=/data/pgsql/postgis/protobuf
//make编译
[postgres@localhost protobuf-3.15.8]$  make && make install

//配置环境变量

[postgres@localhost protobuf-3.15.8]$ vim /home/postres/.bashrc
···
export PROTOBUF_HOME=/data/pgsql/postgis/protobuf
export PATH=$GCC_HOME/bin:$PROTOBUF_HOME/bin:$PATH
export PKG_CONFIG_PATH=/data/pgsql/postgis/protobuf/lib/pkgconfig:$PKG_CONFIG_PATH
···
//保存退出,生效文件
[postgres@localhost protobuf-3.15.8]$ source /home/postres/.bashrc
//验证protobuf是否安装成功
[postgres@localhost protobuf-3.15.8]$ protoc --version
libprotoc 3.10.1

8.2、安装protobuf-c

下载路径:https://github.com/protobuf-c/protobuf-c/releases/download/v1.4.1/protobuf-c-1.4.1.tar.gz

[postgres@localhost postgres]$ tar -zxvf protobuf-c-1.4.1.tar.gz
[postgres@localhost postgres]$ cd protobuf-c-1.4.1
//导入protobuf的pkgconfig
[postgres@localhost protobuf-c-1.4.1]$ ./configure --prefix=/data/pgsql/postgis/protobufc
//make编译
[postgres@localhost protobuf-c-1.4.1]$ make && make install

//配置环境变量

[postgres@localhost protobuf-c-1.3.2]# vim /home/postres/.bashrc
···
export PROTOBUFC_HOME=/data/pgsql/postgis/protobufc
export PATH=$GCC_HOME/bin:$PROTOBUF_HOME/bin:$PROTOBUFC_HOME/bin:$PATH
export PKG_CONFIG_PATH=/data/pgsql/postgis/protobufc/lib/pkgconfig:$PKG_CONFIG_PATH
···
//保存退出,生效文件
[postgres@localhost protobuf-c-1.3.2]# source /home/postres/.bashrc

9、安装sfcgal

9.1、cgal

sfcgal依赖boost,cgal,避免编译sfcgal时各种找不到库的问题。

yum -y install boost-devel gmp* mpfr*

下载路径:https://github.com/CGAL/cgal/archive/releases/CGAL-4.13.tar.gz

[root@localhost postgres]$  tar -zxvf cgal-releases-CGAL-4.13.tar.gz
[root@localhost postgres]$ # cd cgal-releases-CGAL-4.13
[root@localhost cgal-releases-CGAL-4.13]# mkdir build && cd build
//cmake不指定安装目录
[root@localhost build]# cmake ..
//make编译
[root@localhost build]# make && make install

9.2、sfcgal

下载路径:https://github.com/Oslandia/SFCGAL/archive/v1.3.8.tar.gz

[postgres@localhost postgres]$ tar -zxvf SFCGAL-1.3.8.tar.gz
[postgres@localhost postgres]$ cd SFCGAL-1.3.8/
[postgres@localhostt SFCGAL-1.3.8]$ mkdir build && cd build
[postgres@localhostt build]$ cmake -DCMAKE_INSTALL_PREFIX=/data/pgsql/postgis/sfcgal ..
[postgres@localhostt build]$ make  && make install

10、安装PgRouting

pgrouting依赖boost,cgal,如果没有安装,需要安装下
下载路径:https://codeload.github.com/pgRouting/pgrouting/zip/refs/tags/v3.4.2

[postgres@localhost postgres]$  unizip  pgrouting-3.4.2.zip
[postgres@localhost src]$ cd pgrouting-2.6.3/
[postgres@localhost pgrouting-2.6.3]$ mkdir build && cd build
//cmake不指定安装路径,此处读取环境变量pg的路径pgsql/share/extension/
[postgres@localhost build]$ cmake ..
//make编译
[postgres@localhost build]$ make && make install

11、安装postgis

使用root 配置软连接过程 ld.so.conf

[root@localhost src]# vim /etc/ld.so.conf
include ld.so.conf.d/*.conf
/data/postgres/pgsql/pg14/lib
/data/postgres/pgsql/postgis/proj/lib
/data/postgres/pgsql/postgis/gdal/lib
/data/postgres/pgsql/postgis/geos/lib
/data/postgres/pgsql/postgis/jsonc/lib
/data/postgres/pgsql/postgis/sfcgal/lib64
/data/postgres/pgsql/postgis/libxml/lib
/data/postgres/pgsql/postgis/protobuf/lib
/data/postgres/pgsql/postgis/protobufc/lib
//保存退出,生效文件
[root@localhost src]# ldconfig -v

下载路径:https://download.osgeo.org/postgis/source/postgis-3.3.2.tar.gz

[postgres@localhost postgres]$ tar -zxvf postgis-3.3.2.tar.gz
[postgres@localhost postgres]$ cd postgis-3.3.2

//带protobuf,sfcgal安装
[postgres@localhost postgis-3.3.2]$ ./configure --prefix=/data/postgres/pgsql/postgis/postgis --with-gdalconfig=/data/postgres/pgsql/postgis/gdal/bin/gdal-config --with-pgconfig=/home/postgres/pgsql/bin/pg_config --with-geosconfig=/data/postgres/pgsql/postgis/geos/bin/geos-config --with-projdir=/data/postgres/pgsql/postgis/proj --with-xml2config=/data/postgres/pgsql/postgis/libxml/bin/xml2-config --with-jsondir=/data/postgres/pgsql/postgis/jsonc --with-protobufdir=/data/postgres/pgsql/postgis/protobufc --with-sfcgal=/data/postgres/pgsql/postgis/sfcgal/bin/sfcgal-config
//make编译
[postgres@localhost postgis-3.3.2]$ make  && make install

提示

可以不使用全量安装,按照需要的插件进行,比如不安装gdal,不安装protobuf,不安装 sfcgal 等

13、验证安装

[postgres@VM-16-11-opencloudos pgsql]$  psql
psql (14.5)
Type "help" for help.
postgres=# create datebase mytest;
postgres=# select name from pg_available_extensions;
             name
------------------------------
 plperl
 postgis_sfcgal
 address_standardizer_data_us
 plpgsql
 pgrouting
 postgis_topology
 plperlu
 postgis_raster
 postgis_tiger_geocoder
 postgis
 address_standardizer
(11 rows)

14、环境变量参考


# Source default setting
[ -f /etc/bashrc ] && . /etc/bashrc

# User environment PATH
export PGHOME=/data/pgsql/pg14
export PGDATA=/data/pgsql/pg14/data
export PROJ=/data/pgsql/postgis/proj6
export LD_LIBRARY_PATH=$PGHOME/lib:lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH:$PROJ/lib
export DATE='date +"%Y%m%d%H%M"'
export CMAKE_HOME=/data/pgsql/postgis/CMake321
export PROTOBUF_HOME=/data/pgsql/postgis/protobufal
export PROTOBUFC_HOME=/data/pgsql/postgis/protobufc
export GEOCONFIG_HOME=/data/pgsql/postgis/geos39
PATH="$PGHOME/bin:$HOME/.local/bin:$HOME/bin:$CMAKE_HOME/bin:$GEOCONFIG_HOME/bin:$PROTOBUF_HOME/bin:$PROTOBUFC_HOME/bin:$PROJ/bin:$PATH"
export PKG_CONFIG_PATH=/data/pgsql/postgis/protobufal/lib/pkgconfig:/data/pgsql/postgis/sqlite/lib/pkgconfig:$PKG_CONFIG_PATH
export PATH
export MANPATH=$PGHOME/share/man:$MANPATH

15、文中报错

15.1安装libxml

libxml.c:15:20: fatal error: Python.h: No such file or directory
 #include <Python.h>
           	^  
compilation terminated。
libxml2-py.c:4:20: fatal error: Python.h: No such file or directory
 #include <Python.h>
            ^
compilation terminated.
In file included from types.c:9:0:
libxml_wrap.h:1:20: fatal error: Python.h: No such file or directory
 #include <Python.h>
            ^
compilation terminated.
make[4]: *** [libxml.lo] Error 1
make[4]: *** Waiting for unfinished jobs....
make[4]: *** [types.lo] Error 1
make[4]: *** [libxml2-py.lo] Error 1
make[4]: Leaving directory `/root/libxml2-v2.9.12/python'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/root/libxml2-v2.9.12/python'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/root/libxml2-v2.9.12/python'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/libxml2-v2.9.12'
make: *** [all] Error 2

解决方式

yum install python-dev*

15.2 安装cgal

问题1

-- Could NOT find GMP (missing: GMP_LIBRARIES GMP_INCLUDE_DIR)
CMake Error at Installation/cmake/modules/CGAL_SetupDependencies.cmake:66 (message):
CGAL requires GMP to be found
Call Stack (most recent call first):
 Installation/CMakeLists.txt:673 (include)
-- Configuring incomplete, errors occurred!
See also "/root/cgal-releases-CGAL-4.13/build/CMakeFiles/CMakeOutput.log". E_DIR)

解决方式

yum -y install gmp* mpfr*

问题2

CMake Error at Installation/cmake_install.cmake:46 (file):
  file cannot create directory: /usr/local/share/doc/CGAL-4.13-I-900.  Maybe
  need administrative privileges.
Call Stack (most recent call first):
  cmake_install.cmake:47 (include)

解决方式

使用root安装

15.3开启扩展失败问题

** 报错信息*

could not load library "/data/pgsql/pg14/lib/postgis-3.so": libgeos_c.so.1: 无法打开共享对象文件: 没有那个文件或目录

**问题查找 **

postgres 安装目录lib下查看 动态链接 ldd postgis-3.so


[postgres@localhost lib]$ ldd postgis-3.so
   linux-vdso.so.1 (0x00007fff611af000)
   libm.so.6 => /usr/lib64/libm.so.6 (0x00007ff32663a000)   
   libgeos_c.so.1 => /data/pgsql/pg14/lib/libgeos_c.so.1 (0x00007ff326604000)
   -------------------------------------------------------//这个库有问题
   libproj.so.15 => not found
   ------------------------------------------------------
   libxml2.so.2 => /usr/lib64/libxml2.so.2 (0x00007ff326493000)
   libz.so.1 => /usr/lib64/libz.so.1 (0x00007ff326479000)
   liblzma.so.5 => /usr/lib64/liblzma.so.5 (0x00007ff32644e000)
   libdl.so.2 => /usr/lib64/libdl.so.2 (0x00007ff326449000)
   libc.so.6 => /usr/lib64/libc.so.6 (0x00007ff326291000)
   /lib64/ld-linux-x86-64.so.2 (0x00007ff3268d3000)
   libgeos-3.9.1.so => /data/pgsql/postgis/geos39/lib/libgeos-3.9.1.so (0x00007ff32608e000)
   libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007ff325f05000)
   libgcc_s.so.1 => /usr/lib64/libgcc_s.so.1 (0x00007ff325eec000)
   libpthread.so.0 => /usr/lib64/libpthread.so.0 (0x00007ff325ec9000)

发现 libproj.so.15没有找到,再相应插件目录将文件拷贝过去,适当的增加环境变量

解决办法

1拷贝文件过去

[postgres@localhost lib]$ cp /data/pgsql/postgis/proj6/lib/libproj.so.15 /data/pgsql/pg14/lib/libproj.so.15

2 增加环境变量

LD_LIBRARY_PATH=$PGHOME/lib:lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH:$PROJ/lib

15.4 postgis安装


checking GEOS version... 3.11.1
checking geos_c.h usability... yes
checking geos_c.h presence... yes
checking for geos_c.h... yes
checking for initGEOS in -lgeos_c... no
configure: error: could not find libgeos_c - you may need to specify the directory of a geos-config file using --with-geosconfig

16、参考博客

https://blog.csdn.net/qq_22406173/article/details/126121790
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值