连接hbase报以下错:

Caused by: java.io.IOException: org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /hbase/meta-region-server
	at org.apache.hadoop.hbase.client.ConnectionImplementation.get(ConnectionImplementation.java:2013)
	at org.apache.hadoop.hbase.client.ConnectionImplementation.locateMeta(ConnectionImplementation.java:789)
	at org.apache.hadoop.hbase.client.ConnectionImplementation.locateRegion(ConnectionImplementation.java:756)
	at org.apache.hadoop.hbase.client.ConnectionImplementation.locateRegion(ConnectionImplementation.java:745)
	at org.apache.hadoop.hbase.client.ConnectionImplementation.locateRegion(ConnectionImplementation.java:716)
	at org.apache.hadoop.hbase.client.ConnectionImplementation.getRegionLocation(ConnectionImplementation.java:594)
	at org.apache.hadoop.hbase.client.HRegionLocator.getRegionLocation(HRegionLocator.java:72)
	at org.apache.hadoop.hbase.client.RegionServerCallable.prepare(RegionServerCallable.java:223)
	at org.apache.hadoop.hbase.client.RpcRetryingCallerImpl.callWithRetries(RpcRetryingCallerImpl.java:105)
	... 23 more
Caused by: org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /hbase/meta-region-server
	at org.apache.zookeeper.KeeperException.create(KeeperException.java:111)
	at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
	at org.apache.hadoop.hbase.zookeeper.ReadOnlyZKClient$ZKTask$1.exec(ReadOnlyZKClient.java:168)
	at org.apache.hadoop.hbase.zookeeper.ReadOnlyZKClient.run(ReadOnlyZKClient.java:323)
	at java.lang.Thread.run(Thread.java:745)

代码为:

val zk_quorum = PropertyUtil.getValueByKey("conf/dipc.properties", "zookeeper_hadoop_connection")
  val zk_port = PropertyUtil.getValueByKey("conf/dipc.properties", "zookeeper_hadoop_port")
  val hbase_parent = PropertyUtil.getValueByKey("conf/dipc.properties", "zookeeper_znode_parent")

  val hbaseConf = HBaseConfiguration.create()
  hbaseConf.set("hbase.zookeeper.quorum", zk_quorum) //设置zooKeeper集群地址,也可以通过将hbase-site.xml导入classpath,但是建议在程序里这样设置
  hbaseConf.set("hbase.zookeeper.property.clientPort", zk_port) //设置zookeeper连接端口,默认2181
  hbaseConf.set("zookeeper.znode.parent",hbase_parent)
  hbaseConf.set(TableInputFormat.INPUT_TABLE, tableName)

  private val conn: Connection = ConnectionFactory.createConnection(hbaseConf)
  private val admin: Admin = conn.getAdmin

dipc.properties

#hadoop ZK客户端连接信息
zookeeper_hadoop_connection=zk1:2181,zk2:2181,zk3:2181
zookeeper_hadoop_port=2181
 
#hbase相关配置
zookeeper_znode_parent=/hbase

解决方案:zookeeper.znode.parent的值不是/hbase ,而是/hbase-unsecure,不同的环境,此默认值不一样,CDH是/hbase,HDP是/hbase-unsecure,我们用的是HDP,修改为hbase即可,或者更改代码为/hbase-unsecure

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