hbase 访问zookeeper的问题 坑

当使用HBaseConfiguration.create()创建配置时,程序默认连接本地Zookeeper的2181端口。若本地未运行Zookeeper服务器,将导致无法访问HBase。解决方法是在程序中通过设置'hbase.zookeeper.quorum'参数来指定Zookeeper集群地址。示例代码展示了如何在Reducer中设置该参数,从而正确连接到远程Zookeeper并访问HBase。
摘要由CSDN通过智能技术生成

1、 Configuration config = HBaseConfiguration.create(); 书上说是会自动加载hbase-site.xml里面配置的zookeeper 配置

但是实际上是访问的是localhost本地的zookeeper2181端口

2、因此如果本地不是zookeeper server 的话就无法访问hbase 了

3、解决办法通过参数传给程序

例子:

public static class CountReducer extends Reducer<Text, IntWritable, Text, Text> {
        private Text TABLE_NAME = new Text();
        private Text ZOOKEEPER = new Text();
        @Override
        protected void setup(Context context) throws IOException, InterruptedException {
            // 读取配置
            Configuration conf = context.getConfiguration();
            TABLE_NAME = new Text(conf.get("TABLE_NAME"));
            ZOOKEEPER = new Text(conf.get("hbase.zookeeper.quorum"));
            super.setup(context);
        }
        protected void reduce(Text text, Iterable<IntWritable> values,Context conte

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值