HBase的安裝、配置、使用

下載

進入hbase下載頁面,選擇與hadoop版本相兼容的hbase版本。在這個頁面使用ctrl+f搜索"S", 而後下面有一個表就是hbase與hadoop版本對應關係:html

我這裏使用的hadoop版本是2.8.5,使用的hbase版本是2.1.1。java

新建一個/usr/hbase目錄,而後下載hbase。node

安裝

使用tar xzvf hbase-XXX命令解壓hbase的包。解壓完後,進入到解壓好的hbase目錄中,編輯conf/hbase-site.xml,該文件時主要的hbase配置文件,配置hbase的數據存儲目錄,這個配置文件中,在官方文檔說起到linux

You do not need to create the HBase data directory. HBase will do this for you. If you create the directory, HBase will attempt to do a migration, which is not what you want.shell

大概意思是,咱們不須要去建立hbase的數據目錄,hbase會本身建一個目錄來保存數據,若是咱們自定義了目錄,那麼hbase把數據進行遷移過來,這會致使性能以及時間上的一些損耗。apache

配置

配置JAVA_HOME

首先找到java的安裝路徑。而後使用vim /etc/profile命令打開profile文件,而後指定JAVA_HOME:vim

配置hbase-site.xml

由於我以前已經安裝了hadoop,已經有hdfs了,因此,這裏的hbase.rootdir配置就要指向個人hadoop的hdfs目錄,我是配置的core-site.xml中fs.defaultFS配置:oop

個人hbase-site.xml配置以下:性能

<configuration>
  <property>
    <name>hbase.rootdir</name>
    <value>hdfs://localhost:9000/hbase</value>
  </property>
  <property>
    <name>hbase.zookeeper.property.dataDir</name>
    <value>/usr/hadoop/hbase/zookeeper</value>
  </property>
  <property>
    <name>hbase.unsafe.stream.capability.enforce</name>
    <value>false</value>
    <description>
      Controls whether HBase will check for stream capabilities (hflush/hsync).

      Disable this if you intend to run on LocalFileSystem, denoted by a rootdir
      with the 'file://' scheme, but be mindful of the NOTE below.

      WARNING: Setting this to false blinds you to potential data loss and
      inconsistent system state in the event of process and/or node failures. If
      HBase is complaining of an inability to use hsync or hflush it's most
      likely not a false positive.
    </description>
  </property>
</configuration>
  • hbase.rootdir 指定hbase數據存儲的地方
  • hbase.zookeeper.property.dataDirzookeeper也須要存儲一些文件,該地方是指定zookeeper存儲數據的地方

啓動測試

運行hbase

運行bin/start-hbase.sh,若是運行成功,使用jps命令可看到HMaster進程啓動成功:測試

另外訪問<yourip>:16010能看到HBase的管理頁面:

使用hbase shell

進入到hbase的安裝目錄下,使用bin/hbase shell啓動hbase:

看到:

hbase(main):001:0>

表示hbase已經啓動成功,能夠直接使用hbase命令操做了。

  • create <table> <column family>命令

create 'test', 'cf'表示建立一張test的表,column family爲cf,建立表的時候table和column family缺一不可。

  • list <table> 確認某個表是否存在

  • describe <table>查看錶的詳細信息,包括默認值。

  • put <table> <row> <column family> <value> put值到某個表中

由於HBase使用table/row/column family來肯定值的惟一性,因此在put值時,這些信息也是缺一不可的。

  • scan <table> 查看某個表中的數據

  • get <table> <row> 獲取某個表某行的數據

  • disable <table> 禁用表

若是須要刪除表或更改表的設置,須要先使用該命令禁用表,禁用後也可使用enable <table>來啓用表。

  • enable <table> 啓用表

  • drop <table> 刪除表

最後退出HBase Shell: quit

相關文章
相關標籤/搜索