11.9打卡

连接Zookeeper的方法如下:
复制代码
public static Configuration hBaseConfiguration = null;
public static HBaseAdmin hBaseAdmin = null;

public static void init() {
    hBaseConfiguration = HBaseConfiguration.create();
    try {
        hBaseAdmin = new HBaseAdmin(hBaseConfiguration);
    } catch (Exception e) {
        throw new HbaseRuntimeException(e);
    }
}

复制代码
这里其实是将两个默认的配置文件加进来了,对于相同的配置项,后者会覆盖前者

conf.addResource("hbase-default.xml");
conf.addResource("hbase-site.xml");

可是总是报下面的错:

An error is preventing HBase from connecting to ZooKeeper

Caused by: java.io.IOException: Unable to determine ZooKeeper ensemble
断点跟踪到Zookeeper的源码发现是ZKUtil类的connect方法抛出的异常,

复制代码

    Watcher watcher, final String descriptor)
throws IOException {
  if(ensemble == null) {
    throw new IOException("Unable to determine ZooKeeper ensemble");
  }
  int timeout = conf.getInt("zookeeper.session.timeout", 180 * 1000);
  LOG.debug(descriptor + " opening connection to ZooKeeper with ensemble (" +
      ensemble + ")");
  return new ZooKeeper(ensemble, timeout, watcher);
}

复制代码
上述代码表明是没有读取到Zookeeper集群的地址,这个地址是在ZooKeeperWatcher的构造函数中读取的:

this.quorum = ZKConfig.getZKQuorumServersString(conf);
继续跟下去,发现配置信息是makeZKProps方法读取出来的,

复制代码

  // it and grab its configuration properties.
  ClassLoader cl = HQuorumPeer.class.getClassLoader();
  final InputStream inputStream =
    cl.getResourceAsStream(HConstants.ZOOKEEPER_CONFIG_NAME);
  if (inputStream != null) {
    try {
      return parseZooCfg(conf, inputStream);
    } catch (IOException e) {
      LOG.warn("Cannot read " + HConstants.ZOOKEEPER_CONFIG_NAME +
               ", loading from XML files", e);
    }
}

复制代码
看到这里才恍然大悟,它会首先去检查CLASSPATH下是否有zoo.cfg文件,如果有,则将其中的配置项读取出来作为Zookeeper的配置项,而此时就会完全不顾 hbase-default.xml和hbase-site.xml这两个配置文件了!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值