我正在尝试将数据插入hbase。我正在从远程计算机运行Java程序。我已经在下面提到了代码。
try {
Configuration conf = HBaseConfiguration.create();
conf.clear();
conf.set("hbase.zookeeper.quorum", "<HOST_IP>:2181");
conf.set("hbase.zookeeper.property.clientPort", "2181");
conf.set("hbase.zookeeper.dns.nameserver", "<HOST_IP>");
conf.set("hbase.regionserver.port","60020");
conf.set("hbase.master", "<HOST_IP>:9000");
HTable table = new HTable(conf, "test");
Put put = new Put(Bytes.toBytes("row5"));
put.add(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"),
Bytes.toBytes("val1"));
put.add(Bytes.toBytes("colfam1"), Bytes.toBytes("qual2"),
Bytes.toBytes("val2"));
table.put(put);
} catch (MasterNotRunningException e) {
e.printStackTrace();
} catch (ZooKeeperConnectionException e) {
e.printStackTrace();
} catch (TableNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
我收到以下错误
INFO ipc.HbaseRPC: Server at localhost/127.0.0.1:60020 could not be reached after 1 tries, giving up.
org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed setting up proxy interface org.apache.hadoop.hbase.ipc.HRegionInterface to localhost/127.0.0.1:60020 after attempts=1
at org.apache.hadoop.hbase.ipc.HBaseRPC.waitForProxy(HBaseRPC.java:355)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getHRegionConnection(HConnectionManager.java:1176)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getHRegionConnection(HConnectionManager.java:1195)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegionInMeta(HConnectionManager.java:898)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:797)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.relocateRegion(HConnectionManager.java:772)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegionInMeta(HConnectionManager.java:1002)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:801)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:766)
at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:189)
at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:163)
at com.tcs.hbase.HbaseSample.insertData(HbaseSample.java:30)
at com.tcs.hbase.HbaseSample.main(HbaseSample.java:82)
Caused by: java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
at org.apache.hadoop.net.SocketIOWithTimeout.connect(SocketIOWithTimeout.java:206)
at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:406)
at org.apache.hadoop.hbase.ipc.HBaseClient$Connection.setupIOstreams(HBaseClient.java:328)
at org.apache.hadoop.hbase.ipc.HBaseClient.getConnection(HBaseClient.java:883)
at org.apache.hadoop.hbase.ipc.HBaseClient.call(HBaseClient.java:750)
at org.apache.hadoop.hbase.ipc.HBaseRPC$Invoker.invoke(HBaseRPC.java:257)
at $Proxy4.getProtocolVersion(Unknown Source)
at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:419)
at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:393)
at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:444)
at org.apache.hadoop.hbase.ipc.HBaseRPC.waitForProxy(HBaseRPC.java:349)
... 12 more
当我在安装hbase的计算机上运行相同的代码时,它的工作原理很好..从日志中可以清楚地看到rpc正在解析为localhost ip。我想知道如何将rpc ip配置为安装了hbase的计算机的ip。
最佳答案
此问题的根本原因在于/ etc / hosts文件中。如果您检查/ etc / hosts文件,您将找到类似于以下内容的条目(在我的情况下,mu机器被命名为domainnameyouwanttogive)
127.0.0.1本地主机
127.0.1.1域名youwanttogive
以下行对于支持IPv6的主机是理想的
:: 1 ip6-localhost ip6-loopback
fe00 :: 0 ip6-localnet
ff00 :: 0 ip6-mcastprefix
ff02 :: 1 ip6-allnodes
ff02 :: 2 ip6-allrouters
根本原因是,youwanttogive域名解析为127.0.1.1,这是不正确的,因为它应该解析为127.0.0.1(或外部IP)。由于我的外部IP为192.168.58.10,因此创建了以下/ etc / hosts配置;
127.0.0.1本地主机
192.168.43.3域名youwanttogive
以下行对于支持IPv6的主机是理想的
:: 1 ip6-localhost ip6-loopback
fe00 :: 0 ip6-localnet
ff00 :: 0 ip6-mcastprefix
ff02 :: 1 ip6-allnodes
ff02 :: 2 ip6-allrouters
这将确保在本地主机上正确完成主机进程的解析,并且可以在开发系统上正确启动HBase安装。
关于java - Hadoop和Hbase Java客户端.. HbaseRPC的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14373517/