libhdfs的配置和使用

來源:互聯網
上載者:User

標籤:span   print   server   編譯   serve   sample   rar   root   wro   

測試環境:centos6.10,hadoop2.7.3,jdk1.8

測試代碼:HDFSCSample.c

#include "hdfs.h"#include <string.h>#include <stdio.h>#include <stdlib.h>int main(int argc, char **argv) {    hdfsFS fs = hdfsConnect("default", 0);    const char* writePath = "/tmp/testfile.txt";    hdfsFile writeFile = hdfsOpenFile(fs, writePath, O_WRONLY |O_CREAT, 0, 0, 0);    if(!writeFile) {          fprintf(stderr, "Failed to open %s for writing!\n", writePath);          exit(-1);    }    char* buffer = "Hello, World!";    tSize num_written_bytes = hdfsWrite(fs, writeFile, (void*)buffer, strlen(buffer)+1);    if (hdfsFlush(fs, writeFile)) {           fprintf(stderr, "Failed to ‘flush‘ %s\n", writePath);          exit(-1);    }    hdfsCloseFile(fs, writeFile);}

編譯指令碼:

  compile.sh

#!/bin/bashexport JAVA_HOME=/root/softs/jdk1.8.0_172export HADOOP_HOME=/root/softs/hadoop-2.7.3/gcc -I$HADOOP_HOME/include -L$HADOOP_HOME/lib/native -lhdfs -L$JAVA_HOME/jre/lib/amd64/server -ljvm HDFSCSample.c

執行命令: 

  # chmod +x compile.sh

  # ./compile.sh

執行指令碼:

  execute.sh

#!/bin/bashexport JAVA_HOME=/root/softs/jdk1.8.0_172export HADOOP_HOME=/root/softs/hadoop-2.7.3/export LD_LIBRARY_PATH=$HADOOP_HOME/lib/native:$JAVA_HOME/jre/lib/amd64/server/CLASSPATH=./for f in $HADOOP_HOME/share/hadoop/common/*.jar; do  CLASSPATH=${CLASSPATH}:$f;donefor f in $HADOOP_HOME/share/hadoop/common/lib/*.jar; do  CLASSPATH=${CLASSPATH}:$f;donefor f in $HADOOP_HOME/share/hadoop/hdfs/*.jar; do  CLASSPATH=${CLASSPATH}:$f;donefor f in $HADOOP_HOME/share/hadoop/hdfs/lib/*.jar; do  CLASSPATH=${CLASSPATH}:$f;doneexport CLASSPATH=$CLASSPATH./a.out

執行命令:

  # chmod +x execute.sh

  # ./execute.sh

開啟/tmp/testFile.txt,可以看到裡面寫入了一條 Hello, World!

  

libhdfs的配置和使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.