服务器 节点分布图

hbase 必须zookeeper hbase需要依赖hadoop吗_hbase

HBase完全分布式模式

hbase 完全分布式搭架之前,保证hadoop集群上做HDFS 确认是运行着的,hadoop的集群搭建参考

  • 下载解压最新版本:

HBase下载地址 :http://archive.apache.org/dist/hbase/ 点击stable目录选择不同版本,然后下载后缀为 .tar.gz 的文件; 例如 hbase-0.98.9-hadoop2-bin.tar.gz,解压缩,然后解压到指定的目录.

# tar -zxvf hbase-0.98.9-hadoop2-bin.tar.gz -C /usr/local
  • 修改文件 conf/hbase-env.sh

如果你在命令行键入java有反应说明你安装了Java。如果没有装,你需要先安装,然后编辑conf/hbase-env.sh,将其中的JAVA_HOME指向到你Java的安装目录。

# vi conf/hbase-env.sh

hbase 必须zookeeper hbase需要依赖hadoop吗_分布式_02

  • 修改配置文件 conf/hbase-site.xml

要想运行完全分布式模式,你要进行如下配置,先在 hbase-site.xml, 加一个属性 hbase.cluster.distributed 设置为 true 然后把 hbase.rootdir 设置为HDFS的NameNode的位置。 例如,你的namenode运行在namenode.example.org,端口是9000 你期望的目录是 /hbase,使用如下的配置

<configuration>
  <property>
    <name>hbase.rootdir</name>
    <value>hdfs://bjsxt/hbase</value>
    <description>The directory shared by RegionServers.
    </description>
  </property>
  <property>
    <name>hbase.cluster.distributed</name>
    <value>true</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>
</configuration>

hbase 必须zookeeper hbase需要依赖hadoop吗_hbase_03

  • 修改配置文件 conf/regionservers

完全分布式模式的还需要修改conf/regionservers, 列出了你希望运行的全部 HRegionServer,一行写一个host (就像Hadoop里面的 slaves 一样). 列在这里的server会随着集群的启动而启动,集群的停止而停止.

# vi conf/regionservers

hbase 必须zookeeper hbase需要依赖hadoop吗_centos_04

- ZooKeeper 和 HBase

一个分布式运行的HBase依赖一个zookeeper集群。所有的节点和客户端都必须能够访问zookeeper。默认的情况下HBase会管理一个zookeep集群。这个集群会随着HBase的启动而启动。当然,你也可以自己管理一个zookeeper集群,但需要配置HBase。你需要修改conf/hbase-env.sh里面的HBASE_MANAGES_ZK 来切换。这个值默认是true的,作用是让HBase启动的时候同时也启动zookeeper 。这里我们自己管理zookeeper

  • 修改配置文件 conf/hbase-env.sh
# vi conf/hbase-env.sh

hbase 必须zookeeper hbase需要依赖hadoop吗_hadoop_05

当HBase管理zookeeper的时候,你可以通过修改zoo.cfg来配置zookeeper,一个更加简单的方法是在 conf/hbase-site.xml里面修改zookeeper的配置。Zookeep的配置是作为property写在 hbase-site.xml里面的,这里指定zookeeper的集群服务器

  • 修改配置文件 conf/hbase-site.xml
# conf/hbase-site.xml
<property>
    <name>hbase.zookeeper.quorum</name>
    <value>centos-node6,centos-node7,centos-node8</value>
  </property>
  <property>
    <name>hbase.zookeeper.property.dataDir</name>
    <value>/opt/zookeeper</value>
  </property>

hbase 必须zookeeper hbase需要依赖hadoop吗_hbase_06

  • HDFS客户端配置

如果你希望Hadoop集群上做HDFS 客户端配置 ,例如你的HDFS客户端的配置和服务端的不一样。按照如下的方法配置,HBase就能看到你的配置信息

在${HBASE_HOME}/conf下面加一个 hdfs-site.xml (或者 hadoop-site.xml) ,最好是软连接

# cp /usr/local/hadoop-2.5.1/etc/hadoop/hdfs-site.xml  /usr/local/hbase-0.98.9-hadoop2/conf/

hbase 必须zookeeper hbase需要依赖hadoop吗_分布式_07

运行和确认你的安装

首先确认你的HDFS是运行着的。你可以运行HADOOP_HOME中的 bin/start-hdfs.sh 来启动HDFS.你可以通过put命令来测试放一个文件,然后有get命令来读这个文件。通常情况下HBase是不会运行mapreduce的。所以比不需要检查这些。

如果你自己管理ZooKeeper集群,你需要确认它是运行着的。如果是HBase托管,ZoopKeeper会随HBase启动。

- HBase配置同步到指定服务器

– 以上HBase配置信息,只在服务器centos-node6已完成,需要同步到,centos-node7,centos-node8,centos-node9服务器上,保证HBase配置信息一致。

分别在 centos-node7,centos-node8,centos-node9 解压

# tar -zxvf hbase-0.98.9-hadoop2-bin.tar.gz -C /usr/local

拷贝centos-node6上hbase-0.98.9-hadoop2/conf 目录下所有文件到 centos-node7,centos-node8,centos-node9 服务器下 hbase-0.98.9-hadoop2/conf 中,保证hbase配置信息一致。

[root@centos-node6 conf]# scp ./* root@centos-node9:/usr/local/hbase-0.98.9-hadoop2/conf/

