gpt4 book ai didi

java - 无法通过Java连接到Hbase

转载 作者:可可西里 更新时间:2023-11-01 16:41:38 26 4
gpt4 key购买 nike

我正在尝试从 Java 连接到 Hbase。 Hbase-版本 1.0.0但我无法连接它。请告诉我我缺少什么,因为我是 Hbase 的新手。这是我的代码

public class HbaseAddRetrieveData{
public static void main(String[] args) throws IOException {
TableName tableName = TableName.valueOf("stock-prices");


Configuration conf = HBaseConfiguration.create();
conf.set("hbase.master","LocalHost:60000");
conf.set("hbase.zookeeper.property.clientPort", "2181");
conf.set("hbase.zookeeper.quorum", "LocalHost");
conf.set("zookeeper.znode.parent", "/hbase-unsecure");
System.out.println("Config set");
Connection conn = ConnectionFactory.createConnection(conf);
System.out.println("Connection");
Admin admin = conn.getAdmin();
if (!admin.tableExists(tableName)) {
System.out.println("In admin");
admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor("cf")));
}

Table table = conn.getTable(tableName);
Put p = new Put(Bytes.toBytes("AAPL10232015"));
p.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("close"), Bytes.toBytes(119));
table.put(p);

Result r = table.get(new Get(Bytes.toBytes("AAPL10232015")));
System.out.println(r);
}

下面是我面临的错误:

Exception in thread "main" org.apache.hadoop.hbase.client.RetriesExhaustedException: Can't get the locations
at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations(RpcRetryingCallerWithReadReplicas.java:305)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:131)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:56)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:200)
at org.apache.hadoop.hbase.client.ClientScanner.call(ClientScanner.java:287)
at org.apache.hadoop.hbase.client.ClientScanner.nextScanner(ClientScanner.java:267)
at org.apache.hadoop.hbase.client.ClientScanner.initializeScannerInConstruction(ClientScanner.java:139)
at org.apache.hadoop.hbase.client.ClientScanner.<init>(ClientScanner.java:134)
at org.apache.hadoop.hbase.client.HTable.getScanner(HTable.java:823)
at org.apache.hadoop.hbase.MetaTableAccessor.fullScan(MetaTableAccessor.java:601)
at org.apache.hadoop.hbase.MetaTableAccessor.tableExists(MetaTableAccessor.java:365)
at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:281)
at com.tcs.healthcare.HbaseRetrieveData.main(HbaseRetrieveData.java:32)

请指导我完成这个

最佳答案

将本地主机中的 L 更改为 l 并将 'H' 更改为 'h'

Configuration conf = HBaseConfiguration.create();
conf.set("hbase.master","localhost:60000");
conf.set("hbase.zookeeper.property.clientPort", "2181");
conf.set("hbase.zookeeper.quorum", "localhost");
conf.set("zookeeper.znode.parent", "/hbase-unsecure");

如果你使用的是远程机器,那么 conf.set("hbase.master","re​​motehost:60000");即使它不工作然后你检查类路径中的所有 jar (远程)

如果您使用的是 Maven,您可以指向集群中的 jars。

您可以转到集群并检查以下命令以了解远程计算机中的 jars 版本。

`hbase classpath`

您的客户端计算机中应该有相同版本的 jar。对于远程计算机中的 ex hbasex.jar,而您正在使用 hbasey.jar,则它无法连接。

此外,请从客户端机器检查您是否能够 ping 服务器/集群。一般会有防火墙限制。

关于java - 无法通过Java连接到Hbase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40588459/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com