educoder平台分布式文件系统HDFS

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

实验一HDFS的基本操作pwd回车cd/回车mkdir/develop回车mkdir/dev回车mkdir/develop/input回车mkdir/develop/output回车start-dfs.sh回车hadoopfs-mkdir/usr回车hadoopfs-mkdir/usr/input回车hadoopfs-mkdir/usr/output回车hadoopfs-ls/回车hadoopfs-ls/usr回车cd/dev回车cd/develop/input回车touchhelloworld.txt回车vimhelloworld.txt回车hellohadoop退出:wqhadoopfs-puthelloworld.txt/usr/output回车hadoopfs-cat/usr/output/helloworld.txt回车hadoopfs-ls/user/hadoop回车hadoopfs-ls/回车hadoopfs-ls/usr回车hadoopfs-ls/user回车hadoopfs-mv/usr/output/helloworld.txt/回车hadoopfs-ls/回车hadoopfs-rm/helloworld.txt回车hadoopfs-mkdir/usr/output回车touchhello.txt回车vimhello.txt回车HDFS的块比磁盘的块大,其目的是为了最小化寻址开销。退出wqhadoopfs-puthello.txt/usr/output回车hadoopfs-ls/usr/output回车hadoopfs-rm-r/user/hadoop回车hadoopfs-get/usr/output/hello.txt/usr/local回车ls/usr/local测评———————————————————————————————————————实验二第2关:HDFS-JAVA接口之读取文件先设置命令行publicstaticvoidmain(String[]args)throwsIOException{/*********Begin*********/URIuri=URI.create(hdfs://localhost:9000/user/hadoop/task.txt);Configurationconfig=newConfiguration();FileSystemfs=FileSystem.get(uri,config);InputStreamin=null;try{in=fs.open(newPath(uri));IOUtils.copyBytes(in,System.out,2048,false);}catch(Exceptione){IOUtils.closeStream(in);}/*********End*********/}}shell指令:start-dfs.sh回车touchtest.txt回车vimtest.txt独坐池塘如虎踞,绿荫树下养精神。春来我不先开口,哪个虫儿敢作声。退出wq测评———————————————————————————————————————实验三HDFS-JAVA接口之上传文件先设置命令行publicclassFileSystemUpload{publicstaticvoidmain(String[]args)throwsIOException{/*********Begin*********/FilelocalPath=newFile(/develop/input/hello.txt);StringhdfsPath=hdfs://localhost:9000/user/tmp/hello.txt;InputStreamin=newBufferedInputStream(newFileInputStream(localPath));Configurationconfig=newConfiguration();FileSystemfs=FileSystem.get(URI.create(hdfsPath),config);longfileSize=localPath.length()65536?localPath.length()/65536:1;FSDataOutputStreamout=fs.create(newPath(hdfsPath),newProgressable(){longfileCount=0;publicvoidprogress(){System.out.println(总进度+(fileCount/fileSize)*100+%);fileCount++;}});IOUtils.copyBytes(in,out,2048,true);/*********End*********/}}shell指令:mkdir/develop回车mkdir/develop/input回车cd/develop/input回车touchhello.txt回车vimhello.txt迢迢牵牛星,皎皎河汉女。纤纤擢素手,札札弄机杼。终日不成章,泣涕零如雨。河汉清且浅,相去复几许?盈盈一水间,脉脉不得语。《迢迢牵牛星》wq保存退出start-dfs.sh测评———————————————————————————————————————实验四HDFS-JAVA接口之删除文件先设置命令行publicclassFileSystemDelete{publicstaticvoidmain(String[]args)throwsIOException{/*********Begin*********/Stringuri=hdfs://localhost:9000/;Stringpath1=hdfs://localhost:9000/tmp;Stringpath2=hdfs://localhost:9000/user/hadoop;Stringpath3=hdfs://localhost:9000/tmp/test;Stringpath4=hdfs://localhost:9000/usr;Configurationconfig=newConfiguration();FileSystemfs=FileSystem.get(URI.create(uri),config);fs.delete(newPath(path2),true);fs.delete(newPath(path3),true);fs.delete(newPath(path4),true);Path[]paths={newPath(uri),newPath(path1)};FileStatus[]status=fs.listStatus(paths);Path[]listPaths=FileUtil.stat2Paths(status);for(Pathpath:listPaths){System.out.println(path);}/*********End*********/}}shell指令:start-dfs.sh测评

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功