hbase安装部署

下载hbase-0.94.12.tar.gz并解压

一、本地模式

编辑conf/hbase-site.xml,添加hbase.rootdir, 不是hbase.root.dir

<?xml version="1.0"?>  
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  
<configuration>  
  <property>  
    <name>hbase.rootdir</name>  
    <value>file:////data/hbase</value>  
  </property>  
</configuration>


然后启动

$ ./bin/start-hbase.sh
starting Master, logging to logs/hbase-user-master-example.org.out
就可以使用hbase了。

二、集群模式

前提是hadoop集群已经安装成功。
我这里有三台机器:master,slave1,slave2
1、首先要把master的id_rsa.pub拷贝到salve1和slave2的authorized_keys中,这样master可以免密码和两台salve进行通信。
2、设置hosts,把三台机器的ip互相配置好
3、三台机器的时间要差不多,否则会出现奇怪的问题(我就遇到一台regionserver一直起不来,看日志才发现是机器的时间不对)。设置集群各个节点时钟:date -s “2012-02-13 14:00:00”。
master上修改hbase的配置文件
4、修改conf/hbase-env.sh中的JAVA_HOME,把JAVA_HOME改成机器上的JAVA_HOME路径,不设置会有问题。
export HBASE_MANAGES_ZK=true:默认是true, 即hbase托管zookeep。一个分布式运行的Hbase依赖一个zookeeper集群,所有的节点和客户端都必须能够访问zookeeper,默认的情况下Hbase会管理一个zookeep集群,这个集群会随着Hbase的启动而启动。
当为false时就是让Hbase使用一个独立的Zookeep集群。
5、修改conf/hbase-site.xml
<property>
      <name>hbase.rootdir</name>
      <value>hdfs://test01:9000/hbase</value>
    </property>
    <property>
      <name>hbase.cluster.distributed</name>
      <value>true</value>
    </property>
    <property>
      <name>hbase.zookeeper.property.clientPort</name>
      <value>2222</value>
      <description>Property fromZooKeeper's config zoo.cfg.
      The port at which the clients willconnect.
      </description>
    </property>
    <property>
      <name>hbase.zookeeper.quorum</name>
      <value>test02,test03</value>
      <description>Comma separated listof servers in the ZooKeeper Quorum.
      For example,"host1.mydomain.com,host2.mydomain.com,host3.mydomain.com".
      By default this is set to localhost forlocal and pseudo-distributed modes
      of operation. For a fully-distributedsetup, this should be set to a full
      list of ZooKeeper quorum servers. IfHBASE_MANAGES_ZK is set in hbase-env.sh
      this is the list of servers which we willstart/stop ZooKeeper on.
      </description>
    </property>
<property>
      <name>hbase.zookeeper.property.dataDir</name>
      <value>/data/hbase/zookeeper</value>
      <description>Property fromZooKeeper's config zoo.cfg.
      The directory where the snapshot isstored.
      </description>
    </property>
参数说明:
hbase.rootdir: regionserver的共享目录,用于存储数据。即HDFS的NameNode的位置
hbase.cluster.distributed:Hbase的运行模式。false是单机模式(默认),true是分布式模式。若为false,Hbase和Zookeeper会运行在同一个JVM里面。
配置zookeeper:

hbase.zookeeper.property.clientPort:ZooKeeper的zoo.conf中的配置。 客户端连接的端口。

hbase.zookeeper.quorum:Zookeeper集群的地址列表,用逗号分割。默认是localhost,是给伪分布式用的。要修改才能在完全分布式的情况下使用。如果在hbase-env.sh设置了HBASE_MANAGES_ZK,这些ZooKeeper节点就会和Hbase一起启动。

注意:运行一个zookeeper也是可以的,但是在生产环境中,你最好部署3,5,7个节点。部署的越多,可靠性就越高,当然只能部署奇数个,偶数个是不可以的。你需要给每个zookeeper 1G左右的内存,如果可能的话,最好有独立的磁盘。 (独立磁盘可以确保zookeeper是高性能的。).如果你的集群负载很重,不要把Zookeeper和RegionServer运行在同一台机器上面。就像DataNodes 和 TaskTrackers一样

hbase.zookeeper.property.dataDir:ZooKeeper的zoo.conf中的配置。 快照的存储位置。默认值是 /tmp (重启会被删除),最好还是修改下。

6、配置conf/regionservers,在里面加入作为regionserver的机器名称,我这里是slave1和slave2(一行1个)。列在这里的server会随着集群的启动而启动,集群的停止而停止
7、替换hbase lib中的hadoop_core.jar, 需要所用的hadoop集群对应的hadoop core。要替换成所用hadoop集群对应的hadoop版本的core。否则会报:
java.io.IOException: Call to test01/192.168.2.169:9000 failed on local exception: java.io.EOFException
	at org.apache.hadoop.ipc.Client.wrapException(Client.java:775)
	at org.apache.hadoop.ipc.Client.call(Client.java:743)
	at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:220)
	at com.sun.proxy.$Proxy9.getProtocolVersion(Unknown Source)
	at org.apache.hadoop.ipc.RPC.getProxy(RPC.java:359)
	at org.apache.hadoop.hdfs.DFSClient.createRPCNamenode(DFSClient.java:106)
	at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:207)
	at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:170)
	at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:82)
	at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1378)
	at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:66)
	at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1390)
	at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:196)
	at org.apache.hadoop.fs.Path.getFileSystem(Path.java:175)
	at org.apache.hadoop.hbase.util.FSUtils.getRootDir(FSUtils.java:666)
	at org.apache.hadoop.hbase.master.MasterFileSystem.<init>(MasterFileSystem.java:112)
	at org.apache.hadoop.hbase.master.HMaster.finishInitialization(HMaster.java:571)
	at org.apache.hadoop.hbase.master.HMaster.run(HMaster.java:430)
	at java.lang.Thread.run(Thread.java:662)
