【HDFS篇】eclipse下开发hadoop配置相关及测试HDFSDemo
2018-01-31 08:11
465 查看
安装前准备
1.将bin目录下bin目录下的的文件替换到hadoop下的bin。然后将hadoop.dll 他的核心扩展库放在windows system32下。
2.创建jar库 在hadoop的部署包下的涉及到HDFS、MapReduce、common、yarn、tools的jar都放在新建的hadoop-lib下。
3.配置环境变量
新建,HADOOP_HOME
新建HADOOP_USER_NAME,设置成root,原因是在开发HDFS客户端的时候,会告诉HDFS我登陆的用户名称,如果不配置,windows的用户名是什么就会传什么,保证以后方便,不该windows的用户名,直接把用户名配置成环境变量就行。
4.eclipse放入hadopp插件。放入plugins中。然后在视图中可选择hadoop的图标。
5.配置路径
6.新建hadoop
7.新建i项目,注意新建hadoop-lib的jar库。
==================================================
测试demo:
放入基于HA搭建后的hadoop的core-site.xml和hdfs-site.xml 文件
将配置文件的父目录加入source folder。
因为使用hadoop读配置文件的configuration类是在根目录读取配置文件的。所以必须加进来不然没法读取。
测试代码:
1.将bin目录下bin目录下的的文件替换到hadoop下的bin。然后将hadoop.dll 他的核心扩展库放在windows system32下。
2.创建jar库 在hadoop的部署包下的涉及到HDFS、MapReduce、common、yarn、tools的jar都放在新建的hadoop-lib下。
3.配置环境变量
新建,HADOOP_HOME
新建HADOOP_USER_NAME,设置成root,原因是在开发HDFS客户端的时候,会告诉HDFS我登陆的用户名称,如果不配置,windows的用户名是什么就会传什么,保证以后方便,不该windows的用户名,直接把用户名配置成环境变量就行。
4.eclipse放入hadopp插件。放入plugins中。然后在视图中可选择hadoop的图标。
5.配置路径
6.新建hadoop
7.新建i项目,注意新建hadoop-lib的jar库。
==================================================
测试demo:
放入基于HA搭建后的hadoop的core-site.xml和hdfs-site.xml 文件
将配置文件的父目录加入source folder。
因为使用hadoop读配置文件的configuration类是在根目录读取配置文件的。所以必须加进来不然没法读取。
测试代码:
public class TestHDFS { Configuration conf = null; FileSystem fs = null; @Before public void conn() throws Exception{ conf = new Configuration(true); fs = FileSystem.get(conf); } @After public void close() throws Exception{ 4000 fs.close(); } @Test public void mkdir() throws Exception{ Path input = new Path("/000"); if(fs.exists(input)){ fs.delete(input, true); } fs.mkdirs(input); } @Test public void upload() throws Exception{ Path file = new Path("/000/cx.txt"); FSDataOutputStream out = fs.create(file); InputStream in = new BufferedInputStream(new FileInputStream(new File("C:\\Users\\Administrator\\Desktop\\jw.txt"))); IOUtils.copyBytes(in, out, conf, true); } @Test public void download() throws Exception{ Path file = new Path("/000/cx.txt"); FSDataInputStream in = fs.open(file); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("E:\\chenxiao.txt")); IOUtils.copyBytes(in, out, conf); } @Test public void blks() throws Exception{ Path f = new Path("/user/root/chenxiao.txt"); FileStatus file = fs.getFileStatus(f ); BlockLocation[] blks = fs.getFileBlockLocations(file, 0, file.getLen()); for(BlockLocation blk : blks){ System.out.println(blk.toString()); } FSDataInputStream in = fs.open(f); System.out.println((char)in.readByte()); System.out.println((char)in.readByte()); System.out.println((char)in.readByte()); System.out.println((char)in.readByte()); in.seek(1048576); System.out.println((char)in.readByte()); } }
相关文章推荐
- hadoop学习之HDFS(2.1):linux下eclipse中配置hadoop-mapreduce开发环境并运行WordCount.java程序
- 配置 eclipse 编译、开发 Hadoop(MapReduce)源代码
- 配置Hadoop开发环境(Eclipse)
- os上的hadoop执行环境及eclipse嵌入hadoop开发环境配置记录
- 三:win7 下hadoop,eclipse开发环境配置
- Hadoop2.8.0 单机搭建和eclipse开发应用配置 新手笔记
- Hadoop学习2_Hadoop完全分布式的Eclipse开发环境配置
- 黑马程序员--基于Eclipse的Hadoop应用开发环境配置
- windows下基于Eclipse的Hadoop应用开发环境配置
- Hadoop开发环境配置2-eclipse集成maven插件
- 云计算Hadoop配置(四)——Eclipse中搭建Map-reduce开发环境
- ubuntu系统下eclipse配置hadoop开发环境并运行wordcount程序
- hadoop开发运行环境配置及相关问题总结
- Eclipse安装Hadoop插件配置Hadoop开发环境
- Eclipse中配置hadoop开发环境
- hadoop2.6安装配置以及整合eclipse开发环境
- eclipse配置hadoop2.7.2开发环境并本地跑起来
- hadoop 开发调试环境-eclipse配置记录
- eclipse相关下载安装配置---测试小白
- eclipse配置hadoop开发环境并运行WordCount小程序