hbase2.1.3 docker安装与java client测试,开发连接需要特别注意一下配置,否则连接不上timeout

hbase2.1.3 docker安装与java client测试,开发连接需要特别注意一下配置,否则连接不上timeout,第1张

hbase2.1.3 docker安装与java client测试,开发连接需要特别注意一下配置,否则连接不上timeout 1.docker安装
docker run --name hbase --net=host -v /etc/hbase/conf:/hbase-2.1.3/conf -v /home/data/hbase:/hbase-data  harisekhon/hbase
2.修改hbase-sit.xml配置的hbase.master.hostname,hbase.regionserver.hostname,否则开发环境无法连接到hbase。因为开发环境项目的hbase java client

配置hbase连接只配置的ZK地址,故开发环境是通过获取注册到ZK的hbase master,regionserver的真实地址连接的,故需要在ZK注册网络可通的IP地址。

[root@node1 ~]# vim /etc/hbase/conf/
hadoop-metrics2-hbase.properties  hbase-env.sh                      hbase-site.xml                    regionservers
hbase-env.cmd                     hbase-policy.xml                  log4j.properties                  

 
    hbase.master.hostname
    192.168.1.19
  
  
    hbase.regionserver.hostname
    192.168.1.19
  
  
    hbase.cluster.distributed
    true
  
  
    hbase.rootdir
    /hbase-data
  
  
    hbase.zookeeper.quorum
    localhost:2181
  


3.进入docker容器执行命令(hbase shell)进入交互界面,创建一个测试表
Hbase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
For Reference, please visit: http://hbase.apache.org/2.0/book.html#shell
Version 2.1.3, rda5ec9e4c06c537213883cca8f3cc9a7c19daf67, Mon Feb 11 15:45:33 CST 2019
Took 0.0061 seconds                                                                                                                                                       
hbase(main):001:0> create 'person','info'
Created table person
Took 2.0373 seconds                                                                                                                                                       
=> Hbase::Table - person
hbase(main):002:0> list
TABLE                                                                                                                                                                     
person                                                                                                                                                                    
1 row(s)
Took 0.0622 seconds                                                                                                                                                       
=> ["person"]

4.本地java连接hbase进行CRUD;hbase的API不好用,建议做个再封装
package com.jwolf.bigdata;

import lombok.SneakyThrows;
import org.apache.hadoop.hbase.HbaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;


public class HbaseTest {

    @SneakyThrows
    public static void main(String[] args) {
        org.apache.hadoop.conf.Configuration configuration = HbaseConfiguration.create();
        configuration.set("hbase.zookeeper.quorum", "192.168.1.19");
        configuration.set("hbase.zookeeper.port", "2181");
        configuration.set("hbase.zookeeper.znode", "/hbase");
        configuration.set("hbase.client.keyvalue.maxsize", "1572864000");
        configuration.set("hbase.regionserver.port", "1572864000");
        long t = System.currentTimeMillis();
        Connection conn = ConnectionFactory.createConnection(configuration);
        System.out.println("连接耗时" + (System.currentTimeMillis() - t));
        //查看所有表
        // todo:连接不上,docker log显示 Client attempting to establish new session at /192.168.1.11:62303
        String tables = Arrays.stream(conn.getAdmin().listTableNames()).map(TableName::getNameAsString).collect(Collectors.joining());
        System.out.println("已存在表:" + tables);
        //存入数据
        Map cloumns = new HashMap();
        cloumns.put("name", "zzq");//列名和值
        cloumns.put("age", "22");
        //往表中的第row=1的info族中增加了名为name、age数据
        Put put = new Put("1".getBytes());
        put.addColumn("info".getBytes(), "name".getBytes(), "jwolf".getBytes());
        put.addColumn("info".getBytes(), "age".getBytes(), "18".getBytes());
        conn.getTable(TableName.valueOf("person")).put(put);
        System.out.println("增加成功");

    }

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5706337.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存