招聘类网站建设,北京哪家公司做网站,网站 建设平台分析,网站后台帐号密码破解1.前言
基于基础镜像构建gdal环境一般特别大#xff0c;一般少则1.6G#xff0c;多则2G甚至更大#xff0c;这对于镜像的迁移造成了极大的不便。究其原因在于容器中有大量的源码文件以及编译中间过程文件#xff0c;还要大量编译需要的yum库。本文主要通过在centos系统上先…1.前言
基于基础镜像构建gdal环境一般特别大一般少则1.6G多则2G甚至更大这对于镜像的迁移造成了极大的不便。究其原因在于容器中有大量的源码文件以及编译中间过程文件还要大量编译需要的yum库。本文主要通过在centos系统上先构建基础gdal环境然后将编译好的二进制文件以及动态库拷贝出来。通过DockerFile或者操作容器的方式构建进行。通过这样的方式镜像700M左右(基础镜像200Mgdal500M)。当然文章末尾还提供压缩的方式导出镜像(大小约250M左右)。
2. 编译环境
2.1 操作系统
[rootsurpass ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)2.2 gdal以及插件及版本
序号软件名称版本号1antapache-ant-1.10.122gdalgdal-2.4.43geosgeos-3.7.34hdf4hdf-4.2.135hdf5hdf5-1.10.56jpegsrcjpegsrc.v8c7netcdfnetcdf-c-4.4.1.18pcrepcre-8.459projproj-6.0.010swigswig-2.0.911jdkjdk-8u361-linux-x64
这里我已经准备好如果自己下载麻烦可以直接用的准备好的。gdal2.4.4源码编译及相关插件
3.环境准备
3.1 拷贝文件
当然第一步还是先将文件拷贝到centos系统中。
[rootsurpass gdal]# ll
总用量 200516
-rw-r--r--. 1 root root 5424638 3月 4 21:20 apache-ant-1.10.12-bin.tar.bz2
-rw-r--r--. 1 root root 14748072 3月 4 21:20 gdal-2.4.4.tar.gz
-rw-r--r--. 1 root root 2000211 3月 4 21:20 geos-3.7.3.tar.bz2
-rw-r--r--. 1 root root 4418314 3月 4 21:20 hdf-4.2.13.tar.gz
-rw-r--r--. 1 root root 12030972 3月 4 21:20 hdf5-1.10.5.tar.gz
-rw-r--r--. 1 root root 138762230 3月 4 21:20 jdk-8u361-linux-x64.tar.gz
-rw-r--r--. 1 root root 956918 3月 4 21:20 jpegsrc.v8c.tar.gz
-rw-r--r--. 1 root root 17670828 3月 4 21:20 netcdf-c-4.4.1.1.tar.gz
-rw-r--r--. 1 root root 1578809 3月 4 21:20 pcre-8.45.tar.bz2
-rw-r--r--. 1 root root 2405217 3月 4 21:20 proj-6.0.0.tar.gz
-rw-r--r--. 1 root root 5307341 3月 4 21:20 swig-2.0.9.tar.gz3.2 安装依赖环境
yum -y groupinstall Development tools
yum -y install gcc-c
yum -y install zlib-devel
yum -y install sqlite-devel
yum -y install bzip23.3 查看四个文件夹的内容
查看下面四个文件夹是否为空的如果不为空要记下里面的文件我这里是空的。
[rootsurpass local]# ll /usr/local/bin/
总用量 0
[rootsurpass local]# ll /usr/local/lib
总用量 0
[rootsurpass local]# ll /usr/local/include/
总用量 0
[rootsurpass local]# ll /usr/local/share/
总用量 0
drwxr-xr-x. 2 root root 6 4月 11 2018 applications
drwxr-xr-x. 2 root root 6 4月 11 2018 info
drwxr-xr-x. 21 root root 243 4月 27 2022 man4. 安装依赖文件
4.1 Proj安装
tar -zxvf proj-6.0.0.tar.gz
cd proj-6.0.0
./configure
make
make install
# 验证是否安装成功
proj —help此时proj文件编译的位置如下
可执行文件[rootsurpass bin]# ll /usr/local/bin/
总用量 2096
-rwxr-xr-x. 1 root root 192008 3月 4 21:42 cct
-rwxr-xr-x. 1 root root 192544 3月 4 21:42 cs2cs
-rwxr-xr-x. 1 root root 279296 3月 4 21:42 geod
-rwxr-xr-x. 1 root root 222448 3月 4 21:42 gie
lrwxrwxrwx. 1 root root 4 3月 4 21:42 invgeod - geod
lrwxrwxrwx. 1 root root 4 3月 4 21:42 invproj - proj
-rwxr-xr-x. 1 root root 172400 3月 4 21:42 proj
-rwxr-xr-x. 1 root root 1070520 3月 4 21:42 projinfo动态库[rootsurpass bin]# ll /usr/local/lib
总用量 114204
-rw-r--r--. 1 root root 85747468 3月 4 21:42 libproj.a
-rwxr-xr-x. 1 root root 940 3月 4 21:42 libproj.la
lrwxrwxrwx. 1 root root 17 3月 4 21:42 libproj.so - libproj.so.15.0.0
lrwxrwxrwx. 1 root root 17 3月 4 21:42 libproj.so.15 - libproj.so.15.0.0
-rwxr-xr-x. 1 root root 31187152 3月 4 21:42 libproj.so.15.0.0
drwxr-xr-x. 2 root root 21 3月 4 21:42 pkgconfig共享文件[rootsurpass proj]# ll /usr/local/share/proj/
总用量 6180
-rw-r--r--. 1 root root 1183 3月 4 21:42 CH
-rw-r--r--. 1 root root 728 3月 4 21:42 GL27
-rw-r--r--. 1 root root 2099 3月 4 21:42 ITRF2000
-rw-r--r--. 1 root root 3660 3月 4 21:42 ITRF2008
-rw-r--r--. 1 root root 3498 3月 4 21:42 ITRF2014
-rw-r--r--. 1 root root 19535 3月 4 21:42 nad27
-rw-r--r--. 1 root root 16593 3月 4 21:42 nad83
-rw-r--r--. 1 root root 6385 3月 4 21:42 nad.lst
-rw-r--r--. 1 root root 232 3月 4 21:42 null
-rw-r--r--. 1 root root 3915 3月 4 21:42 other.extra
-rw-r--r--. 1 root root 6242304 3月 4 21:42 proj.db
-rw-r--r--. 1 root root 7079 3月 4 21:42 world文件头[rootsurpass include]# ll /usr/local/include/
总用量 184
-rw-r--r--. 1 root root 44277 3月 4 21:42 geodesic.h
-rw-r--r--. 1 root root 2960 3月 4 21:42 org_proj4_PJ.h
drwxr-xr-x. 2 root root 179 3月 4 21:42 proj
-rw-r--r--. 1 root root 8346 3月 4 21:42 proj_api.h
-rw-r--r--. 1 root root 23206 3月 4 21:42 proj_constants.h
-rw-r--r--. 1 root root 34185 3月 4 21:42 proj_experimental.h
-rw-r--r--. 1 root root 42507 3月 4 21:42 proj.h
-rw-r--r--. 1 root root 19796 3月 4 21:42 proj_symbol_rename.h后面编译的软件基本在这几个文件夹如有特殊会单独说明。
4.2 安装java环境
4.2.1 解压压缩包
tar -zxvf jdk-8u361-linux-x64.tar.gz -C /usr/local/4.2.2 编辑环境变量
# 编译/etc/profile
export JAVA_HOME/usr/local/jdk1.8.0_361
export PATH$PATH:$JAVA_HOME/bin
export CLASSPATH.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar4.2.3 配置文件生效
source /etc/profile4.2.4 验证java环境有效性
[rootsurpass jdk1.8.0_361]# java -version
java version 1.8.0_361
Java(TM) SE Runtime Environment (build 1.8.0_361-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.361-b09, mixed mode)4.3 安装ant
4.3.1 解压压缩包
# 注意这里的参数是-j,不是-z.
tar -jxvf apache-ant-1.10.12-bin.tar.bz2 -C /usr/local/4.3.2 配置环境变量
vim /etc/profile
export ANT_HOME/usr/local/apache-ant-1.10.12
export PATH$PATH:$ANT_HOME/bin4.3.3 配置文件生效
source /etc/profile4.3.4 验证ant环境有效性
[rootsurpass apache-ant-1.10.12]# ant -version
Apache Ant(TM) version 1.10.12 compiled on October 13 20214.4. 安装pcre
tar -jxvf pcre-8.45.tar.bz2
cd pcre-8.45
./configure --enable-utf8
make
make install
# 验证是否安装成功
[rootsurpass bin]# geod
Rel. 6.0.0, March 1st, 20194.5 安装swig
tar -zxf swig-2.0.9.tar.gz
cd swig-2.0.9/
./configure
make
make install
[rootsurpass swig-2.0.9]# swig -version
SWIG Version 2.0.9
Compiled with g [x86_64-unknown-linux-gnu]
Configured options: pcre
Please see http://www.swig.org for reporting bugs and further information4.6 安装geos
tar -jxvf geos-3.7.3.tar.bz2
cd geos-3.7.3
make
make install
ldconfig4.7 安装jpeg
4.7.1 编译插件
tar -zxvf jpegsrc.v8c.tar.gz
cd jpeg-8c/
./configure --prefix/opt/jpeg
make
make install4.7.2 查看编译成果
[rootsurpass jpeg]# ll /opt/jpeg/
总用量 0
drwxr-xr-x. 2 root root 80 3月 4 22:22 bin
drwxr-xr-x. 2 root root 74 3月 4 22:22 include
drwxr-xr-x. 2 root root 103 3月 4 22:22 lib
drwxr-xr-x. 3 root root 17 3月 4 22:22 share4.8 安装hdf5
4.8.1 编译插件
tar -zxvf hdf5-1.10.5.tar.gz
cd hdf5-1.10.5
export F9Xifort
./configure --prefix/opt/hdf5 --with-hdf4/opt/hdf4 --with-jpeg/opt/jpeg --enable-java --enable-cxx
make
make install4.8.2 查看编译成果
[rootsurpass hdf5]# ll /opt/hdf5/
总用量 12
drwxr-xr-x. 2 root root 4096 3月 4 22:32 bin
drwxr-xr-x. 2 root root 4096 3月 4 22:32 include
drwxr-xr-x. 2 root root 4096 3月 4 22:32 lib
drwxr-xr-x. 3 root root 27 3月 4 22:32 share4.9 安装hdf4
4.9.1 编译插件
tar -zxvf hdf-4.2.13.tar.gz
cd hdf-4.2.13
./configure --prefix/opt/hdf4 --enable-netcdf --enable-jpeg --with-jpeg/opt/jpeg --enable-hdf5 --with-hdf5/opt/hdf5 --enable-shared --disable-fortran --enable-java
make
make install4.9.2 查看编译成果
[rootsurpass hdf-4.2.13]# ll /opt/hdf4
总用量 12
drwxr-xr-x. 2 root root 4096 3月 4 22:36 bin
drwxr-xr-x. 2 root root 4096 3月 4 22:36 include
drwxr-xr-x. 2 root root 4096 3月 4 22:36 lib
drwxr-xr-x. 4 root root 38 3月 4 22:36 share4.10 安装netcdf
4.10.1 编译插件
tar -zxvf netcdf-c-4.4.1.1.tar.gz
cd netcdf-c-4.4.1.1
CPPFLAGS-l/opt/hdf4/include -l/opt/hdf5/include -l/opt/jpeg/include
LDFLAGS-l/opt/hdf4/lib -l/opt/hdf5/lib -l/opt/jpeg/lib
./configure --prefix/opt/netcdf --enable-hdf5 --with-hdf5/opt/hdf5 --enable-hdf4 --with-hdf4/opt/hdf4 --enable-jpeg --with-jpeg/opt/jpeg --disable-netcdf-4
make
make install4.10.2 查看编译成果
[rootsurpass opt]# ll /opt/netcdf/
总用量 0
drwxr-xr-x. 2 root root 78 3月 4 22:40 bin
drwxr-xr-x. 2 root root 63 3月 4 22:40 include
drwxr-xr-x. 3 root root 158 3月 4 22:40 lib
drwxr-xr-x. 3 root root 17 3月 4 22:40 share5. 安装gdal
5.1 编译软件
经过一系列的插件终于可以编译gdal了。
tar -zxvf gdal-2.4.4.tar.gz
cd gdal-2.4.4
./configure --prefix/opt/netcdf --enable-hdf5 --with-hdf5/opt/hdf5 --enable-hdf4 --with-hdf4/opt/hdf4 --enable-jpeg --with-jpeg/opt/jpeg --disable-netcdf-4
make
make install5.2 修改配置文件
vim /etc/profile
export PATH${PATH}:/opt/hdf4/include:/opt/hdf4/bin:/opt/hdf5/include:/opt/hdf5/bin:/opt/netcdf/include:/opt/netcdf/bin:/opt/gdal/include:/opt/gdal/bin
export LD_LIBRARY_PATH${LD_LIBRARY_PATH}:/opt/hdf4/lib:/opt/hdf5/lib:/opt/netcdf/lib:/opt/gdal/lib
source /etc/profile[rootsurpass gdal-2.4.4]# gdalinfo --version
GDAL 2.4.4, released 2020/01/086. 后期数据准备
6.1 删除中间编译数据
将/usr/local、/opt/hdf4、/opt/hdf5、/opt/jpeg、/opt/netcdf的lib下的所有以a和la结尾的文件删除。
6.2 拷贝文件
将/opt/hdf4、/opt/hdf5、/opt/jpeg、/opt/netcdf下的bin、include、lib、share分别复制到/usr/local下相对应的文件夹下。
6.3 压缩导出
将/usr/local下的bin、include、lib、share赋值出来打成压缩包。如果想直接用可以看到这里gdal2.4.4编译的动态库
7. 打开镜像
7.1 下载centos镜像
docker pull centos
[rootsurpass gdal_lib]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7.9 eeb6ee3f44bd 17 months ago 204 MB7.2 打开镜像
打开镜像容器docker run --rm -it centos:7.9 bash将本地文件拷贝容器里[rootsurpass gdal_lib]# docker cp bin/ d21d5b03fbb4:/usr/local
[rootsurpass gdal_lib]# docker cp include/ d21d5b03fbb4:/usr/local
[rootsurpass gdal_lib]# docker cp lib/ d21d5b03fbb4:/usr/local
[rootsurpass gdal_lib]# docker cp share/ d21d5b03fbb4:/usr/local加载动态库 在/etc/ld.so.conf.d创建文件gdal.conf加入如下代码/usr/local/lib加载动态库ldconfig7.3 提交镜像
docker commit -mgdal_java -asurpassliang d21d5b03fbb4 gdal2.4.4_java:v0.1[rootsurpass gdal_lib]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gdal2.4.4_java v0.1 5895879a8d11 27 seconds ago 759 MB8. 导出镜像
# 导出镜像
docker save gdal_java:v0.2 | gzip gdal_java_v0.2.tar.gz
# 导入镜像
gunzip -c gdal_java_v0.2.tar.gz | docker load