HBase:一个官方HBase MapReduce Read/Write Example出现的各种错误

1.声明

当前内容主要用于本人学习和复习,当前的内容为运行一个官方的demo,出现的各种问题错误

2.问题1,无法从mirror中加载hadoop-mapreduce-client-common-2.8.5.jar

在使用maven并添加这个pom依赖的时候:

<dependency>
	<groupId>org.apache.hadoop</groupId>
	<artifactId>hadoop-mapreduce-client-common</artifactId>
	<version>2.8.5</version>
</dependency>

直接说无法找到…(本人使用阿里的mirror)

解决办法,直接从Linux中的Hadoop的文件中(hadoop-2.8.5\share\hadoop\mapreduce直接复制到eclipse中),然后手动加入依赖

3.当前的还原后的demo

主要的pom依赖

	<dependencies>
		<!-- https://mvnrepository.com/artifact/org.apache.hbase/hbase-client -->
		<dependency>
			<groupId>org.apache.hbase</groupId>
			<artifactId>hbase-client</artifactId>
			<version>2.2.5</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.apache.hbase/hbase-mapreduce -->
		<dependency>
			<groupId>org.apache.hbase</groupId>
			<artifactId>hbase-mapreduce</artifactId>
			<version>2.2.5</version>
		</dependency>

		<!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-common -->
		<dependency>
			<groupId>org.apache.hadoop</groupId>
			<artifactId>hadoop-common</artifactId>
			<version>2.8.5</version>
		</dependency>

	</dependencies>
import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.mapreduce.Job;

public class HBaseMapReduceExample {
	private static String sourceTable = "test-filter";
	private static String targetTable = "test-filter2";

	public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
		Configuration config = HBaseConfiguration.create();
		config.set("hbase.zookeeper.quorum", "192.168.1.104:2181");
		Job job = new Job(config, "ExampleReadWrite");
		job.setJarByClass(HBaseMapReduceExample.class); // class that contains mapper
		Scan scan = new Scan();
		scan.setCaching(500); // 1 is the default in Scan, which will be bad for MapReduce jobs
		scan.setCacheBlocks(false); // don't set to true for MR jobs
		// set other scan attrs
		TableMapReduceUtil.initTableMapperJob(sourceTable, // input table
				scan, // Scan instance to control CF and attribute selection
				MyMapper.class, // mapper class
				null, // mapper output key
				null, // mapper output value
				job);
		TableMapReduceUtil.initTableReducerJob(targetTable, // output table
				null, // reducer class
				job);
		job.setNumReduceTasks(0);
		boolean b = job.waitForCompletion(true);
		if (!b) {
			throw new IOException("error with job!");
		}
	}

	public static class MyMapper extends TableMapper<ImmutableBytesWritable, Put> {
		public void map(ImmutableBytesWritable row, Result value, Context context)
				throws IOException, InterruptedException {
			// this example is just copying the data from the source table...
			context.write(row, resultToPut(row, value));
		}

		private static Put resultToPut(ImmutableBytesWritable key, Result result) throws IOException {
			Put put = new Put(key.get());
			for (Cell cell : result.listCells()) {
				put.add(cell);
			}
			return put;
		}
	}
}

先解释一下这个java的内容:主要是使用hadoop中的MapRedurce通过一个工作计划使HBase中的src表复制HBase的target表中(实现数据的复制)

4.问题2:HADOOP_HOME and hadoop.home.dir are unset

由于本人是使用eclipse(window10)访问Linux中的HBase的,出现这个问题,说要我配置HADOOP_HOME环境变量

于是使用管理员打开winrar并执行解压hadoop操作,配置环境变量:HADOOP_HOME,并配置PATH中为:%HADOOP_HOME%/bin

这里注意:如果再次执行出现了相同的问题请重启eclipse

此时执行发现又报错了!

5.问题3:Could not locate Hadoop executable: D:\Linux System\software\hadoop-2.8.5\bin\winutils.exe -see https://wiki.apache.org/hadoop/WindowsProblems

这个说我的hadoop中的bin中缺少winutils.exe,于是本人百度到处找这个winutils.exe(本人使用别人github上面的)

出现的问题:Cannot run program "D:\Linux System\software\hadoop-2.8.5\bin\winutils.exe": CreateProcess error=216, 该版本的 %1 与你运行的 Windows 版本不兼容。请查看计算机的系统信息,然后联系软件发布者

就是发现当前的github上面的winutils.exe文件与当前的windows10系统不兼容,于是重新下载,终于找到了一个107k的可以使用的winutils.exe
在这里插入图片描述

再次执行:还是报错

6.问题4:Exception in thread “main” java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z

这个问题就是说无法将当前的hadoop操作链接到windows操作,通过百度发现,原来就是这个hadoop.ddl没有添加的问题,直接复制github上面的hadoop.ddl放入(结果测试成功!)

在这里插入图片描述
这里给出windows10下hadoop2.8.5所需要的资源:资源

重启电脑后又出现了相同的问题:直接将hadoop.dll复制到windows中的System32中即可完成!

7.最后的执行结果

由于前面创建了一个表:‘test-filter’,所以这里直接使用复制表结构方式

clone_table_schema 'test-filter','test-filter2'

最后的执行结果:
在这里插入图片描述

发现test-filter中的数据被复制到test-filter2中了,实现了复制数据的操作

8.总结

1.使用windows10中的eclipse操作Linux中的Hadoop的时候,本机中必须配置环境变量HADOOP_HOME,并且具有windows10可用的的winutils.exe,还需要hadoop.ddl

2.有的时候mirror并不能获取jar时,只能从当前的项目中去找

以上纯属个人见解,如有问题请联系本人!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值