无法连接到在vagrant上运行的hbase(zookeeper)

6ju8rftf  于 2021-06-10  发布在  Hbase
关注(0)|答案(1)|浏览(458)

我有一个简单的流浪者机器,它在hbase上有一个独立的示例。启动hbase时,我可以访问hbase信息urlhttp://192.168.99.101:16010/主状态。
但是当我尝试通过java连接时,我无法连接到zookeeper。
流浪档案

Vagrant.configure("2") do |config|
  config.vm.box = "hbase-phoenix"  # A simple HBase phoenix box
  config.vm.box_check_update = false
  config.vbguest.auto_update = false
  config.vm.define "hbase_pnx" do |hbase_pnx|
    hbase_pnx.vm.hostname = "hbasepnx"
    hbase_pnx.vm.network "private_network", ip: "192.168.99.101"
    hbase_pnx.vm.network "forwarded_port", guest: 2181, host: 2181
    hbase_pnx.vm.network "forwarded_port", guest: 16010, host: 16010
  end
end

vm上的主机文件如下所示

vagrant@hbasepnx:~$ cat /etc/hosts
192.168.99.101  hbasepmx        hbasepnx
192.168.99.101  hbase-vm        hbase-vm
192.168.99.101  localhost
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

hbase-site.xml看起来像

<configuration>
  <property>
    <name>hbase.rootdir</name>
    <value>file:///home/vagrant/data/hbase</value>
  </property>
  <property>
    <name>hbase.zookeeper.property.dataDir</name>
    <value>/home/vagrant/data/zookeeper</value>
  </property>
  <property>
    <name>hbase.cluster.distributed</name>
    <value>false</value>
  </property>
</configuration>

简单的测试代码

public void testHBaseCRUD() throws Exception {
        Configuration config = HBaseConfiguration.create();
        config.set("hbase.zookeeper.quorum", "192.168.99.101");
        config.set("hbase.zookeeper.property.clientPort", "2181");
        try (HTable htable = new HTable(config, tableName)) {
            int total = 100;
            long t1 = System.currentTimeMillis();
            for (int i = 0; i < total; i++) {
                int userid = i;
                String email = "user-" + i + "@foo.com";
                String phone = "555-1234";

                byte[] key = Bytes.toBytes(userid);
                Put put = new Put(key);

                put.add(Bytes.toBytes(familyName), Bytes.toBytes("FIRST_NAME"), Bytes.toBytes(email));  // <-- email goes here
                put.add(Bytes.toBytes(familyName), Bytes.toBytes("LAST_NAME"), Bytes.toBytes(phone));  // <-- phone goes here
                htable.put(put);

        }
        long t2 = System.currentTimeMillis();
        System.out.println("inserted " + total + " users  in " + (t2 - t1) + " ms");

    }

hbase版本为hbase-1.1.9

2017-03-28 10:06:01,422 INFO  [main-SendThread(192.168.99.101:2181)] zookeeper.ClientCnxn (ClientCnxn.java:primeConnection(852)) - Socket connection established to 192.168.99.101/192.168.99.101:2181, initiating session
2017-03-28 10:06:01,427 INFO  [main-SendThread(192.168.99.101:2181)] zookeeper.ClientCnxn (ClientCnxn.java:onConnected(1235)) - Session establishment complete on server 192.168.99.101/192.168.99.101:2181, sessionid = 0x15b1534b9900009, negotiated timeout = 40000
2017-03-28 10:06:50,084 INFO  [hconnection-0x4206a205-metaLookup-shared--pool2-t1] client.RpcRetryingCaller (RpcRetryingCaller.java:callWithRetries(142)) - Call exception, tries=10, retries=35, started=48438 ms ago, cancelled=false, msg=row 'user,    ,99999999999999' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=hbasepmx,37628,1490709431477, seqNum=0
2017-03-28 10:07:02,605 INFO  [hconnection-0x4206a205-metaLookup-shared--pool2-t1] client.RpcRetryingCaller (RpcRetryingCaller.java:callWithRetries(142)) - Call exception, tries=11, retries=35, started=60963 ms ago, cancelled=true, msg=row 'user,    ,99999999999999' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=hbasepmx,37628,1490709431477, seqNum=0
2017-03-28 10:07:48,168 INFO  [hconnection-0x4206a205-metaLookup-shared--pool2-t2] client.RpcRetryingCaller (RpcRetryingCaller.java:callWithRetries(142)) - Call exception, tries=10, retries=35, started=46421 ms ago, cancelled=false, msg=row 'user,    ,99999999999999' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=hbasepmx,37628,1490709431477, seqNum=0
2017-03-

任何帮助都将不胜感激。谢谢

5lhxktic

5lhxktic1#

显然,这个问题的答案是无法从windows远程客户端连接到hbase独立服务器
问题是zookeeper只使用主机名而不是ip连接
所以在我的windows主机文件中我需要添加

192.168.99.101  hbasepmx        hbasepnx
192.168.99.101  hbase-vm        hbase-vm

代码里的变化是,

config.set("hbase.zookeeper.quorum", "hbase-vm");

相关问题