2

我在具有 3 个 zookeeper 节点的 5 节点 Cloudera 集群上安装了 Phoenix。

我正在尝试从下面的 JDBC 程序运行一个基本的 SQL 命令,但我遇到了 zookeeper 错误。有人可以建议吗?

import java.sql.*;

public class PhoenixJDBC {

 public static void main(String args[]) {

 try {
     //Register JDBC Driver
     Class.forName("org.apache.phoenix.jdbc.PhoenixDriver").newInstance();

     Connection conn = DriverManager.getConnection("jdbc:phoenix:54.152.31.122","","");

     //Create a Statement class to execute the SQL statement
     Statement stmt = conn.createStatement();

     //Execute the SQL statement and get the results in a Resultset
     ResultSet rs = stmt.executeQuery("select * from US_POPULATION");

     // Iterate through the ResultSet, displaying two values
     // for each row using the getString method

     while (rs.next())
         System.out.println("Name= " + rs.getString("host"));
 }
 catch (SQLException e) {
     e.printStackTrace();
 }
 catch (Exception e) {
     e.printStackTrace();
 }
 }
 }

例外:

org.apache.phoenix.exception.PhoenixIOException: org.apache.hadoop.hbase.MasterNotRunningException: Can't get connection to ZooKeeper: KeeperErrorCode = ConnectionLoss for /hbase
     at org.apache.phoenix.util.ServerUtil.parseServerException(ServerUtil.java:108)
     at org.apache.phoenix.query.ConnectionQueryServicesImpl.ensureTableCreated(ConnectionQueryServicesImpl.java:832)
     at org.apache.phoenix.query.ConnectionQueryServicesImpl.createTable(ConnectionQueryServicesImpl.java:1126)
     at org.apache.phoenix.query.DelegateConnectionQueryServices.createTable(DelegateConnectionQueryServices.java:110)
     at org.apache.phoenix.schema.MetaDataClient.createTableInternal(MetaDataClient.java:1590)
     at org.apache.phoenix.schema.MetaDataClient.createTable(MetaDataClient.java:568)
     at org.apache.phoenix.compile.CreateTableCompiler$2.execute(CreateTableCompiler.java:175)
     at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:271)
     at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:263)
     at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
     at org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:261)
     at org.apache.phoenix.jdbc.PhoenixStatement.executeUpdate(PhoenixStatement.java:1043)
     at org.apache.phoenix.query.ConnectionQueryServicesImpl$9.call(ConnectionQueryServicesImpl.java:1551)
     at org.apache.phoenix.query.ConnectionQueryServicesImpl$9.call(ConnectionQueryServicesImpl.java:1520)
     at org.apache.phoenix.util.PhoenixContextExecutor.call(PhoenixContextExecutor.java:77)
     at org.apache.phoenix.query.ConnectionQueryServicesImpl.init(ConnectionQueryServicesImpl.java:1520)
     at org.apache.phoenix.jdbc.PhoenixDriver.getConnectionQueryServices(PhoenixDriver.java:162)
     at org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.connect(PhoenixEmbeddedDriver.java:126)
     at org.apache.phoenix.jdbc.PhoenixDriver.connect(PhoenixDriver.java:133)
     at java.sql.DriverManager.getConnection(Unknown Source)
     at java.sql.DriverManager.getConnection(Unknown Source)
     at mysqljbdctest.PhoenixJDBC.main(PhoenixJDBC.java:15)
Caused by: org.apache.hadoop.hbase.MasterNotRunningException: org.apache.hadoop.hbase.MasterNotRunningException: Can't get connection to ZooKeeper: KeeperErrorCode = ConnectionLoss for /hbase
     at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$StubMaker.makeStub(HConnectionManager.java:1651)
     at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(HConnectionManager.java:1677)
     at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getKeepAliveMasterService(HConnectionManager.java:1884)
     at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getHTableDescriptor(HConnectionManager.java:2671)
     at org.apache.hadoop.hbase.client.HBaseAdmin.getTableDescriptor(HBaseAdmin.java:397)
     at org.apache.hadoop.hbase.client.HBaseAdmin.getTableDescriptor(HBaseAdmin.java:402)
     at org.apache.phoenix.query.ConnectionQueryServicesImpl.ensureTableCreated(ConnectionQueryServicesImpl.java:764)
     ... 20 more
4

2 回答 2

3

从堆栈跟踪来看,HMaster 可能已关闭。

另外,您是否尝试过在您的 URL 中输入完整的 zookeeper 仲裁?像这样的东西:

jdbc:phoenix:54.152.31.122,54.152.31.123,54.152.31.124

我在 Amazon 上遇到了一个问题(你的集群在哪里?),内部和外部 IP 变得混乱,zookeeper 无法正确连接到 HBase。我解决了这个问题(不是最具可扩展性的解决方案,但它有效!)通过在集群中的机器上的 /etc/hosts 中创建指向内部 IP 地址的别名,然后在我的本地桌面上使用相同的别名但指向外部 IPs。然后,更改我的集群设置以在任何地方使用别名而不是 IP 地址。快速测试这是否是您的问题 - 构建您的应用程序,将其复制到集群中的一台服务器上,然后查看它是否可以在那里运行。

希望有帮助!

于 2015-02-23T16:35:33.677 回答
0

/hbase 是 Zookeeper 中的默认目录。您必须在 hbase-site.xml 中检查 hbase 在 Zookeeper 中保存的路径 - 可能是 /hbase-unsecure。

我们试试看

jdbc:phoenix:zk-host:port:path_on_zookeeper
于 2015-10-15T07:18:13.260 回答