hbase 必须zookeeper hbase需要依赖hadoop吗_hbase_08

启动HBase

hbase启动之前,首先确认你的HDFS是运行着的,如果你自己管理ZooKeeper集群,你需要确认它是运行着的。

  • HBase 在那台服务器上启动,那台服务器就默认为 HMaster,也可以单独 启动HMaster
# ./start-hbase.sh

hbase 必须zookeeper hbase需要依赖hadoop吗_hbase 必须zookeeper_09

  • 启动多个Master
# ./hbase-daemon.sh start master

hbase 必须zookeeper hbase需要依赖hadoop吗_centos_10

访问HBase 映射的tcp端口:60010

  • centos-node6 服务器

hbase 必须zookeeper hbase需要依赖hadoop吗_分布式_11

  • centos-node7

hbase 必须zookeeper hbase需要依赖hadoop吗_分布式_12

  • 关闭 centos-node6 上的HMaster后

hbase 必须zookeeper hbase需要依赖hadoop吗_centos_13

  • 访问 centos-node7:60010

hbase 必须zookeeper hbase需要依赖hadoop吗_hbase_14

可以看出,cnetos-node6上的HMaster断机后,HMasterz自动切换到centos-node7服务器上。Hbase 高可用搭建完成!

HBase Shell

  • HBase shell 对hbase操作

在任意一台服务器上操作HBase shell,都是可以的,执行命令 hbase shell 回车,可以看到 hbase shell 链接成功

# ./hbase shell

hbase 必须zookeeper hbase需要依赖hadoop吗_hbase 必须zookeeper_15

  • 查看表 list 命令
hbase(main):001:0> list

hbase 必须zookeeper hbase需要依赖hadoop吗_centos_16

  • 创建一个表
hbase(main):001:0> create 't_class','cF1'

hbase 必须zookeeper hbase需要依赖hadoop吗_分布式_17

  • t_class插入数据
hbase(main):001:0> put 't_class','ROW1','cF1:NAME','English'

hbase 必须zookeeper hbase需要依赖hadoop吗_centos_18

  • 执行 flush ‘t_class’ 将内存中的数据写入到hdfs中

hbase 必须zookeeper hbase需要依赖hadoop吗_centos_19

  • hbase 表中的数据查看

在hbase中bin/目录下执行./hbase可以看到关于hbase的相关命令

[root@centos-node8 bin]# ./hbase
Usage: hbase [<options>] <command> [<args>]
Options:
  --config DIR    Configuration direction to use. Default: ./conf
  --hosts HOSTS   Override the list in 'regionservers' file

Commands:
Some commands take arguments. Pass no args or -h for usage.
  shell           Run the HBase shell
  hbck            Run the hbase 'fsck' tool
  hlog            Write-ahead-log analyzer
  hfile           Store file analyzer
  zkcli           Run the ZooKeeper shell
  upgrade         Upgrade hbase
  master          Run an HBase HMaster node
  regionserver    Run an HBase HRegionServer node
  zookeeper       Run a Zookeeper server
  rest            Run an HBase REST server
  thrift          Run the HBase Thrift server
  thrift2         Run the HBase Thrift2 server
  clean           Run the HBase clean up script
  classpath       Dump hbase CLASSPATH
  mapredcp        Dump CLASSPATH entries required by mapreduce
  pe              Run PerformanceEvaluation
  ltt             Run LoadTestTool
  version         Print the version
  CLASSNAME       Run the class named CLASSNAME
  • hbase 命令查看hdfs中表 ‘t_class’文件内容,执行 ./hbase hfile 可以看到相关的命令
[root@centos-node8 bin]# ./hbase hfile
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hbase-0.98.9-hadoop2/lib/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop-2.5.1/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
2017-07-13 23:58:09,430 INFO  [main] Configuration.deprecation: fs.default.name is deprecated. Instead, use fs.defaultFS
usage: HFile [-a] [-b] [-e] [-f <arg> | -r <arg>] [-h] [-k] [-m] [-p]
       [-s] [-v] [-w <arg>]
 -a,--checkfamily         Enable family check
 -b,--printblocks         Print block index meta data
 -e,--printkey            Print keys
 -f,--file <arg>          File to scan. Pass full-path; e.g.
                          hdfs://a:9000/hbase/hbase:meta/12/34
 -h,--printblockheaders   Print block headers for each block.
 -k,--checkrow            Enable row order check; looks for out-of-order
                          keys
 -m,--printmeta           Print meta data of file
 -p,--printkv             Print key/value pairs
 -r,--region <arg>        Region to scan. Pass region name; e.g.
                          'hbase:meta,,1'
 -s,--stats               Print statistics
 -v,--verbose             Verbose output; emits file and meta data
                          delimiters
 -w,--seekToRow <arg>     Seek to this row and print all the kvs for this
                          row only
  • 拷贝hdfs下t_class文件路径 执行一下命令

hbase 必须zookeeper hbase需要依赖hadoop吗_分布式_20

# ./hbase hfile -p -f /hbase/data/default/t_class/7a64e48f6e64cc7deb13b72f7d1aa89e/cF1/0e619ff0dd1a422cb5176f909e2ff977

hbase 必须zookeeper hbase需要依赖hadoop吗_hadoop_21

执行到这里,HBase基于Hadoop2.5完全分布式HA环境搭架 完成了,此文只作为学习期间的笔记