博客
关于我
第2.1.3章 hadoop之eclipse远程调试hadoop
阅读量:307 次
发布时间:2019-03-01

本文共 3182 字,大约阅读时间需要 10 分钟。

1 eclipse配置

下载插件,将放到eclipse的plugins目录或者dropins下,重启eclipse
选择Window->Show View->Other->MapReduce Tools->Map/Reduce Locations
Map/reduce配置
配置好后,eclipse可以连接到远程的DFS
dfs
2 windows配置
选择Window->Prefrences->Hadoop Map/Reduce,配置本地的hadoop,但是本地hadoop默认即可,不需要调整。
这里写图片描述
配置环境变量
1

将winutils.exe复制到本地hadoop的$HADOOP_HOME\bin目录

将hadoop.dll复制到%windir%\System32目录
winutils.exe和hadoop.dll的获取,您可以从csdn上下载,也可以自行在hadoop-common-project\hadoop-common\src\main\winutils编译那个.net工程
环境变量配置
1
2
3 wordcount示例的运行
创建maven工程,不赘述,在pom.xml中引入hadoop的jar。

2.6.4
org.apache.hadoop
hadoop-common
${ hadoop.version}
org.apache.hadoop
hadoop-hdfs
${ hadoop.version}
org.apache.hadoop
hadoop-client
${ hadoop.version}

将core-site.xml、hdfs-site.xml、mapred-site.xml、yarn-site.xml拷贝到src/main/resources

将源码中的WordCount导入到工程中,编译Export出jar到其他的文件夹中,为方便测试命名为testWordCount.jar
然后修改工程的main代码,添加下图红色部分内容
main
配置Run Configurations,在Arguments中添加参数
第一行hdfs://192.168.5.174:9000/user/hadoop/testdata/test.log是输入文件
第二行hdfs://192.168.5.174:9000/user/hadoop/testdata/output2是输出目录
hadoop 参数配置
test.log的内容可通过以下代码写入

import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import java.net.URI;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FSDataOutputStream;import org.apache.hadoop.fs.FileStatus;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IOUtils;import org.junit.Test;public class TestHdfs {   	@Test	public void test_hdfs(){   		String uri = "hdfs://192.168.5.174:9000/";		Configuration config = new Configuration(); 		try {   			FileSystem fs = FileSystem.get(URI.create(uri), config);			//			FileStatus[] statuses = fs.listStatus(new Path("/user/hadoop/testdata"));			for (FileStatus status:statuses){   				System.out.println(status);			}			//									FSDataOutputStream os = fs.create(new Path("/user/hadoop/testdata/test.log"));			os.write(readFile());			os.flush();			os.close();			//			InputStream is = fs.open(new Path("/user/hadoop/testdata/test.log")); 			IOUtils.copyBytes(is, System.out, 1024, true);  		} catch (IOException e) {   			e.printStackTrace();		}  			}		private byte[] readFile(){   		File file = new File("F:/阿里云/174/hadoop-hadoop-namenode-dashuju174.log");		StringBuffer text = new StringBuffer();		try {   			InputStreamReader read = new  InputStreamReader(new FileInputStream(file),"UTF-8");			String lineTxt = null;			BufferedReader bufferedReader = new BufferedReader(read);            while((lineTxt = bufferedReader.readLine()) != null){                   text.append(lineTxt).append("\n");            }            read.close();		} catch (UnsupportedEncodingException | FileNotFoundException e) {   			e.printStackTrace();		} catch (IOException e) {   			// TODO Auto-generated catch block			e.printStackTrace();		}		return text.toString().getBytes();	}}

运行后结果

hadoop运行结果

你可能感兴趣的文章
mysql 如何给SQL添加索引
查看>>
mysql 字段区分大小写
查看>>
mysql 字段合并问题(group_concat)
查看>>
mysql 字段类型类型
查看>>
MySQL 字符串截取函数,字段截取,字符串截取
查看>>
MySQL 存储引擎
查看>>
mysql 存储过程 注入_mysql 视图 事务 存储过程 SQL注入
查看>>
MySQL 存储过程参数:in、out、inout
查看>>
mysql 存储过程每隔一段时间执行一次
查看>>
mysql 存在update不存在insert
查看>>
Mysql 学习总结(86)—— Mysql 的 JSON 数据类型正确使用姿势
查看>>
Mysql 学习总结(87)—— Mysql 执行计划(Explain)再总结
查看>>
Mysql 学习总结(88)—— Mysql 官方为什么不推荐用雪花 id 和 uuid 做 MySQL 主键
查看>>
Mysql 学习总结(89)—— Mysql 库表容量统计
查看>>
mysql 实现主从复制/主从同步
查看>>
mysql 审核_审核MySQL数据库上的登录
查看>>
mysql 导入 sql 文件时 ERROR 1046 (3D000) no database selected 错误的解决
查看>>
mysql 导入导出大文件
查看>>
MySQL 导出数据
查看>>
mysql 将null转代为0
查看>>