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

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

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

stream浪文件

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> 

简单的testing代码看起来像

 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- 

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

显然这个问题有一个答案在无法连接到HBase独立的服务器从Windows远程客户端

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

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

 192.168.99.101 hbasepmx hbasepnx 192.168.99.101 hbase-vm hbase-vm 

而在代码中的变化是,

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