Caused by: java.io.EOFException
	at java.io.DataInputStream.readInt(DataInputStream.java:375)
	at org.apache.hadoop.ipc.Client$Connection.receiveResponse(Client.java:501)
	at org.apache.hadoop.ipc.Client$Connection.run(Client.java:446)
8、将master上的hbase文件夹拷贝到slave1和slave2
9、运行master上的./bin/start-hbase.sh来运行集群,成功如下所示:
slave1: starting zookeeper, logging to /root/software/hbase-0.94.12/bin/../logs/hbase-root-zookeeper-slave1.out
slave2: starting zookeeper, logging to /root/software/hbase-0.94.12/bin/../logs/hbase-root-zookeeper-slave2.out
starting master, logging to /root/software/hbase-0.94.12/logs/hbase-root-master-master.out
Listening for transport dt_socket at address: 10444
slave2: starting regionserver, logging to /root/software/hbase-0.94.12/bin/../logs/hbase-root-regionserver-slave2.out
slave1: starting regionserver, logging to /root/software/hbase-0.94.12/bin/../logs/hbase-root-regionserver-slave1.out
其中Master中的jps:
23673 HMaster
1486 Bootstrap
24220 Jps
两台slave中的jps都是:
2658 TaskTracker
1713 HQuorumPeer
2905 Jps
1794 HRegionServer
2571 DataNode
查看管理页面: http://master:60010
PBUF版本不同的异常,导致hmaster启动不了。
java.lang.IllegalArgumentException: PBUF
	at org.apache.hadoop.hbase.zookeeper.ZKTableReadOnly.getTableState(ZKTableReadOnly.java:152)
	at org.apache.hadoop.hbase.zookeeper.ZKTable.getTableState(ZKTable.java:109)
	at org.apache.hadoop.hbase.zookeeper.ZKTable.populateTableStates(ZKTable.java:94)
	at org.apache.hadoop.hbase.zookeeper.ZKTable.<init>(ZKTable.java:80)
	at org.apache.hadoop.hbase.master.AssignmentManager.<init>(AssignmentManager.java:223)
	at org.apache.hadoop.hbase.master.HMaster.initializeZKBasedSystemTrackers(HMaster.java:503)
	at org.apache.hadoop.hbase.master.HMaster.finishInitialization(HMaster.java:587)
	at org.apache.hadoop.hbase.master.HMaster.run(HMaster.java:430)
	at java.lang.Thread.run(Thread.java:662)
2014-01-10 17:37:17,580 INFO org.apache.hadoop.hbase.master.HMaster: Aborting
原因是hbase-site.xml中配置的zookeeper信息:hbase.zookeeper.property.dataDir。 之前是其他版本的hbase造成PBUF版本不一致。解决方法是删除master和regionserver上的hbase.zookeeper.property.dataDir对应的内容。
0.96版的安装
0.96版和0.94安装方法一样,但需要hadoop-2.x。 
hbase 0.96依赖的lib中全是hadoop-2.1.0-beta的jar包,所以使用Hadoop-2.1.0-beta就行。
我一开始使用的是hadoop-2.2.0,然后HMaster老是无法启动,异常是:
Unhandled exception. Starting shutdown.
org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.ipc.RpcServerException):
Unknown out of band call #-2147483647
网上一搜是因为hbase中依赖的全是hadoop-2.1.0-beta的jar包,所以我把里面的jar包全换成hadoop-2.2.0的,但hadoop-client.2.2.0.jar包找不到(不用它时报找不到org.apache.hadoop.util.PlatformNam),网上说是要自己编译源码,好麻烦,所以还是使用haooop-2.1.0。
使用hadoop-2.1.0后HMaster还是启不起来,再看异常
org.apache.zookeeper.KeeperException$DataInconsistencyException: KeeperErrorCode = DataInconsistency
	at org.apache.hadoop.hbase.zookeeper.ZKUtil.convert(ZKUtil.java:1851)
	at org.apache.hadoop.hbase.zookeeper.ZKTableReadOnly.getTableState(ZKTableReadOnly.java:164)
	at org.apache.hadoop.hbase.zookeeper.ZKTable.populateTableStates(ZKTable.java:83)
	at org.apache.hadoop.hbase.zookeeper.ZKTable.<init>(ZKTable.java:69)
	at org.apache.hadoop.hbase.master.AssignmentManager.<init>(AssignmentManager.java:281)
	at org.apache.hadoop.hbase.master.HMaster.initializeZKBasedSystemTrackers(HMaster.java:677)
	at org.apache.hadoop.hbase.master.HMaster.finishInitialization(HMaster.java:809)
	at org.apache.hadoop.hbase.master.HMaster.run(HMaster.java:603)
	at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.hadoop.hbase.exceptions.DeserializationException: Missing pb magic PBUF prefix
	at org.apache.hadoop.hbase.protobuf.ProtobufUtil.expectPBMagicPrefix(ProtobufUtil.java:210)
	at org.apache.hadoop.hbase.zookeeper.ZKTableReadOnly.getTableState(ZKTableReadOnly.java:154)
	... 7 more
原来是以前装的是hbase-0.94.12的zookeeper中有数据(在zookeeper机器上),0.96和0.94的数据结构不一样,导致序列化/反序列化失败,删除旧数据后,重跑hbase,一切搞定。

相关推荐