Java连接hbase

454 阅读1分钟

1. 环境配置

  • 参考hbase伪分布式配置一文,启动hbase。

  • 在hbase服务器的/etc/hosts中,添加:

      10.100.10.46 postgresql
    

    前面是ip,后面的名字可以与你配置hbase的名字一致

  • 假如你在windows环境下开发,需要连接服务器上的hbase,则需要在本机system32中hosts也添加:

      10.100.10.46 postgresql	
      
    

2. java开发环境配置

  • pom.xml配置如下:

  • hbase连接:

      // 定义配置对象HBaseConfiguration
      private static Configuration configuration;
      public HbaseTest() throws Exception {
      	configuration = HBaseConfiguration.create();
      	configuration.set("hbase.zookeeper.quorum","10.100.10.46");  //hbase 服务地址
      	configuration.set("hbase.rootdir","hdfs://10.100.10.46:9000/hbase");
      	admin = new HBaseAdmin(configuration);
      }