1. 下载和安装cygwin(http://www.cygwin.com/)
2. 下载新的Zookeeper包和HBase包,我这里ZooKeeper版本为3.3.1,HBase版本为0.20.4
3. 把利用它们的源码包在Eclipse下生成2个独立的Project,注意:zookeeper工程,你要把那个conf目录加入到工程的src中去
4. 修改zookeeper工程下的conf目录中的zoo.cfg文件,例子如下:
tickTime=5000
# the directory where the snapshot is stored.
dataDir=D:/zookeeper-3.3.1/data
# the port at which the clients will connect
clientPort=2181
就是给zookeeper指定文件存放的地方以及端口
5.启动zookeeper
在Eclipse中新建一个Run config, main class为:org.apache.zookeeper.server.quorum.QuorumPeerMain
启动的程序参数为:D:/workspace/zookeeper3.3.1/conf/zoo.cfg(这个上面我们改动的东东啦,当然你可能不是这个路径)
启动的虚拟机参数为:
-Dzookeeper.log.dir=D:/workspace/zookeeper3.3.1/log
-Dzookeeper.root.logger=INFO,CONSOLE
如图所示:
好了,这样就可以在Eclipse中把ZooKeeper启动起来了。
6 修改HBase project中的一个类
org.apache.hadoop.hbase.LocalHBaseCluster
找到它的main函数,把main函数改成下
HBaseConfiguration conf = new HBaseConfiguration();
conf.set("hbase.zookeeper.quorum", "localhost");
conf.set("hbase.zookeeper.property.clientPort", "2181");
LocalHBaseCluster cluster = new LocalHBaseCluster(conf,1);
cluster.startup();
}
注意红色那行: LocalHBaseCluster cluster = new LocalHBaseCluster(conf,1); 构造函数中的1是代表Region server的个数,在这里我只想起一个region server.
7 修改HBase的配置文件
在HBase project下的src中你可以看到hbase-default.xml和hbase-site.xml两个文件,你改哪个都可以。我是直接在
hbase-default.xml改的,重要的是下面3个属性hbase.rootdir,hbase.cluster.distributed,hbase.tmp.dir,
我把hbase.rootdir,hbase.tmp.dir都指向了本地的目录,你当然可以根据自己的需要调整,当然你格式一定像我一样写哦。
<name>hbase.rootdir</name>
<value> file:///D:/hbase-0.20.3/data </value>
<description>The directory shared by region servers.
Should be fully-qualified to include the filesystem to use.
E.g: hdfs://NAMENODE_SERVER:PORT/HBASE_ROOTDIR
</description>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value> false </value>
<description>The mode the cluster will be in. Possible values are
false: standalone and pseudo-distributed setups with managed Zookeeper
true: fully-distributed with unmanaged Zookeeper Quorum (see hbase-env.sh)
</description>
</property>
<property>
<name>hbase.tmp.dir</name>
<value> D:/hbase-0.20.3/tmp </value>
<description>Temporary directory on the local filesystem.</description>
</property>
<property>
8 启动HBase,简单,直接run org.apache.hadoop.hbase.LocalHBaseCluster就可以了,run config不需要 没有什么别的配置。当然就也可以debug了。
9 比较重要的说明: 如果你不修改Hbase工程源码中的hbase-default.xml或者hbase-site.xml的话,你在调试的过程中会经常碰到诸如:频繁的扫描-META-表,HBase Client端超时等等,非常不利于你调试的,所以你要修改hbase-default.xml或者hbase-site.xml,将一些参数调整下。我这里比较懒,我是直接修改了hbase-default.xml了,你改hbase-site.xml也可以,你改hbase-site.xml其实是相当于"override" hbase-default.xml中的默认配置。好吧,我把我自己修改好的hbase-default.xml直接发上来,我这样改过后,在调试中没有出现什么不爽的情况。