赞
踩
有需要GDAL开发的同学,在linux服务器上,最好还是自己编译环境,初次编译是很痛苦,但是在此过程中,对插件之间的版本依赖关系,插件编译配置、问题定位,解决问题,shell脚本都能够全面的提升。最后还能得到一个最新版的环境,何乐而不为了!!!
Centos系统可以访问外网。
Centos系统版本:CentOS Linux release 7.3.1611 (Core)
需要安装的软件如下:
apache-ant-1.10.12-bin.tar.gz
cgal-4.14.tar.xz
cmake-3.20.6.tar.gz
gdal-3.0.4.tar.gz
geos-3.8.0.tar.bz2
gmp-6.1.2.tar.bz2
json-c-json-c-0.13.1-20180305.tar.gz
libxml2-2.9.10.tar.gz
mpfr-4.0.2.tar.gz
pcre-8.44.tar.gz
postgis-3.0.1.tar.gz
postgresql-12.2.tar.gz
proj-6.3.1.tar.gz
protobuf-c-1.3.3.tar.gz
protobuf-cpp-3.11.4.tar.gz
SFCGAL-1.3.7.tar.gz
sqlite-autoconf-3360000.tar.gz
swig-4.0.1.tar.gz
先通过yum基础插件
yum -y install gcc gcc-c++ gcc-g77 make libtool flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel gettext-devel pcre-devel
以下所有安装源文件放置均放在/usr/local/src/下
- #用户组
- groupadd postgres
- #用户组添加用户
- useradd -g postgres postgres
-
-
- mkdir -p /usr/local/pgsql
- mkdir /usr/local/pgsql/data
- chown -R postgres:postgres /usr/local/pgsql
-
- cd /usr/local/src/
- wget https://ftp.postgresql.org/pub/source/v12.2/postgresql-12.2.tar.gz
- tar -xzvf postgresql-12.2.tar.gz
- cd postgresql-12.2
- ./configure --prefix=/usr/local/pgsql --without-readline
- make && make install
./configure --prefix=/usr/local/pgsql --without-readline,效果:
make 效果:
make install 效果:
vi打开配置文件后,按i插入,ESC退出编译,:wq保存,:q!不保存,以后每次保存后要刷新环境变量:source /etc/profile
- vi /etc/profile
- PG_HOME=/usr/local/pgsql
-
- LD_LIBRARY_PATH=$PG_HOME/lib:$LD_LIBRARY_PATH
- PATH=$PG_HOME/bin:$PATH
-
- PKG_CONFIG_PATH=$PG_HOME/lib/pkgconfig:$PKG_CONFIG_PATH
- export PKG_CONFIG_PATH LD_LIBRARY_PATH
-
- source /etc/profile
- 查看Postgresql版本命令
-
-
-
-
-
- pg_config --version
-
-
-
-
-
-
-
- #切换用户
- su postgres
-
- #初始化数据库
- /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
- #切换root
- exit
-
- vi /usr/local/pgsql/data/postgresql.conf
- listen_address = '*'
- port = 5432
- vi /usr/local/pgsql/data/pg_hba.conf
- host all all 0.0.0.0/0 md5
- host all all 192.168.1.0/24 md5
- host all all ::1/128 ident
- #切换用户
- su postgres
-
- #启动数据库服务器
- /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
- #创建数据库
- /usr/local/pgsql/bin/createdb gisdb
-
- #停止数据库服务
- /usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data
- #重新启动数据库
- /usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data
到这里,数据库已经安装成功了,使用navicat或dbeaver连接试试吧!
- pg_ctl stop -D /usr/local/pgsql/data/
- pg_ctl start -D /usr/local/pgsql/data/
- pg_ctl restart -D /usr/local/pgsql/data/
/usr/lib/systemd/system 新建postgresql.service文件,复制以下内容到postgresql.service
- [Unit]
- Description=PostgreSQL database server
- After=network.target
-
- [Service]
- Type=forking
-
- User=postgres
- Group=postgres
-
- # Port number for server to listen on
- Environment=PGPORT=5432
-
- # Location of database directory
- Environment=PGDATA=/usr/local/pgsql/data
-
- # Where to send early-startup messages from the server (before the logging
- # options of postgresql.conf take effect)
- # This is normally controlled by the global default set by systemd
- # StandardOutput=syslog
-
- # Disable OOM kill on the postmaster
- OOMScoreAdjust=-1000
-
- #ExecStartPre=/usr/local/pgsql/bin/postgresql-check-db-dir ${PGDATA}
- ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300
- ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA} -s -m fast
- ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D ${PGDATA} -s
-
- # Give a reasonable amount of time for the server to start up/shut down
- TimeoutSec=300
-
- [Install]
- WantedBy=multi-user.target
- su root
- cd /usr/lib/systemd/system
- chmod 754 postgresql.service
- systemctl enable postgresql.service
启动,停止,重启
- systemctl start postgresql.service
- systemctl stop postgresql.service
- systemctl restart postgresql.service
修改数据库密码
- su - postgres
- psql -U postgres
- ALTER USER postgres WITH PASSWORD '123456'
- \q
yum install -y unzip zip
wget https://www.sqlite.org/2020/sqlite-autoconf-3360000.tar.gz tar –zxvf sqlite-autoconf-3360000.tar.gz cd sqlite-autoconf-3360000 bash ./configure --prefix=/usr/local/pgsql/plugin/sqlite3 make && make install
#软连接到/usr/bin目录
ln -s /usr/local/pgsql/plugin/sqlite3/bin/sqlite3 /usr/bin/sqlite3 echo "/usr/local/pgsql/plugin/sqlite3/lib" > /etc/ld.so.conf.d/sqlite3.conf ldconfig
#查看版本号
sqlite3 -version
bash ./configure --prefix=/usr/local/pgsql/plugin/sqlite3 命令结果:
make 命令结果:
make install 命令结果:
- wget https://github.com/json-c/json-c/archive/json-c-0.13.1-20180305.tar.gz
- tar -xzvf json-c-0.13.1-20180305.tar.gz
- cd json-c-json-c-0.13.1-20180305
- bash ./configure --prefix=/usr/local/pgsql/plugin/json-c
- make && make install
- echo "/usr/local/pgsql/plugin/json-c/lib" > /etc/ld.so.conf.d/json-c-0.13.1.conf
- ldconfig
bash ./configure --prefix=/usr/local/pgsql/plugin/json-c,命令效果:
make 命令效果:
make install 命令效果:
- wget https://github.com/protocolbuffers/protobuf/releases/download/v3.11.4/protobuf-cpp-3.11.4.tar.gz
- tar -xzvf protobuf-cpp-3.11.4.tar.gz
- cd protobuf-3.11.4
- bash ./configure
- make && make install
- bash ./configure 命令效果:
-
-
-
-
-
-
- bash ./configure 命令效果:
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
- bash ./configure
- make && make install
bash ./configure 报错:
vi /etc/profile 添加配置
- PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
- export PKG_CONFIG_PATH
source /etc/profile 配置生效。
.configure 命令正常效果:
make 命令效果:
make install 命令效果:
- wget https://download.osgeo.org/proj/proj-6.3.1.tar.gz
- tar -xf proj-6.3.1.tar.gz
- cd proj-6.3.1
- ./configure --prefix=/usr/local/pgsql/plugin/proj
- make && make install
- echo "/usr/local/pgsql/plugin/proj/lib" > /etc/ld.so.conf.d/proj-6.3.1.conf
- ldconfig
./configure --prefix=/usr/local/pgsql/plugin/proj 命令报错,提示sqlite3版本太低,必须大于等于3.11,当前版本为3.7.17
解决方法:升级sqlite版本。如果再出现以下提示,应该是在安装sqlite3时指定了安装目录,个别命令没有安装全面。
重新安装sqlite3
- wget https://www.sqlite.org/2020/sqlite-autoconf-3360000.tar.gz
- tar –zxvf sqlite-autoconf-3360000.tar.gz
- cd sqlite-autoconf-3360000
- ./configure --prefix=/usr/local/pgsql/plugin/sqlite3
- make && make install
-
- #查看版本号
- sqlite3 -version
进入 /usr/local/src/proj-6.3.1目录, ./configure --prefix=/usr/local/pgsql/plugin/proj 命令正常效果:
make 命令效果:
make install 命令效果:
- wget http://download.osgeo.org/geos/geos-3.8.0.tar.bz2
- tar -jxf geos-3.8.0.tar.bz2
- cd geos-3.8.0
- ./configure --prefix=/usr/local/pgsql/plugin/geos
- make && make install
- echo "/usr/local/pgsql/plugin/geos/lib" > /etc/ld.so.conf.d/geos-3.8.0.conf
- ldconfig
在解压 *.tar.bz2文件时报错如下,解决方法:yum -y install bzip2
./configure --prefix=/usr/local/pgsql/plugin/geos 命令效果:
make 命令效果:
make install 命令效果:
由于SFCGAL需要依赖Boost、CGAL、GMP、MPFR这四个软件,所以具体总共需要安装以下四个软件:
boost-devel.x86_64
gmp-devel.x86_64
mpfr-devel.x86_64
CGAL-4.14
yum install boost boost-devel
- wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.bz2
- tar -jxvf gmp-6.1.2.tar.bz2
- cd gmp-6.1.2
- bash ./configure --enable-cxx
- make && make install
./configure --enable-cxx 命令效果:
make 命令效果:
make install 命令效果:
- wget https://www.mpfr.org/mpfr-current/mpfr-4.0.2.tar.gz
- tar -xzvf mpfr-4.0.2.tar.gz
- cd mpfr-4.0.2
- ./configure
- make && make install
make install 命令效果:
- wget http://distfiles.macports.org/cgal/cgal-4.14.tar.xz
- xz -d cgal-4.14.tar.xz
- tar xvf cgal-4.14.tar
- cd CGAL-4.14
- mkdir build && cd build
- cmake ..
- make && make install
cmake .. 命令提示未找到,具体安装步骤参考:记一次 Centos7 cmake 版本升级(由 v2.8.12.2 升级至 v3.14.5)_cmake version 2.8.12.2-CSDN博客
如果使用yum安装cmake,默认版本是:cmake version 2.8.12.2,在执行cmake ..命令时报以下错误
- wget https://cmake.org/files/v3.17/cmake-3.17.4.tar.gz
- tar -zxvf cmake-3.17.4.tar.gz
- cd cmake-3.17.4
- ./configure --prefix=/usr/local/cmake
- make
- make install
- #创建链接
- ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
- vim /etc/profile
-
- export CMAKE_HOME=/usr/local/cmake
- export PATH=$PATH:$CMAKE_HOME/bin
-
- #使配置生效
- source /etc/profile
- #查看版本
- cmake –version
接下来继续安装cgal-4.14,进入/usr/local/src/CGAL-4.14/build,执行cmake .. 命令正常效果:
make 命令效果:
make install 命令效果:
安装过程中可能会出现以下错误
解决方法: 修改/usr/include/boost/ cstdint.hpp 44行代码为:
- #if defined(BOOST_HAS_STDINT_H) \
- && (!defined(__GLIBC__) \
- || defined(__GLIBC_HAVE_LONG_LONG) \
- || (defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 17)))))
- 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
- cmake -DCMAKE_INSTALL_PREFIX=/usr/local/sfcgal ..
- make && make install
- echo "/usr/local/sfcgal/lib64" > /etc/ld.so.conf.d/sfcgal-1.3.7.conf
- ldconfig
make 命令效果:
make install 命令效果:
- 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=/usr/local/pcre
- make && make intall
- echo "/usr/local/pcre/lib" > /etc/ld.so.conf.d/pcre-8.44.conf
- ldconfig
./configure --enable-utf8 --prefix=/usr/local/pcre 命令效果:
make 命令效果:
make install 命令效果:
- wget http://xmlsoft.org/sources/libxml2-2.9.10.tar.gz
- tar -xzvf libxml2-2.9.10.tar.gz
- cd libxml2-2.9.10
- ./configure --prefix=/usr/local/libxml2
- make && make intall
- echo "/usr/local/libxml2/lib" > /etc/ld.so.conf.d/libxml2-2.9.10.conf
- ldconfig
make命令,遇到错误提示“libxml.c:14:20: fatal error: Python.h: No such file or directory”
解决方法如下:
- # 可以先查看一下含python-devel的包
- yum search python | grep python-devel
-
- # 64位安装python-devel.x86_64,32位安装python-devel.i686,我这里安装:
- sudo yum install python-devel.x86_64
-
- # 进入/usr/include/python2.7看一下现在有没有Python.h,版本不同目录名不同,我这里是2.7版本。
- # 其实也可以看到很多.h文件,python需要库或头文件都在这个地方。
make 命令正常效果:
make install 命令效果:
- wget https://mirrors.tuna.tsinghua.edu.cn/apache//ant/binaries/apache-ant-1.10.12-bin.tar.gz
- tar -zxvf apache-ant-1.10.12-bin.tar.gz
- mv apache-ant-1.10.12 /usr/local/ant
- wget http://prdownloads.sourceforge.net/swig/swig-4.0.1.tar.gz
- tar -zxvf swig-4.0.1.tar.gz
- cd swig-4.0.1
- bash ./configure --prefix=/usr/local/swig --without-pcre
- make && make install
./configure --prefix=/usr/local/swig --without-pcre 命令效果:
make 命令效果:
make install 命令效果:
vim /etc/profile
- ANT_HOME=/usr/local/ant
- SWIG_HOME=/usr/local/swig
-
- PATH=$ANT_HOME/bin:$SWIG_HOME/bin:$PATH
-
- export ANT_HOME SWIG_HOME
source /etc/profile
查看版本
ant –version
- wget http://download.osgeo.org/gdal/3.0.4/gdal-3.0.4.tar.gz
- tar -xf gdal-3.0.4.tar.gz
- cd gdal-3.0.4
- bash ./configure --prefix=/usr/local/pgsql/plugin/gdal --with-proj=/usr/local/pgsql/plugin/proj --with-geos=/usr/local/pgsql/plugin/geos/bin/geos-config --with-libjson-c=/usr/local/pgsql/plugin/json-c
- make && make install
- echo "/usr/local/pgsql/plugin/gdal/lib" > /etc/ld.so.conf.d/gdal-3.0.4.conf
- ldconfig
make 命令效果:
make install 命令效果:
通过vi /etc/profile去配置gdal/lib、gdal/bin、gdal/data吧,也可以把profile下载到本地改完再上传
- GDAL_HOME=/usr/local/pgsql/plugin/gdal
- GDAL_DATA=$GDAL_HOME/share/gdal
-
- LD_LIBRARY_PATH=$GDAL_HOME/lib:/usr/local/lib64:$JRE_HOME/lib:$LD_LIBRARY_PATH
-
- PATH=$GDAL_HOME/bin:$PATH
-
- export PATH LD_LIBRARY_PATH GDAL_DATA
gdalinfo –version
- wget https://download.osgeo.org/postgis/source/postgis-3.0.1.tar.gz
- tar -xvzf postgis-3.0.1.tar.gz
- cd postgis-3.0.1
- ./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-geosconfig=/usr/local/pgsql/plugin/geos/bin/geos-config --with-projdir=/usr/local/pgsql/plugin/proj --with-gdalconfig=/usr/local/pgsql/plugin/gdal/bin/gdal-config --with-jsondir=/usr/local/pgsql/plugin/json-c --with-pcredir=/usr/local/pcre
- make && make install
./configure 命令效果:
make 命令效果:
make install 命令效果:
undefined reference to `sqlite3_column_origin_name',解决链接参考:https://www.cnblogs.com/xuanmanstein/p/13227545.html
具体做法是在源码文件夹下
- cd /usr/local/src/sqlite-autoconf-3360000
- vi ./sqlite3.c
添加
- #define SQLITE_CORE 1
- #define SQLITE_AMALGAMATION 1
- #ifndef SQLITE_PRIVATE
- # define SQLITE_PRIVATE static
- #endif
然后 再
- ./configure
- make
- make install
- cd /usr/local/src/postgresql-12.2/contrib/fuzzystrmatch
- make && make install
make 命令效果:
make install 命令效果:
- systemctl stop postgresql.service
-
- systemctl start postgresql.service
- #切换postgres用户
- su postgres
- #登录PG数据库
- psql
- # 创建数据库
- create database postgis;
- #切换到postgis库中
- \c postgis
- #显示一下扩展模块
- \dx
- create extension postgis;
- create extension postgis_topology;
- create extension fuzzystrmatch;
- create extension postgis_tiger_geocoder;
create extension postgis; 报错如下:
could not load library "/usr/local/pgsql/lib/postgis-3.so": libprotobuf-c.so.1
- vi /etc/ld.so.conf
- #依赖库比较多时,就直接把依赖库lib加入系统共享库,如
-
- /usr/local/lib
-
- ldconfig
重新启动postgresql数据库。
- 修改文件:/usr/local/src/gdal-3.0.4/swig/java/java.opt,修改JAVA_HOME的值为java的根目录
- JAVA_HOME = /usr/local/jdk1.8.0_281
- cd /usr/local/src/gdal-3.0.4/swig/java
- make && make install
- mkdir -p /usr/local/pgsql/plugin/gdal/java
- cp /usr/local/src/gdal-3.0.4/swig/java/gdal.jar /usr/local/pgsql/plugin/gdal/java
- cp /usr/local/src/gdal-3.0.4/swig/java/.libs/*.so /usr/local/pgsql/plugin/gdal/java
cp /usr/local/src/gdal-3.0.4/swig/java/.libs/*.so /usr/local/jdk1.8.0_281/lib/amd64
- cp /usr/local/src/gdal-3.0.4/swig/java/gdal.jar /usr/local/jdk1.8.0_281/jre/lib/ext
-
- vi /etc/profile
- CLASS_PATH=$JAVA_HOME/jre/lib/ext/gdal.jar:$CLASS_PATH
- source /etc/profile
http://192.168.1.82:8080/gdal/api/gdal/load
http://192.168.1.82:8080/gdal/api/gdal/register
http://192.168.1.82:8080/gdal/api/gdal/test/shp
http://192.168.1.82:8080/gdal/api/gdal/selectAltitude?lon=101.971729&lat=38.246638
错误1: java.lang.UnsatisfiedLinkError: Native Library /usr/java/packages/lib/amd64/libgdalalljni.so already loaded in another classloader
jvm启动时已经加载过libgdalalljni.so,不能能再次加载了,在linux系统上无需代码加载libgdalalljni.so
- echo '/usr/local/pgsql/lib' >> /etc/ld.so.conf
- ldconfig
- gdal.jar未放置到/usr/local/jdk1.8.0_281/jre/lib/ext
-
- vi /etc/profile
- CLASS_PATH=$JAVA_HOME/jre/lib/ext/gdal.jar:$CLASS_PATH
- source /etc/profile
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。