任務描述
任務內容為HBase的安裝部署與測試。
任務指導
HBase集群需要整個集群所有節點安裝的HBase版本保持一致,并且擁有相同的配置
具體配置步驟如下:
1. 解壓縮HBase的壓縮包
2. 配置HBase的環境變量
3. 修改HBase的配置文件,HBase的配置文件存放在HBase安裝目錄下的conf中
4. 首先在一臺節點對整個HBase集群進行配置,再將此節點的配置發送到集群的其它節點上。
5. 具體需要修改的HBase的配置文件包括 hbase-site.xml、hbase-env.sh、regionservers
任務實現
1、HBase安裝
這里已經將壓縮包存放在/opt/software目錄下,解壓命令如下:
[root@master1 ~]# tar -zxvf /opt/software/hbase-2.3.5-bin.tar.gz -C /opt/app/
設置HBase環境變量(master1、slave1、slave2)這里以master1為例:
[root@master1 ~]#?vi /etc/profile
export?HBASE_HOME=/opt/app/hbase-2.3.5
export?PATH=$PATH:$HBASE_HOME/bin
使用【source? /etc/profile】使配置文件生效。
2、配置hbase-env.sh文件
[root@master1 ~]# cd $HBASE_HOME/conf
[root@master1 conf]# vi hbase-env.sh
在文件末尾添加如下配置:
export JAVA_HOME=/opt/app/jdk1.8.0_181
export HBASE_MANAGES_ZK=false
3、配置?hbase-site.xml文件,該文件存放在$HBASE_HOME/conf目錄下,配置內容如下:
<?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>hdfs://master1:9000/hbase</value>
</property>
<property>
<name>hbase.unsafe.stream.capability.enforce</name>
<value>false</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>master1:2181,slave1:2181,slave2:2181</value>
</property>
</configuration>
4、配置regionservers文件
[root@master1 conf]# vi regionservers
slave1
slave2
5、將Hadoop的配置文件拷貝到HBase的conf目錄
[root@master1 ~]# cp $HADOOP_HOME/etc/hadoop/core-site.xml $HBASE_HOME/conf
[root@master1 ~]# cp $HADOOP_HOME/etc/hadoop/hdfs-site.xml $HBASE_HOME/conf
6、將master1的HBase分發至整個集群:
[root@master1 ~]# cd /opt/app
[root@master1 app]# scp -r hbase-2.3.5 slave1:/opt/app/
[root@master1 app]# scp -r hbase-2.3.5 slave2:/opt/app/
7、測試
HBase使用ZooKeeper保存元數據,在啟動前需要保證ZooKeeper集群(master1、slave1、slave3)已啟動,命令如下:
# zkServer.sh start
#在master1上啟動HBase集群
[root@master1 ~]# start-hbase.sh
此時可以通過16010端口產看HBase的Web UI界面,如【http://master1:16010】。
#新建一個名為test的表,使其只包含一個名為data的列,表和列族屬性都為默認值
[root@master1 ~]# hbase shell
hbase(main):001:0>?create?'test','data'
0?row(s)?in?0.4150?seconds
#通過鍵入help查看幫助命令,運行list查看新建的表是否存在
hbase(main):003:0>?list
TABLE
test
1?row(s)?in?0.0230?seconds
#在列族data中二個不同的行和列上插入數據,然后列出表內容
hbase(main):004:0>?put?'test','row1','data:1','values1'
0?row(s)?in?0.1280?seconds
hbase(main):005:0>?put?'test','row2','data:2','values2'
0?row(s)?in?0.0090?seconds
hbase(main):006:0>?scan?'test'
ROW?COLUMN+CELL
row1?column=data:1,?timestamp=1473585137461,?value=values1
row2?column=data:2,?timestamp=1473585158072,?value=values2
2?row(s)?in?0.0200?seconds
#刪除剛創建的表test,需要先設為禁用,然后刪除,不設置會報錯:
hbase(main):008:0>?drop?'test'
ERROR:?Table?test?is?enabled.?Disable?it?first.
hbase(main):009:0>?disable?'test'
0?row(s)?in?1.1800?seconds
hbase(main):010:0>?drop?'test'
0?row(s)?in?0.1570?seconds
#為后續功能創建命名空間
create_namespace 'ns_ct'
#為后續功能創建表
create 'ns_ct:calllog','f1','f2'