HBase使用常见异常

无法连接ZooKeeper


典型异常:

INFO ClientCnxn: Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)

15/07/12 10:06:33 WARN ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect


例如当我们想获取HBase某张表各个Region的Start Keys时,使用下面的代码:

val hbaseConf = HBaseConfiguration.create
val htable = new HTable(hbaseConf, s"${tablename}")
val startKeys = htable.getStartKeys
startKeys.foreach(keys => println(Bytes.toStringBinary(keys)))



如果运行上述代码的节点没有安装ZooKeeper,那么就会报Session 0x0 for server null异常,如果运行的节点是ZooKeeper Qurom的一个节点,就不会报异常。


原因:由于代码中在创建HBase Configuration时没有显式地指定ZooKeeper Qurom,HBase的应用程序不知道到哪里去连接ZooKeeper Qurom,因此它会去尝试连接一个默认<localhost:2181>,从下面的日志可以看出来:

INFO ClientCnxn: Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)



因此,我们可以在代码中指定ZooKeeper Qurom的地址,如下:

val hbaseConf = HBaseConfiguration.create
hbaseConf.set(HConstants.ZOOKEEPER_QUORUM, Commons.ZkQurom)



这样,就可以连接到位于其他节点的ZooKeeper了,从下面的日志可以看出:

INFO ZooKeeper: Initiating client connection, connectString=hadoop4.com:2181,hadoop1.com:2181,hadoop5.com:2181 sessionTimeout=90000 watcher=hconnection-0x68122ade, quorum=hadoop4.com:2181,hadoop1.com:2181,hadoop5.com:2181, baseZNode=/hbase

15/07/12 10:15:58 INFO ClientCnxn: Opening socket connection to server hadoop1.com/59.215.222.3:2181. Will not attempt to authenticate using SASL (unknown error)

15/07/12 10:15:58 INFO ClientCnxn: Socket connection established to hadoop1.com/59.215.222.3:2181, initiating session

15/07/12 10:15:58 INFO ClientCnxn: Session establishment complete on server hadoop1.com/59.215.222.3:2181, sessionid = 0x24e51f0d17b4955, negotiated timeout = 60000

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值