zoukankan      html  css  js  c++  java
  • java API连接虚拟机上的hbase

    今天用本地的eclipse连接虚拟机上的hbase数据库,代码如下:

    public static void main(String[] args) throws Exception{
    			Configuration conf = HBaseConfiguration.create();
    			//conf.set("fs.defaultFS", "hdfs://192.168.252.200:9000/");
    			//conf.set("hbase.master", "192.168.252.200");
    			conf.set("hbase.zookeeper.quorum","192.168.252.200:2181,192.168.252.201:2181,192.168.252.202:2181");
    			conf.set("hbase.zookeeper.property.clientPort", "2181");
    			@SuppressWarnings({ "resource", "deprecation" })
    			HBaseAdmin admin = new HBaseAdmin(conf); 
    			
    			 System.out.println(1);
    			TableName name = TableName.valueOf("nvshen");
    			HTableDescriptor desc = new HTableDescriptor(name);
    			 System.out.println(2);
    			HColumnDescriptor base_info = new HColumnDescriptor("base_info");
    			HColumnDescriptor extra_info = new HColumnDescriptor("extra_info");
    			base_info.setMaxVersions(5);
    			extra_info.setMaxVersions(5);
    			System.out.println(3);
    			desc.addFamily(base_info);
    			desc.addFamily(extra_info);
    			System.out.println(4);
    			admin.createTable(desc);
    			System.out.println("创建完成");
    		}
    

     我虚拟机上用的是自己搭建的zookeeper集群

    然后在运行代码时,总是卡在最后的创建上,而且程序也不终止,也不提示任何信息,让人很是头疼,但是过了很长一段时间之后eclipse就会报错了,这要是没有一点耐心根本发现不了会报错,大致错误如下:

    xception in thread "main" org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=35, exceptions:
    Tue Sep 12 11:25:29 CST 2017, RpcRetryingCaller{globalStartTime=1505186727016, pause=100, retries=35}, org.apache.hadoop.hbase.MasterNotRunningException: java.net.UnknownHostException: web2.2ge.cn
    Tue Sep 12 11:25:29 CST 2017, RpcRetryingCaller{globalStartTime=1505186727016, pause=100, retries=35}, org.apache.hadoop.hbase.MasterNotRunningException: java.net.UnknownHostException: web2.2ge.cn
    Tue Sep 12 11:25:29 CST 2017, RpcRetryingCaller{globalStartTime=1505186727016, pause=100, retries=35}, org.apache.hadoop.hbase.MasterNotRunningException: java.net.UnknownHostException: web2.2ge.cn
    Tue Sep 12 11:25:30 CST 2017, RpcRetryingCaller{globalStartTime=1505186727016, pause=100, retries=35}, org.apache.hadoop.hbase.MasterNotRunningException: java.net.UnknownHostException: web2.2ge.cn
    Tue Sep 12 11:25:30 CST 2017, RpcRetryingCaller{globalStartTime=1505186727016, pause=100, retries=35}, org.apache.hadoop.hbase.MasterNotRunningException: java.net.UnknownHostException: web2.2ge.cn
    at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:157)
    

     经过百度搜索之后,应该在C:WindowsSystem32driversetchosts目录下加上虚拟机上的地址映射关系,即虚拟上的 /etc/hosts文件中配置Hadoop时添加的东西,将其复制到本地的C:WindowsSystem32driversetchosts,然后保存,再次运行就可以执行成功了

    在第一次编辑C:WindowsSystem32driversetchosts文件时会显示权限不够,这时候需要先对该文件进行一些权限的设置,详细内容见一下地址:

    https://jingyan.baidu.com/article/624e7459b194f134e8ba5a8e.html

    如果有问题,请留言交流

  • 相关阅读:
    codeforces 407B Long Path
    CodeForces 489C Given Length and Sum of Digits...
    hacker cup 2015 Round 1 解题报告
    hacker cup 2015 资格赛
    Codeforces 486(#277 Div 2) 解题报告
    POJ 3468 A Simple Problem with Integers splay
    Codeforces 484(#276 Div 1) D Kindergarten DP
    求平均值问题201308031210.txt
    I love this game201308022009.txt
    QQ
  • 原文地址:https://www.cnblogs.com/ljysy/p/9767502.html
Copyright © 2011-2022 走看看