eclipse 远程接入vmware中的hbase

hadoop和hbase都部署在linux下,但是我们习惯在windows下使用eclipse编写java,所以就有了这个蛋疼的事情
环境:windows7 eclipse hbase-0.92.0
1、把需要用到的jar导入
需要的jar可以在linux下的HADOOP_HOME/lib和HBASE_HOME/lib下找到,需要的jar包如下:
eclipse 远程接入vmware中的hbase_第1张图片
2、配置文件hbase-site.xml:
<configuration>
        <property>
                <name>hbase.rootdir</name>
                <value>hdfs://192.168.1.128:9000/hbase</value>
        </property>
        <property>
                <name>hbase.cluster.distributed</name>
                <value>true</value>
        </property>
        <property>
                <name>hbase.master</name>
                <value>192.168.1.128:60000</value>
        </property>
        <property>
                <name>hbase.zookeeper.quorum</name>
                <value>192.168.1.128</value>
        </property>
        <property>
                <name>zookeeper.session.timeout</name>
                <value>60000</value>
        </property>
        <property>
                <name>hbase.zookeeper.prpperty.clientPort</name>
                <value>2181</value>
        </property>
</configuration>
3、测试函数:
public static void main(String[] args) throws IOException {



                  Configuration conf = HBaseConfiguration.create(); HTable table = new
                  HTable(conf, "testtable"); Put put = new Put(Bytes.toBytes("row1"));
                  put.add(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"),
                  Bytes.toBytes("val1")); put.add(Bytes.toBytes("colfam1"),
                  Bytes.toBytes("qual2"), Bytes.toBytes("val2")); table.put(put);
                 table.close();

}
中间遇到一个exception:
13/01/07 09:10:34 INFO client.HConnectionManager$HConnectionImplementation: getMaster attempt 0 of 10 failed; retrying after sleep of 1000
java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:574)
at org.apache.hadoop.net.SocketIOWithTimeout.connect(SocketIOWithTimeout.java:206)
at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:373)
at org.apache.hadoop.hbase.ipc.HBaseClient$Connection.setupConnection(HBaseClient.java:328)
at org.apache.hadoop.hbase.ipc.HBaseClient$Connection.setupIOstreams(HBaseClient.java:362)
at org.apache.hadoop.hbase.ipc.HBaseClient.getConnection(HBaseClient.java:1026)
at org.apache.hadoop.hbase.ipc.HBaseClient.call(HBaseClient.java:878)
at org.apache.hadoop.hbase.ipc.WritableRpcEngine$Invoker.invoke(WritableRpcEngine.java:150)
at $Proxy4.getProtocolVersion(Unknown Source)
at org.apache.hadoop.hbase.ipc.WritableRpcEngine.getProxy(WritableRpcEngine.java:183)
at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:303)
at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:280)
at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:332)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getMaster(HConnectionManager.java:642)
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:106)
at test.HBaseHelper.<init>(HBaseHelper.java:24)
at test.HBaseHelper.getHelper(HBaseHelper.java:28)
at test.PutExample.main(PutExample.java:17)

解决:
源码中org.apache.hadoop.hbase.HconnectionManager这个类里面
eclipse 远程接入vmware中的hbase_第2张图片
这个isa无论你在hbase-site.xml是否有设置
<property>
<name>hbase.master</name>
<value>192.168.1.128:60000</value>
</property>
取值都是你外网的地址xxx.xxx.xxx.xxx:60000,有时候没有联网时是127.0.0.1:60000,(bug)为此吧windows的C:\Windows\System32\drivers\etc的hosts文件加上一句:
192.168.1.128 localhost.localdomain localhost
原理:client要连接虚拟机的HMaster,HMaster的端口在虚拟机中hbase设置时60000,client首先通过${hbase.ip}:2181端口和hbase通信,hbase返回HMaster所在的机子的hostname(hbase是为集群设置的,对hosts很敏感),虚拟机中的hostname是localhost.localdomain,因此isa通过sn( ServerName sn )取到ip地址,因此需要在hosts设置HMaster所在的主机hostname的ip

4、查看结果:
在hbase shell下:
hbase(main):003:0> scan 'testtable'
ROW COLUMN+CELL
row1 column=colfam1:qual1, timestamp=1300108258094, value=val1
row2 column=colfam1:qual1, timestamp=1300108258094, value=val2
插入成功





你可能感兴趣的:(vmware,eclipse,hbase)