版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SunnyYoona/article/details/53456433
1. 启动Hadoop
如果没有安装Hadoop,则查看博文:http://blog.csdn.net/sunnyyoona/article/details/53454430
启动Hadoop并查看Hadoop版本:
xiaosi@yoona:~/opt/hadoop-2.7.3$ sbin/start-dfs.sh
Starting namenodes on [localhost]
localhost: starting namenode, logging to /home/xiaosi/opt/hadoop-2.7.3/logs/hadoop-xiaosi-namenode-yoona.out
localhost: starting datanode, logging to /home/xiaosi/opt/hadoop-2.7.3/logs/hadoop-xiaosi-datanode-yoona.out
Starting secondary namenodes [0.0.0.0]
0.0.0.0: starting secondarynamenode, logging to /home/xiaosi/opt/hadoop-2.7.3/logs/hadoop-xiaosi-secondarynamenode-yoona.out
xiaosi@yoona:~/opt/hadoop-2.7.3$ bin/hadoop version
Hadoop 2.7.3
Subversion https://git-wip-us.apache.org/repos/asf/hadoop.git -r baa91f7c6bc9cb92be5982de4719c1c8af91ccff
Compiled by root on 2016-08-18T01:41Z
Compiled with protoc 2.5.0
From source with checksum 2e4ce5f957ea4db193bce3734ff29ff4
This command was run using /home/xiaosi/opt/hadoop-2.7.3/share/hadoop/common/hadoop-common-2.7.3.jar
从上可以知道Hadoop版本为2.7.3版本
2. 下载与解压
我们从官网上下载:http://www.apache.org/dyn/closer.cgi/hbase/
解压到~/opt文件夹下:
xiaosi@yoona:~$ tar -zxvf hbase-1.2.4-bin.tar.gz -C opt/
重命名,便与管理:
xiaosi@yoona:~$ cp hbase-1.2.4-bin.tar.gz hbase-1.2.4
3. 配置
修改hbase-env.sh,配置JDK路径以及Zookeeper:
# The java implementation to use. Java 1.7+ required.
export JAVA_HOME=/home/xiaosi/opt/jdk-1.8.0
# Tell HBase whether it should manage it's own instance of Zookeeper or not.
export HBASE_MANAGES_ZK=true
修改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>system.username</name>
<value>xiaosi</value>
</property>
<property>
<name>hbase.rootdir</name>
<value>hdfs://localhost:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.tmp.dir</name>
<value>/home/${system.username}/tmp/hbase</value>
</property>
</configuration>
4. 设置环境变量
在/etc/profile配置文件中,创建HBASE_HOME环境变量指向hbase目录,便于以后操作:
# hbase
export HBASE_HOME=/home/xiaosi/opt/hbase-1.2.4
export PATH=${HBASE_HOME}/bin:$PATH
5. 启动Hadoop
进入 Hadoop 主文件夹,开启NameNode和DataNode守护进程:
xiaosi@yoona:~/opt/hadoop-2.7.3$ cd ~
xiaosi@yoona:~$ cd $HADOOP_HOME
xiaosi@yoona:~/opt/hadoop-2.7.3$ sbin/start-dfs.sh
Starting namenodes on [localhost]
localhost: starting namenode, logging to /home/xiaosi/opt/hadoop-2.7.3/logs/hadoop-xiaosi-namenode-yoona.out
localhost: starting datanode, logging to /home/xiaosi/opt/hadoop-2.7.3/logs/hadoop-xiaosi-datanode-yoona.out
Starting secondary namenodes [0.0.0.0]
0.0.0.0: starting secondarynamenode, logging to /home/xiaosi/opt/hadoop-2.7.3/logs/hadoop-xiaosi-secondarynamenode-yoona.out
6. 启动HBase
进入 HBase 主文件夹,开启HMaster和HRegionServer守护进程:
xiaosi@yoona:~/opt/hbase-1.2.4$ bin/start-hbase.sh
localhost: starting zookeeper, logging to /home/xiaosi/opt/hbase-1.2.4/bin/../logs/hbase-xiaosi-zookeeper-yoona.out
starting master, logging to /home/xiaosi/opt/hbase-1.2.4/logs/hbase-xiaosi-master-yoona.out
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
starting regionserver, logging to /home/xiaosi/opt/hbase-1.2.4/logs/hbase-xiaosi-1-regionserver-yoona.out
通过jps命令查看启动情况:
xiaosi@yoona:~/opt/hbase-1.2.4$ jps
1536 Jps
915 HQuorumPeer
22886 SecondaryNameNode
22678 DataNode
1117 HRegionServer
989 HMaster
22511 NameNode
7. 进入Hbase Shell
xiaosi@yoona:~/opt/hbase-1.2.4$ bin/hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/xiaosi/opt/hbase-1.2.4/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/xiaosi/opt/hadoop-2.7.3/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.2.4, r67592f3d062743907f8c5ae00dbbe1ae4f69e5af, Tue Oct 25 18:10:20 CDT 2016
hbase(main):001:0>
走到这一步,我们已经确定HBase已经安装成功。为了最终验证,可以试试列出HBase中所有表的命令。这个动作执行了一个全程请求,从客户端应用到HBase服务器,然后返回。在Shell提示符下,输入list然后按下回车键:
hbase(main):001:0> list
TABLE
0 row(s) in 0.1980 seconds
=> []
完成安装与验证,现在可以创建表并存储一些数据了。
8. 初步使用HBase
创建一个有列族的表student,列族为info:
hbase(main):002:0> create 'student', 'info'
0 row(s) in 1.3580 seconds
=> Hbase::Table - student
再次查看表:
hbase(main):003:0> list
TABLE
student
1 row(s) in 0.0150 seconds
=> ["student"]