麒麟V10SP1部署postgresql+postgis+pgrouting
1、查看当前操作系统版本:
nkvers
############## Kylin Linux Version #################
Release:
Kylin Linux Advanced Server release V10 (Tercel)
Kernel:
4.19.90-17.5.ky10.aarch64
Build:
Kylin Linux Advanced Server
release V10 (SP1) /(Tercel)-aarch64-Build07/20200821
#################################################
2、安装依赖包
如果是无外网连接离线安装,先用:yum install –downloadonly [软件名称] –downloaddir=[指定rpm包存放路径] 下载好如下依赖包然后CP到服务器上运行RPM -IVH *.RPM,有外网连接直接运行如下命令:
yum install bzip*
yum install -y perl-ExtUtils-Embed
yum install -y flex
yum install -y bison
yum install -y readline-devel
yum install -y zlib-devel
yum install -y openssl-devel
yum install -y pam-devel
ryum install -y libxml2-devel
yum install -y libxslt-devel
yum install -y openldap-devel
yum install -y python-devel
yum install -y gcc-c++
yum install -y libssh2-devel
yum install cmake
yum install sqlite-devel
3、安装PostgreSQL
#下载源码包
wget http://ftp.postgresql.org/pub/source/v13.1/postgresql-13.1.tar.bz2
#解压源码包
tar xjvf postgresql-13.1.tar.bz2
#进入解压源码包目录
cd postgresql-13.1/
#配置编译
./configure –prefix=/opt/pgsql
#编译
gmake
#安装
gmake install
4、安装PostGIS依赖
因PostGIS依赖都无法通过YUM 源安装,因此只能通过源码安装:
4.1、#安装geos
wget http://download.osgeo.org/geos/geos-3.8.0.tar.bz2
tar -xjf geos-3.8.0.tar.bz2
cd geos-3.8.0
./configure –prefix=/opt/geos-3.8.0 –enable-python
make
sudo make install
4.2、#安装proj
wget https://download.osgeo.org/proj/proj-6.2.1.tar.gz
sudo apt-get install sqlite3
tar zxvf proj-6.2.1.tar.gz
cd proj-6.2.1
./configure –prefix=/opt/proj-6.2.1
make
sudo make install
4.3、#安装libxml2
wget ftp://xmlsoft.org/libxml2/libxml2-2.9.1.tar.gz
tar zxvf libxml2-2.9.1.tar.gz
cd libxml2-2.9.1
./configure –prefix=/opt/libxml2-2.9.1
make
sudo make install
4.4、#安装json-c
git clone https://github.com/json-c/json-c.git
mkdir json-c-build
cd json-c-build
cmake …/json-c -DCMAKE_INSTALL_PREFIX=/opt/json-c
make
sudo make install
4.5、#安装 gdal
wget https://download.osgeo.org/gdal/3.3.3/gdal-3.3.3.tar.gz
tar zxvf gdal-3.3.3.tar.gz
cd gdal-3.3.3
./configure –prefix=/opt/gdal-3.3.3 –with-proj=/opt/proj-6.2.1 –with-libjson-c=/opt/json-c
make clean;make
sudo make install
编译过程中如报PNG错误,需修改代码:vi /gdal-3.3.3/frmts/png/libpng/pngpriv.h
在#ifndef PNG_ARM_NEON_OPT行上增加#define PNG_ARM_NEON_OPT 0
4.6、安装protobuf
下载源码
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protobuf-all-3.6.1.tar.gz
tar zxvf protobuf-all-3.6.1.tar.gz
cd protobuf-3.6.1
./configure –prefix=/opt/protobuf-3.6.1
make
sudo make install
#配置环境变量,增加/usr/local/protobuf-3.6.1安装目录
vi /etc/profile
export CMAKE_HOME=/usr/bin/cmake
export PKG_CONFIG_PATH=/opt/protobuf-3.6.1/lib/pkgconfig
export PROTOBUF_HOME=/opt/protobuf-3.6.1
export PATH=$CMAKE_HOME/bin:$PROTOBUF_HOME/bin:$PATH
#wq保存退出
source /etc/profile
#验证protobuf执行程序
protoc –version
4.7、#安装protobuf-c
wget https://github.com/protobuf-c/protobuf-c/releases/download/v1.4.0/protobuf-c-1.4.0.tar.gz
tar -zxvf protobuf-c-1.4.0.tar.gz
cd protobuf-c-1.4.0
#导入protobuf的pkgconfig,否则”–No package ‘protobuf’ found”
export PKG_CONFIG_PATH=/opt/protobuf-3.6.1/lib/pkgconfig
./configure –prefix=/opt/protobuf-c-1.4.0
make
make install
#配置环境变量,增加protobuf-c-1.4.0/bin
vi /etc/profile
export PATH=$PATH:/opt/protobuf-c-1.4.0/bin
#保存退出
source /etc/profile
5、安装PostGIS
#下载PostGIS源码
wget http://download.osgeo.org/postgis/source/postgis-3.1.6.tar.gz
tar zxvf postgis-3.1.6.tar.gz
cd postgis-3.1.6
./configure –prefix=/opt/postgis –with-gdalconfig=/opt/gdal-3.3.3/bin/gdal-config –with-pgconfig=/opt/pgsql/bin/pg_config –with-geosconfig=/opt/geos-3.8.0/bin/geos-config –with-projdir=/opt/proj-6.2.1/ –with-xml2config=/opt/libxml2-2.9.1/bin/xml2-config –with-jsondir=/opt/json-c –with-protobufdir=/opt/protobuf-c-1.4.0
注意:with前是两个-
make
make install
configrue 若提示版protobuf-c版本不对,需要手动修改configure脚本,增加版本变量值到configure文件。
6、安装pgRouting依赖
6.1、#安装CGAL
wget https://github.com/CGAL/cgal/archive/refs/tags/v5.5.1.tar.gz
tar -zxvf v5.5.1.tar.gz
cd cgal-5.5.1/
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/opt/cgal-5.5.1 …
make
make install
6.2、#安装BOOST
wget https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz
./bootstrap.sh –prefix=/opt/boost_1_81_0
./b2
sudo ./b2 install
7、安装pgRouting
wget https://github.com/pgRouting/pgrouting/releases/download/v3.4.2/pgrouting-3.4.2.tar.gz
tar -zxvf pgrouting-3.4.2.tar.gz
cd pgrouting-3.4.2
mkdir build
编辑环境配置文件vim /etc/profile
增加:export PATH=/opt/pgsql/bin/:$PATH
source /etc/profile
cd build
cmake -DCMAKE_INSTALL_PREFIX=/opt/pgrouting-3.4.2 …
make
make install
8、测试PostGIS与pgRouting
#启动PostgreSQL
su postgres
pg_ctl -D /opt/pgsql/data start
#进入psql
/opt/pgsql/bin/psql
#创建PostgreSQL扩展
CREATE EXTENSION postgis;
CREATE EXTENSION pgrouting;
CREATE EXTENSION postgis_topology;
#列表列表插件
\dx
#检查插件版本
SELECT PostGIS_full_version();
select pgr_version();
#测试MVT
WITH mvtgeom AS
(
SELECT ST_TileEnvelope(12,513,412) AS geom
)
SELECT ST_AsMVT(mvtgeom.*)
FROM mvtgeom;