分享

eclipse下通过java连hbase超时

韦伯 发表于 2017-12-26 09:23:17 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 1 6937
服务器hbase-site.xml配置如下:
<configuration>
  <property>
        <name>hbase.rootdir</name>  
        <value>hdfs://localhost:9000/hbase</value>   
    </property>
    <property>
        <name>hbase.cluster.distributed</name>
        <value>true</value>
    </property>
   
</configuration>
启动成功后通过hbase shell能插入表能操作。http://192.168.163.128:16010/master-status可以正常访问

etc/hosts 配置如下
127.0.0.1        localhost
127.0.1.1        hadoop-virtual-machine




客户端代码
  客户端host如下
127.0.1.1   hadoop-virtual-machine


    static {
        conf = HBaseConfiguration.create();
         // 设置Zookeeper,直接设置IP地址
        conf.set("hbase.zookeeper.quorum", "192.168.163.128");



        conf.set("hbase.zookeeper.property.clientPort", "2181");  
      

    }
    public static void createTable(String tableName, String[] family) {
        Admin admin;
        HTableDescriptor table;
        TableName t_name = TableName.valueOf(tableName);
        Connection connection = null;
        try {
            connection = ConnectionFactory.createConnection(conf);
            admin = connection.getAdmin();
            table = new HTableDescriptor(t_name);
            for (int i = 0; i < family.length; i++) {
                table.addFamily(new HColumnDescriptor(family));
            }
           if (admin.tableExists(t_name)) {
                System.out.println("Table Exists!!");
                System.exit(0);
            } else {
                admin.createTable(table);
               System.out.println("Create Table Success!!! Table Name :[ " + tableName + " ]");
            }
            admin.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (null != connection && !connection.isClosed()) {
                    connection.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
   
    报错如下

Caused by: java.net.SocketTimeoutException: callTimeout=60000, callDuration=76858: row 'test2,,' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=hadoop-virtual-machine,16201,1514190954917, seqNum=0
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:169)
at org.apache.hadoop.hbase.client.ResultBoundedCompletionService$QueueingFuture.run(ResultBoundedCompletionService.java:65)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
at org.apache.hadoop.net.SocketIOWithTimeout.connect(SocketIOWithTimeout.java:206)
at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:529)
at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:493)
at org.apache.hadoop.hbase.ipc.RpcClientImpl$Connection.setupConnection(RpcClientImpl.java:416)
at org.apache.hadoop.hbase.ipc.RpcClientImpl$Connection.setupIOstreams(RpcClientImpl.java:722)
at org.apache.hadoop.hbase.ipc.RpcClientImpl$Connection.writeRequest(RpcClientImpl.java:906)
at org.apache.hadoop.hbase.ipc.RpcClientImpl$Connection.tracedWriteRequest(RpcClientImpl.java:873)
at org.apache.hadoop.hbase.ipc.RpcClientImpl.call(RpcClientImpl.java:1241)
at org.apache.hadoop.hbase.ipc.AbstractRpcClient.callBlockingMethod(AbstractRpcClient.java:227)
at org.apache.hadoop.hbase.ipc.AbstractRpcClient$BlockingRpcChannelImplementation.callBlockingMethod(AbstractRpcClient.java:336)
at org.apache.hadoop.hbase.protobuf.generated.ClientProtos$ClientService$BlockingStub.scan(ClientProtos.java:34094)
at org.apache.hadoop.hbase.client.ScannerCallable.openScanner(ScannerCallable.java:400)
at org.apache.hadoop.hbase.client.ScannerCallable.call(ScannerCallable.java:204)
at org.apache.hadoop.hbase.client.ScannerCallable.call(ScannerCallable.java:65)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:210)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas$RetryingRPC.call(ScannerCallableWithReplicas.java:364)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas$RetryingRPC.call(ScannerCallableWithReplicas.java:338)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:136)
... 4 more

已有(1)人评论

跳转到指定楼层
desehawk 发表于 2017-12-26 09:42:17
127.0.1.1        hadoop-virtual-machine
把这个注释掉改成ip地址
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条