1.需求
根據(jù)GDAL2.4.0的更新說(shuō)明瓣履,從該版本開始GDAL支持對(duì)HDFS存儲(chǔ)的影像數(shù)據(jù)的讀取岔绸,但是目前發(fā)布的prebuilt版本均沒(méi)有提供此功能,因此需要從源代碼重新編譯。
2.環(huán)境
CentOS 7 , GDAL 2.4.0 , hadoop 2.9.2
3.編譯準(zhǔn)備
3.1源代碼下載
GDAL:https://github.com/OSGeo/gdal/releases
hadoop:https://hadoop.apache.org/releases.html
4.編譯hadoop
下載hadoop源代碼并解壓縮后籍嘹,在BUILDING.txt文件可看到hadoop的安裝指南方库,其中編譯需求摘錄如下:
Requirements:
* Unix System
* JDK 1.7 or 1.8
* Maven 3.0 or later
* Findbugs 1.3.9 (if running findbugs)
* ProtocolBuffer 2.5.0
* CMake 2.6 or newer (if compiling native code), must be 3.0 or newer on Mac
* Zlib devel (if compiling native code)
* openssl devel (if compiling native hadoop-pipes and to get the best HDFS encryption performance)
* Linux FUSE (Filesystem in Userspace) version 2.6 or above (if compiling fuse_dfs)
* Internet connection for first build (to fetch all Maven and Hadoop dependencies)
* python (for releasedocs)
* Node.js / bower / Ember-cli (for YARN UI v2 building)
根據(jù)該說(shuō)明下載相關(guān)軟件并安裝后结序,進(jìn)入hadoop-2.9.2-src源代碼目錄,執(zhí)行
mvn clean package -Pdist,native -DskipTests -Dtar -Dsnappy.lib=/usr/lib64 -Dbundle.snappy -Drequire.openssl
進(jìn)行編譯和打包纵潦,打包好的文件位于hadoop-2.9.2-src/hadoop-dist
目錄下
5.配置libhdfs.so
libhdfs.so是hadoop提供的操作HDFS的C語(yǔ)言客戶端徐鹤,經(jīng)過(guò)上一步的編譯后,生成的libhdfs.so位于/hadoop-dist/target/hadoop-2.9.2/lib/native/
邀层,生成的hdfs.h頭文件位于/hadoop-dist/target/hadoop-2.9.2/include/
返敬,然后將libhdfs.so拷貝到/usr/local/lib
,將hdfs.h文件拷貝到/usr/local/include
寥院,編寫測(cè)試代碼testhdfs.c
#include <stdio.h>
#include "hdfs.h"
int main(int argc, char **argv)
{
hdfsFS fs = hdfsConnect("10.46.120.32", 8010);
if (!fs) {
fprintf(stderr, "connect fail\n");
return -1;
}
hdfsFile writeFile = hdfsOpenFile(fs, "/first.txt", O_WRONLY, 4096, 0, 0);
if (!writeFile) {
fprintf(stderr,"openfile fali\n");
return -1;
}
hdfsWrite(fs, writeFile, "hello hdfs", 10);
hdfsCloseFile(fs, writeFile);
hdfsDisconnect(fs);
return 0;
}
使用GCC編譯gcc testhdfs.c -lhdfs
劲赠,若編譯成功,表示以上步驟正確秸谢,libhdfs.so配置正確经磅。
6.編譯gdal
進(jìn)入gdal源代碼路徑下,輸入
./configure --with-java=/home/jdk1.8.0_191 --with-hdfs=/usr/local/
make
make install
默認(rèn)安裝路徑在/usr/local
钮追,在控制臺(tái)輸入gdalinfo --version
看到版本信息即代表編譯安裝成功预厌。
6.1.編譯gdal的Java binding
首先需要安裝swig和ant
yum install -y swig
http://ant.apache.org/
然后進(jìn)入/gdal/swig/java
目錄,在控制臺(tái)輸入make
元媚,即可在該目錄下生成gdal.jar,libgdalalljni.so,libgdalalljni.la
三個(gè)文件轧叽,最后將so文件和la文件拷貝到/usr/local/lib
下
7.測(cè)試gdal讀取hdfs文件
將hadoop配置文件core_site.xml拷貝到本機(jī)HADOOP_HOME目錄下
在控制臺(tái)輸入
gdalinfo /vsihdfs/hdfs://ip:port/tif/3857t.tif
若成功顯示該tiff文件的信息苗沧,則說(shuō)明GDAL+HDFS編譯安裝成功。
7.1.測(cè)試gdal通過(guò)webHDFS接口讀取hdfs文件
在控制臺(tái)輸入
gdalinfo /vsiwebhdfs/http://ip:port/webhdfs/v1/tif/3857t.tif
補(bǔ)充
如需支持ESRI FileGDB讀寫炭晒,首先從GitHub上下載對(duì)應(yīng)操作系統(tǒng)的FileGDB API待逞,然后在編譯GDAL時(shí)添加
./configure --prefix=/export/gdal/gdal-3.4.3/build --with-java=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.352.b08-2.el7_9.x86_64 with_fgdb=/export/esri_filegdb_api/FileGDB_API_RHEL7_64