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

    如果有问题,请留言交流

  • 相关阅读:
    慕课网多物体运动源代码
    慕课网javascript动画特效 多透明度 源代码
    百度地图实时侦听鼠标滚轮获取地图zoom缩放级别
    百度地图自定义地图切片问题
    百度地图之多点步行路径连线问题
    百度地图利用数组实现多个标注点的显示
    理解clear: left/clear: right
    CSS3 Transform属性详解
    setInterval() 方法
    for Share
  • 原文地址:https://www.cnblogs.com/ljysy/p/9767502.html
Copyright © 2011-2022 走看看