/home/centos/hadoop-2.9.2/share/hadoop/common
/home/centos/hadoop-2.9.2/share/hadoop/mapreduce
다음 경로에 있는 jar 파일 12개를 이클립스 프로젝트의 lib에 추가해준다.
package hdfs;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class hdfsFile {
public static void main(String[] args){
if(args.length !=2){
System.err.println("사용 방법: HdfsFile <filename> <contents>");
System.exit(2);
}
try {
Configuration conf = new Configuration();
FileSystem hdfs = FileSystem.get(conf);
Path path = new Path(args[0]);
if(hdfs.exists(path)) {
hdfs.delete(path, true);
}
//파일 저장
FSDataOutputStream os = hdfs.create(path);
os.writeUTF(args[1]);
os.close();
//파일내용읽기
FSDataInputStream is = hdfs.open(path);
String inputString = is.readUTF();
is.close();
//화면에 출력
System.out.println("Input Data:" + inputString);
} catch(Exception e) {
e.printStackTrace();
}
}}
hdfsFile을 만들어 hadoop.jar 파일로 export 해준다.
[root@master source]# hadoop jar /home/centos/source/Hadoop.jar hdfs.hdfsFile input.txt "Hello, Hadoop. Hello, World"
이 파일을 적당한 위치에 옮긴 뒤 실행해준다.
실행 결과를 확인하고 hdfs에서 조회해본다.
잘 생성된 것을 확인할 수 있다.
'미분류 > Hadoop' 카테고리의 다른 글
Hadoop - Oozie 설치하기 (0) | 2019.04.10 |
---|---|
Hadoop - Zookeeper 설치하기 (0) | 2019.04.10 |
Hadoop - Pig 설치하기 (0) | 2019.04.09 |
VMware를 이용하여 Hadoop 완전분산모드 구축 (0) | 2019.04.04 |
CentOS7 기반으로 Hadoop Standalone 설치하기 (0) | 2019.04.01 |