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放入(結果測試成功!)

在這裏插入圖片描述

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時,只能從當前的項目中去找

以上純屬個人見解,如有問題請聯繫本人!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章