這邊博文就帶着大家一起學習如何安裝HBase,首先,我們來學習如何在單節點上安裝HBase,後續會帶着大家一起學習如何搭建HBase叢集。
一、配置伺服器主機名和IP映射
1、配置主機名
vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=liuyazhuang121
NTPSERVERARGS=iburst
2、配置主機名映射
vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.209.121 liuyazhuang121
二、安裝Hadoop
1、僞分布式安裝
2、 叢集安裝
3、 高可用叢集安裝
這篇博文中,我也是在單節點上安裝的Hadoop,将HBase和Hadoop安裝在了同一台伺服器上。由于HBase的運作依賴于Zookeeper,是以,在同一台伺服器上,又安裝了單節點的Zookeeper。
三、安裝并配置Zookeeper
HBase的運作依賴于Zookeeper,是以我們先安裝Zookeeper。
1、安裝Zookeeper
這裡我安裝的Zookeeper版本是zookeeper-3.4.9.tar.gz,上傳Zookeeper到伺服器的/usr/local目錄下,然後解壓
tar -zxvf zookeeper-3.4.9.tar.gz
2、配置系統環境變量
vim /etc/profile
HADOOP_HOME=/usr/local/hadoop-2.5.2
ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.9
PATH=$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$ZOOKEEPER_HOME/bin:$PATH
export HADOOP_HOME ZOOKEEPER_HOME PATH
3、配置zoo.cfg
進入ZOOKEEPER_HOME/conf目錄下,執行如下指令
cp zoo_sample.cfg zoo.cfg
然後編譯zoo.cfg檔案如下:
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zookeeper-3.4.9/data
dataLogDir=/usr/local/zookeeper-3.4.9/dataLog
# the port at which the clients will connect
clientPort=2182
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
注意:HBase中自帶有Zookeeper,為了不和HBASE中自帶的Zookeeper端口沖突,這裡的Zookeeper配置的端口為2182,并不是預設的2181,如果Hbase和Zookeeper安裝在不同的伺服器上,則不存在這種問題。
然後再ZOOKEEPER_HOME目錄下建立data、dataLog目錄。
mkdir -p /usr/local/zookeeper-3.4.9/data
mkdir -p /usr/local/zookeeper-3.4.9/dataLog
4、啟動Zookeeper
zkServer.sh start
四、安裝并配置HBase
1、安裝Hbase
這裡我安裝的HBase版本是hbase-0.96.2-hadoop2-bin.tar.gz,将其上傳到伺服器的/usr/local目錄下,然後輸入如下指令解壓
tar-zxvf hbase-0.96.2-hadoop2-bin.tar.gz
vim /etc/profile
HADOOP_HOME=/usr/local/hadoop-2.5.2
ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.9
HBASE_HOME=/usr/local/hbase-0.96.2-hadoop2
PATH=$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$ZOOKEEPER_HOME/bin:$HBASE_HOME/bin:$PATH
export HADOOP_HOME ZOOKEEPER_HOME PATH HBASE_HOME
3、拷貝Hadoop的hdfs-site.xml和core-site.xml檔案
cp /usr/local/hadoop-2.5.2/etc/hadoop/core-site.xml /usr/local/hbase-0.96.2-hadoop2/conf/
cp /usr/local/hadoop-2.5.2/etc/hadoop/hdfs-site.xml /usr/local/hbase-0.96.2-hadoop2/conf/
4、修改hbase-env.sh
4.1 修改JAVE_HOME
export JAVA_HOME=/usr/local/src/jdk1.7.0_80
4.2 修改HBASE_MANAGES_ZK為false
修改HBASE_MANAGES_ZK為false來告訴HBase使用外部的Zookeeper
export HBASE_MANAGES_ZK=false
5、修改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>hdfs://liuyazhuang121:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>false</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>liuyazhuang121:2182</value>
</property>
</configuration>
因為我們配置的Zookeeper端口為2182,是以這裡将hbase.zookeeper.quorum的value配置成了liuyazhuang121:2182
6、修改regionservers
修改regionservers檔案,将localhost修改成liuyazhuang121如下:
liuyazhuang121
7、啟動HBase
start-hbase.sh
8、檢視本機啟動的Java程序
[root@liuyazhuang121 conf]# jps
6008 QuorumPeerMain
2445 NameNode
2539 DataNode
7289 Jps
6153 HMaster
2723 SecondaryNameNode
2993 NodeManager
2893 ResourceManager
[root@liuyazhuang121 conf]#
9、檢視HBase管理頁面
在浏覽器中輸入http://192.168.209.121:60010檢視HBase管理頁面如下: