Configuration and use of Libhdfs

Source: Internet
Author: User

Tags: span print server compilation serve sample RAR root Wro

Test environment: centos6.10,hadoop2.7.3,jdk1.8

Test code: HDFSCSAMPLE.C

#include"Hdfs.h"#include<string.h>#include<stdio.h>#include<stdlib.h>intMainintargcChar**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 script:

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

Execute command:

# chmod +x compile.sh

#./compile.sh

Execute script:

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 in $HADOOP _home/share/hadoop/common/*. jar; do  CLASSPATH =${classpath}: $f;d onefor F in $HADOOP _home/share/hadoop/common/lib/*.jar; Do  Classpath=${classpath}: $f;d onefor F-$HADOOP _home/share/hadoop/hdfs/*.jar; do  Classpath=${classpath }: $f;d onefor F in $HADOOP _home/share/hadoop/hdfs/lib/*.jar; Do  Classpath=${classpath}: $f;d oneexport classpath= $CLASSPATH./a.out

Execute command:

# chmod +x execute.sh

#./execute.sh

Open/tmp/testfile.txt, you can see the inside write a Hello, world!

  

Configuration and use of Libhdfs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: