无法连接到Vagrant上运行的HBase(Zookeeper)

时间:2017-03-28 14:11:14

标签: docker vagrant hbase apache-zookeeper vagrant-windows

我有简单的流浪汉机器,它在HBase上有一个独立的实例。当我启动hbase时,我可以访问hbase信息网址http://192.168.99.101:16010/master-status

但是当我尝试通过java连接时,我无法连接到Zookeeper。

Vagrant文​​件

accesBD.closeConnection(null)

VM上的主机文件类似于

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

hbase-site.xml看起来像

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

简单的测试代码看起来像

<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>

Hbase版本为hbase-1.1.9

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");

    }

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

1 个答案:

答案 0 :(得分:0)

显然这个问题有答案 Unable to connect to HBase stand alone server from windows remote client

问题是Zookeeper只能使用主机名而不是IP

进行连接

所以在我的Windows主机文件中我需要添加

192.168.99.101  hbasepmx        hbasepnx
192.168.99.101  hbase-vm        hbase-vm

在代码中,更改是,

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