尝试使用 java 连接远程服务器中的 HBase 时出现连接问题

Connection issue when trying to connect HBase in remote server using java

我尝试使用 java 连接远程服务器中的 HBase。下面是我的 java 代码

String zookeeperHost = "myserverIP";
String tableName = "User";

Configuration hconfig = HBaseConfiguration.create();
hconfig.setInt("timeout", 1200);
hconfig.set("hbase.zookeeper.quorum",zookeeperHost);
hconfig.set("hbase.zookeeper.property.clientPort", "2181");
TableName tname = TableName.valueOf(tableName);

try {
    HBaseAdmin.checkHBaseAvailable(hconfig);
} catch (ServiceException e) {
    e.printStackTrace();
}

HTableDescriptor htable = new HTableDescriptor(tname);
htable.addFamily( new HColumnDescriptor("Id"));
htable.addFamily( new HColumnDescriptor("Name"));
System.out.println( "Connecting..." );
Connection connection = ConnectionFactory.createConnection(hconfig);
HBaseAdmin hbase_admin = (HBaseAdmin)connection.getAdmin();
System.out.println( "Creating Table..." );
hbase_admin.createTable( htable );
System.out.println("Done!");

但我一直收到此异常

org.apache.hadoop.hbase.MasterNotRunningException:

com.google.protobuf.ServiceException: java.net.ConnectException: Connection >refused: no further information

我该如何解决这个问题?

在下面添加'hconfig'

 hconfig.set("hbase.master", hbaseConnectionIpAddr);
 hconfig.set("hbase.master.port", hbaseConnectionPortNum);

以下异常可能有两个原因

org.apache.hadoop.hbase.MasterNotRunningException

  1. 客户端计算机无法访问远程 VM hostname/IP。为了解决这个问题,您需要更新入站规则以允许端口访问。如果是 VM 主机名,请确保已在 /etc/hosts 中添加条目以使用 IP 地址解析主机名。

  2. 第二个问题可能是 HBase master 是 运行。确保 HMaster 服务是否来自您的远程服务器 运行。