一、安裝包的準備
我準備的是版本是:hbase-1.2.6-bin.tar.gz,可自行網上下載,也是你唯一需要下載的安裝包。
注:jdk配置爲1.8.x,配置方法網上太多了,自己找。
二、文件夾的準備和安裝包的解壓
mkdir /home/hbase
mkdir /home/hbase/data/hbase_db
mkdir /home/hbase/data/zk_db
將hbase-1.2.6-bin.tar.gz上傳到 /home/hbase/目錄下並執行如下命令解壓
tar -zxvf hbase-1.2.6-bin.tar.gz
結果如下:
三、配置文件的修改
cd /home/hbase/hbase-1.2.6/conf
vi hbase-env.sh
下面2行註釋了,不然啓動時會有警告
#export HBASE_MASTER_OPTS="$HBASE_MASTER_OPTS -XX:PermSize=512m -XX:MaxPermSize=512m"
#export HBASE_REGIONSERVER_OPTS="$HBASE_REGIONSERVER_OPTS -XX:PermSize=512m -XX:MaxPermSize=512m"
配置啓動hbase包裏自帶的zookeeper
export HBASE_MANAGES_ZK=true
vi hbase-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
/**
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<configuration>
<property>
<name>hbase.rootdir</name>
<value>file:///home/hbase/data/hbase_db</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/hbase/data/zk_db</value>
</property>
<property>
<name>hbase.zookeeper.property.clienPort</name>
<value>2181</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>false</value>
</property>
<property>
<name>hbase.unsafe.stream.capability.enforce</name>
<value>false</value>
</property>
</configuration>
將上面<configuration></configuration> 標籤內的內容複製過去粘貼了就行,
其中
<property>
<name>hbase.rootdir</name>
<value>file:///home/hbase/data/hbase_db</value>
</property>
表示將hbase的數據存儲於本地/home/hbase/data/hbase_db目錄下
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/hbase/data/zk_db</value>
</property>
表示將管理hbase節點的zookeeper信息存儲於與本地 /home/hbase/data/zk_db 目錄下
你可以配置其他路徑或目錄下,但是配置格式要和這保持一致。
<property>
<name>hbase.zookeeper.property.clienPort</name>
<value>2181</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>false</value>
</property>
表示限定使用zookeeper端口爲 2181 且hbase爲單節點不爲集羣。
四、hbase啓動
cd /home/hbase/hbase-1.2.6/bin
sh start-hbase.sh
因爲是單節點,所以啓動後 jps只要有HMaster進程在就可以了。
五、hbase UI 頁面的訪問,以及命令行登錄
重點前提:hbase所在服務需要配置好主機名
查看主機名: hostname
設置主機名:hostnamectl set-hostname 主機名
訪問的電腦(windows)機器host文件必須配置hbase部署機器的主機名
瀏覽器回車 bigdata10:16010 即可訪問
hbase shell 命令登錄
創建表hhf
create 'hhf','f'
創建表 hhf1
create 'hhf1','f'
查看錶列表:list
至此hbase部署完成,且成功啓動。
六、java demo訪問hbase
添加如下依賴
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-server</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-common</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
建立連接
寫數據
查數據
其他的增刪改查也都類似,有不明白的參考hbase權威操作指南。pdf
至此完成了。