码迷,mamicode.com
首页 > 其他好文 > 详细

HDFS

时间:2016-11-19 16:23:33      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:使用   log   java   int   机制   get   rgs   private   tao   

1.HDFS shell
1.0查看帮助
hadoop fs -help <cmd>
1.1上传
hadoop fs -put <linux上文件> <hdfs上的路径>
1.2查看文件内容
hadoop fs -cat <hdfs上的路径>
1.3查看文件列表
hadoop fs -ls /
1.4下载文件
hadoop fs -get <hdfs上的路径> <linux上文件>

 

2.使用java接口操作HDFS

public class HDFSDemo {
	
	private FileSystem fs = null;
	@Before
	public void init() throws IOException, URISyntaxException, InterruptedException{
		fs = FileSystem.get(new URI("hdfs://itcast01:9000"), new Configuration(),"root");
	}
	@Test
	public void  testDel() throws IllegalArgumentException, IOException{
		boolean flag = fs.delete(new Path("/words.txt"), true);
		System.out.println(flag);
	}
	@Test
	public void testMkdir() throws IllegalArgumentException, IOException{
		boolean flag = fs.mkdirs(new Path("/itcast88888888"));
		System.out.println(flag);
	}
	@Test
	public void testUpload() throws IllegalArgumentException, IOException{
		FSDataOutputStream out = fs.create(new Path("/words.txt"));
		FileInputStream in = new FileInputStream(new File("c:/w.txt"));
		IOUtils.copyBytes(in, out, 2048, true);
	}

	public static void main(String[] args) throws IOException, URISyntaxException {
		FileSystem fs = FileSystem.get(new URI("hdfs://itcast01:9000"), new Configuration());
		InputStream in = fs.open(new Path("/jdk.avi"));
		FileOutputStream out = new FileOutputStream(new File("c:/jdk123456"));
		IOUtils.copyBytes(in, out, 2048, true);
	}
}

  

 

3.hadoop通信机制
不同进程之间的方法进行调用

 

4.HDFS源码分析
FileSystem.get --> 通过反射实例化了一个DistributedFileSystem --> new DFSCilent()把他作为自己的成员变量
在DFSClient构造方法里面,调用了createNamenode,使用了RPC机制,得到了一个NameNode的代理对象,就可以和NameNode进行通信了

FileSystem --> DistributedFileSystem --> DFSClient --> NameNode的代理

 

HDFS

标签:使用   log   java   int   机制   get   rgs   private   tao   

原文地址:http://www.cnblogs.com/ganchuanpu/p/6080461.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!