org.apache.hadoop.hbase.MasterNotRunningException解决策略
执行HBase时常会遇到个错误,我就有这种经历。
ERROR: org.apache.hadoop.hbase.MasterNotRunningException: Retried 7 times
检查日志:org.apache.hadoop.ipc.RPC$VersionMismatch: Protocol org.apache.hadoop.hdfs.protocol.ClientProtocol version mismatch. (client = 42, server = 41)
假设是这个错误,说明RPC协议不一致所造成的,解决方法:将hbase/lib文件夹下的hadoop-core的jar文件删除。将hadoop文件夹下的hadoop-0.20.2-core.jar复制到hbase/lib以下。然后又一次启动hbase就可以。
另外一种错误是:没有启动hadoop。先启用hadoop,再启用hbase。
在Eclipse开发中,须要增加hadoop全部的jar包以及HBase二个jar包(hbase,zooKooper)。
- 建表,通过HBaseAdmin类中的create静态方法来创建表。
- HTable类是操作表,比如,静态方法put能够插入数据,该类初始化时能够传递一个行键,静态方法getScanner()能够获得某一列上的全部数据。返回Result类,Result类中有个静态方法getFamilyMap()能够获得以列名为key,值为value,这刚好与hadoop中map结果是一样的。
package test;
import java.io.IOException;
import java.util.Map;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result; public class Htable { /**
* @param args
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Configuration hbaseConf = HBaseConfiguration.create();
HBaseAdmin admin = new HBaseAdmin(hbaseConf);
HTableDescriptor htableDescriptor = new HTableDescriptor("table"
.getBytes()); //set the name of table
htableDescriptor.addFamily(new HColumnDescriptor("fam1")); //set the name of column clusters
admin.createTable(htableDescriptor); //create a table
HTable table = new HTable(hbaseConf, "table"); //get instance of table.
for (int i = 0; i < 3; i++) { //for is number of rows
Put putRow = new Put(("row" + i).getBytes()); //the ith row
putRow.add("fam1".getBytes(), "col1".getBytes(), "vaule1"
.getBytes()); //set the name of column and value.
putRow.add("fam1".getBytes(), "col2".getBytes(), "vaule2"
.getBytes());
putRow.add("fam1".getBytes(), "col3".getBytes(), "vaule3"
.getBytes());
table.put(putRow);
}
for(Result result: table.getScanner("fam1".getBytes())){//get data of column clusters
for(Map.Entry<byte[], byte[]> entry : result.getFamilyMap("fam1".getBytes()).entrySet()){//get collection of result
String column = new String(entry.getKey());
String value = new String(entry.getValue());
System.out.println(column+","+value);
}
}
admin.disableTable("table".getBytes()); //disable the table
admin.deleteTable("table".getBytes()); //drop the tbale
}
}以上代码不难看懂。
以下介绍一下,用mapreduce如何操作HBase。主要对HBase中的数据进行读取。
如今有一些大的文件,须要存入HBase中。其思想是先把文件传到HDFS上,利用map阶段读取<key,value>对,可在reduce把这些键值对上传到HBase中。

package test; import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper; public class MapperClass extends Mapper<LongWritable,Text,Text,Text>{
public void map(LongWritable key,Text value,Context context)thorws IOException{
String[] items = value.toString().split(" ");
String k = items[0];
String v = items[1];
context.write(new Text(k), new Text(v));
} }

Reduce类,主要是将键值传到HBase表中

package test; import java.io.IOException;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableReducer;
import org.apache.hadoop.io.Text; public class ReducerClass extends TableReducer<Text,Text,ImmutableBytesWritable>{
public void reduce(Text key,Iterable<Text> values,Context context){
String k = key.toString();
StringBuffer str=null;
for(Text value: values){
str.append(value.toString());
}
String v = new String(str);
Put putrow = new Put(k.getBytes());
putrow.add("fam1".getBytes(), "name".getBytes(), v.getBytes());
}
}

由上面可知ReducerClass继承TableReduce,在hadoop里面ReducerClass继承Reducer类。它的原型为:TableReducer<KeyIn,Values,KeyOut>能够看出,HBase里面是读出的Key类型是ImmutableBytesWritable。
Map,Reduce。以及Job的配置分离。比較清晰,mahout也是採用这样的构架。

package test; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.util.Tool; public class Driver extends Configured implements Tool{ @Override
public static void run(String[] arg0) throws Exception {
// TODO Auto-generated method stub
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum.", "localhost"); Job job = new Job(conf,"Hbase");
job.setJarByClass(TxtHbase.class); Path in = new Path(arg0[0]); job.setInputFormatClass(TextInputFormat.class);
FileInputFormat.addInputPath(job, in); job.setMapperClass(MapperClass.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class); TableMapReduceUtil.initTableReducerJob("table", ReducerClass.class, job); job.waitForCompletion(true);
} }

Driver中job配置的时候没有设置 job.setReduceClass(); 而是用 TableMapReduceUtil.initTableReducerJob("tab1", THReducer.class, job); 来运行reduce类。
主函数

package test; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.ToolRunner; public class TxtHbase {
public static void main(String [] args) throws Exception{ Driver.run(new Configuration(),new THDriver(),args); }
}

读取数据时比較简单,编写Mapper函数,读取<key,value>值即可了。

package test; import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapred.TableMap;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter; public class MapperClass extends MapReduceBase implements
TableMap<Text, Text> {
static final String NAME = "GetDataFromHbaseTest";
private Configuration conf; public void map(ImmutableBytesWritable row, Result values,
OutputCollector<Text, Text> output, Reporter reporter)
throws IOException {
StringBuilder sb = new StringBuilder();
for (Entry<byte[], byte[]> value : values.getFamilyMap(
"fam1".getBytes()).entrySet()) {
String cell = value.getValue().toString();
if (cell != null) {
sb.append(new String(value.getKey())).append(new String(cell));
}
}
output.collect(new Text(row.get()), new Text(sb.toString()));
}

要实现这种方法 initTableMapJob(String table, String columns, Class<?
extends TableMap> mapper, Class<? is-external=true">Class
extends org.apache.hadoop.io.WritableComparable> outputKeyClass,
org.apache.hadoop.mapred.JobConf job, boolean addDependencyJars)。

package test; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.util.Tool; public class Driver extends Configured implements Tool{ @Override
public static void run(String[] arg0) throws Exception {
// TODO Auto-generated method stub
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum.", "localhost");
Job job = new Job(conf,"Hbase");
job.setJarByClass(TxtHbase.class);
job.setInputFormatClass(TextInputFormat.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class); TableMapReduceUtilinitTableMapperJob("table", args0[0],MapperClass.class, job);
job.waitForCompletion(true); }
}

主函数

package test; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.ToolRunner; public class TxtHbase {
public static void main(String [] args) throws Exception{ Driver.run(new Configuration(),new THDriver(),args); }
}
org.apache.hadoop.hbase.MasterNotRunningException解决策略的更多相关文章
- 远程调用HBase出错,尝试10次后,报org.apache.hadoop.hbase.MasterNotRunningException错误
网上的解决方案挺多的,但都不适用于我今天下午碰到的情况. 环 境:HBase-0.90.3在debian 6下,客户端在windows上.我用之前的HBase服务器是没问题的,但重新解压并配置后就有问 ...
- org.apache.hadoop.hbase.TableNotDisabledException 解决方法
Exception in thread "main" org.apache.hadoop.hbase.TableNotDisabledException: org.apache.h ...
- Cloudera集群中提交Spark任务出现java.lang.NoSuchMethodError: org.apache.hadoop.hbase.HTableDescriptor.addFamily错误解决
Cloudera及相关的组件版本 Cloudera: 5.7.0 Hbase: 1.20 Hadoop: 2.6.0 ZooKeeper: 3.4.5 就算是引用了相应的组件依赖,依然是报一样的错误! ...
- 【解决】org.apache.hadoop.hbase.ClockOutOfSyncException:
org.apache.hadoop.hbase.ClockOutOfSyncException: org.apache.hadoop.hbase.ClockOutOfSyncException: Se ...
- 执行HBase shell时出现ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet错误解决办法(图文详解)
不多说,直接上干货! [kfk@bigdata-pro01 bin]$ jps NameNode ResourceManager JournalNode HMaster DataNode HRegio ...
- hbase运行时ERROR:org.apache.hadoop.hbase.PleaseHoldException:Master is initializing的解决方法
最终解决了,其实我心中有一句MMP. 版本: hadoop 2.6.4 + hbase0.98 第一个问题,端口问题8020 hadoop默认的namenode 资源子接口是8020 端口,然后我这接 ...
- 使用IDEA操作Hbase API 报错:org.apache.hadoop.hbase.client.RetriesExhaustedException的解决方法:
使用IDEA操作Hbase API 报错:org.apache.hadoop.hbase.client.RetriesExhaustedException的解决方法: 1.错误详情: Excepti ...
- 运行HBase应用开发程序产生异常,提示信息包含org.apache.hadoop.hbase.ipc.controller.ServerRpcControllerFactory的解决办法
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties Exception in thread ...
- hbase(ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet)
今天启动clouder manager集群时候hbase list出现 (ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException ...
随机推荐
- MongoDB 学习笔记(1)
数据库 一个mongodb中可以建立多个数据库. MongoDB的默认数据库为"db",该数据库存储在data目录中. MongoDB的单个实例可以容纳多个独立的数据库,每一个都有 ...
- Lighttpd1.4.20源代码分析 笔记 状态机之错误处理和连接关闭
这里所说的错误有两种: 1.http协议规定的错误,如404错误. 2.server执行过程中的错误.如write错误. 对于http协议规定的错误,这里的"错误"是针对clien ...
- js事件之event.preventDefault()与(www.111cn.net)event.stopPropagation()用法区别
event.preventDefault()用法介绍 该方法将通知 Web 浏览器不要执行与事件关联的默认动作(如果存在这样的动作).例如,如果 type 属性是 "submit" ...
- 《自己动手写框架2》:用200行的DBF解析器来展示良好架构设计
因为工作关系.须要工作其中,须要读取DBF文件.找了一些DBF读取开源软件,要么是太过庞大,动不动就上万行.要么是功能有问题,编码,长度,总之是没有找到一个很爽的. 在万般无奈之下,我老人家怒从心头起 ...
- win10 docker 安装部署
Docker 安装教程: https://blog.csdn.net/hunan961/article/details/79484098 安装docker前需要首先开启虚拟服务:重启电脑-->F ...
- 搭建MVC及WEB API项目框架时碰到的问题集合
前言 刚开始创建MVC与Web API的混合项目时,碰到好多问题,今天拿出来跟大家一起分享下.有朋友私信我问项目的分层及文件夹结构在我的第一篇博客中没说清楚,那么接下来我就准备从这些文件怎么分文件夹说 ...
- java中多个数字运算后值不对(失真)处理方法
最近遇到一个bug ,在java里面计算两个数字相减,633011.20-31296.30 得到的结果居然是601714.8999999999,丢失精度了,原来这是Java浮点运算的一个bug. 解决 ...
- 如何不使用Navigator空间实现跳转页面?
//引入 Loading页面 主页面 登录页等页面组件 constructor(props) { super(props); this.state = { 登录状态: 等待检查 }; } compon ...
- [LeetCode] Shortest Word Distance I & II & III
Shortest Word Distance Given a list of words and two words word1 and word2, return the shortest dist ...
- ASP.NET MVC中的cshtml页面中的下拉框的使用
ASP.NET MVC中的cshtml页面中的下拉框的使用 用上@Html.DropDownList 先记下来..以做备忘...