我编写了一个简单的 HBase 客户端程序来在我的 HBase 集群(1 个主服务器和 3 个区域服务器)中执行 CRUD 操作。 Zookeeper实例仅在主服务器中运行,仲裁包括所有4台服务器。集群运行良好,可以使用YCSB客户端进行读/写(意味着服务器/zookeeper端没有任何问题)。
现在,在 eclipse 类路径中,我添加了所有 HBase 库和 hbase-0.94.7.jar(其中包含 hbase-default.xml 文件)。我还在项目中添加了集群中的原始 hbase-site.xml 文件。
最初,我使用未修改的 hbase-default.xml 运行客户端代码,我发现客户端正在尝试与 Zookeeper 实例的本地主机进行通信。从而忽略 hbase-site.xml。
然后我修改了保存Master/Zookpeer服务器公共(public)IP地址的3个参数并再次尝试。这次我收到以下错误,客户端不断尝试与 Zookeeper 及其其他仲裁成员连接。
我拥有 Zookeeper 仲裁中的所有 4 台服务器,假设它们的 IP 地址是:
W.W.W.W//HBase 主服务器和 Zookeeper 服务器
X.X.X.X//HBase RS 和 Zookeeper 仲裁成员
Y.Y.Y.Y//HBase RS 和 Zookeeper 仲裁成员
Z.Z.Z.Z//HBase RS 和 Zookeeper 仲裁成员
13/06/19 13:06:23 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=W.W.W.W:2181,X.X.X.X:2181,Y.Y.Y.Y:2181,Z.Z.Z.Z:2181 sessionTimeout=180000 watcher=hconnection 13/06/19 13:06:23 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is 5828@Kamal-VAIO 13/06/19 13:06:24 INFO zookeeper.ClientCnxn: Opening socket connection to server W.W.W.W:2181. Will not attempt to authenticate using SASL (unknown error) 13/06/19 13:06:25 WARN zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect java.net.ConnectException: Connection refused: no further information<小时/>
13/06/19 13:06:25 WARN zookeeper.RecoverableZooKeeper: Possibly transient ZooKeeper exception: org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hbase/hbaseid 13/06/19 13:06:25 INFO util.RetryCounter: Sleeping 2000ms before retry #1... 13/06/19 13:06:25 INFO zookeeper.ClientCnxn: Opening socket connection to server X.X.X.X:2181. Will not attempt to authenticate using SASL (unknown error) 13/06/19 13:06:26 WARN zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect java.net.ConnectException: Connection refused: no further information<小时/>
...等等
最佳答案
问题已解决。
解决方案:
- 右键单击 Eclipse 中的项目
- 转到“属性”
- 选择 Java 构建路径
- 前往图书馆
- 点击“添加类文件夹”
- 添加一个名为conf的新文件夹
- 按全部确定
- 将我的 hbase-site.xml 复制到 conf 文件夹中
- 还将我的 HBase 集群的 IP 主机列表添加到 Win 7 主机文件中并保存。
- 运行hbase代码,客户端可以成功连接Zookeeper和HBase master。
注意:第10步是必须的,否则客户端将从Zookeeper实例获取主机名并且无法解析它们。
非常感谢大家。
关于Java客户端无法连接Zookeeper和HBase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17184705/