Hadoop与Hbase基本配置
生活随笔
收集整理的這篇文章主要介紹了
Hadoop与Hbase基本配置
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
在經(jīng)歷了幾周的努力之后,終于選擇放棄現(xiàn)在安裝的穩(wěn)定版本,轉(zhuǎn)而安裝舊版本來部署Sleuthkit-Hadp系統(tǒng)。直到昨天,自己還一直為Inconsistent configuration的錯(cuò)誤頭疼不已。既然同事的版本已經(jīng)裝成功了,那自己也就先用跑通的系統(tǒng)試一下吧,畢竟先放下再回來看現(xiàn)在的問題可能有更好的解決思路吧。今天開始正式重新部署SH系統(tǒng)的第一步,安裝Hadoop與Hbase。之前的安裝筆記比較凌亂,今天借著這樣的機(jī)會把整個(gè)步驟重新梳理一遍。
一、安裝Hadoop
? ? ?自己使用的軟件版本是hadoop-1.0.3,比較早的一個(gè)版本,可以去hadoop的官方網(wǎng)站去下載。在安裝hadoop以前首先要設(shè)置系統(tǒng)環(huán)境:
<1> 安裝java-1.6版本,之前自己安裝的java-1.7,但是沒有成功,不曉得是不是java版本的緣故;無論如何,這次自己選擇了比較保守的方案,從oracle官方注冊后下載jdk-6u45-linux-i586.bin后解包得到【jdk-1.6.0_45】。注意到這里都是bin文件,因此需要chmod該文件以775的可執(zhí)行權(quán)限,然后./filename.bin即可;
<2> 安裝ssh,并且設(shè)置ssh無密碼登錄hadoop
<2.1>運(yùn)行sudo apt-get install ssh/rsync,運(yùn)行sudo apt-get install openjava1.6-jdk (for jps command)
<2.2>配置ssh本機(jī)免口令登錄主要有兩步:
運(yùn)行ssh-keygen -t dsa -P '' -f /.ssh/id_dsa
? ?-t用來指定加密算法,可以選擇dsa和rsa兩種加密方式;
? ?-P用來指定密碼,兩個(gè)單引號表示空密碼'';
? ?-f用來指定存放密鑰的文件
運(yùn)行cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
? ?這一步將公鑰添加進(jìn)本機(jī)的authorized_keys中,完成這兩步后可以ssh localhost驗(yàn)證是否成功。接下來需要進(jìn)入已經(jīng)解好的hadoop-1.0.3中進(jìn)行配置。hadoop的偽分布模式主要需要配置以下幾個(gè)配置文件:
<3>conf/hbase-env.sh:主要用來配置hadoop的運(yùn)行環(huán)境,這里需要修改JAVA_HOME到你的jdk1.6目錄(見黑體)
#Set Hadoop-specific environment variables here.
# The only required environment variable is JAVA_HOME.?All?others are
# optional. When running a distributed configuration?it?is best to
# set JAVA_HOME in this file,?so that?it?is correctly defined?on
# remote nodes.
# The java implementation to use. Required.
export JAVA_HOME=/home/hadoop/platform/jdk1.6.0_45
# Extra Java CLASSPATH elements. Optional.
# export HADOOP_CLASSPATH=
# The maximum amount of heap to use,?in MB. Default is 1000.
# export HADOOP_HEAPSIZE=2000
# Extra Java runtime?options.?Empty by default.
# export HADOOP_OPTS=-server
# Command specific?options?appended to HADOOP_OPTS when specified
export HADOOP_NAMENODE_OPTS="-Dcom.sun.management.jmxremote $HADOOP_NAMENODE_OPTS"
export HADOOP_SECONDARYNAMENODE_OPTS="-Dcom.sun.management.jmxremote $HADOOP_SECONDARYNAMENODE_OPTS"
export HADOOP_DATANODE_OPTS="-Dcom.sun.management.jmxremote $HADOOP_DATANODE_OPTS"
export HADOOP_BALANCER_OPTS="-Dcom.sun.management.jmxremote $HADOOP_BALANCER_OPTS"
export HADOOP_JOBTRACKER_OPTS="-Dcom.sun.management.jmxremote $HADOOP_JOBTRACKER_OPTS"
# export HADOOP_TASKTRACKER_OPTS=
# The following applies to multiple commands (fs,?dfs,?fsck,?distcp etc)
# export HADOOP_CLIENT_OPTS
# Extra ssh?options.?Empty by default.
# export HADOOP_SSH_OPTS="-o ConnectTimeout=1 -o SendEnv=HADOOP_CONF_DIR"
# Where log?files?are stored. $HADOOP_HOME/logs by default.
# export HADOOP_LOG_DIR=${HADOOP_HOME}/logs
# File naming remote slave hosts. $HADOOP_HOME/conf/slaves by default.
# export HADOOP_SLAVES=${HADOOP_HOME}/conf/slaves
# host:path where hadoop code should be rsync'd?from.?Unset by default.
# export HADOOP_MASTER=master:/home/$USER/src/hadoop
# Seconds to sleep between slave commands. Unset by default. This
# can be useful in large clusters,?where,?e.g.,?slave rsyncs can
# otherwise arrive faster than the master can service them.
# export HADOOP_SLAVE_SLEEP=0.1
# The?directory?where pid?files?are stored. /tmp by default.
# export HADOOP_PID_DIR=/var/hadoop/pids
# A string representing this instance of hadoop. $USER?by default.
# export HADOOP_IDENT_STRING=$USER
# The scheduling priority for daemon processes. See 'man nice'.
# export HADOOP_NICENESS=10
<4>conf/core-site.xml
? ? ?這里主要配置fs.default.name(用來指定namenode)和hadoop.tmp.dir(默認(rèn)的hdfs的tmp目錄位置),這里可以不設(shè)置hadoop.tmp.dir,那么就會保存在默認(rèn)的/tmp下,每次重啟機(jī)器都會丟失數(shù)據(jù)。
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl"?href="configuration.xsl"?>
??
<!-- Put site-specific property overrides in this file. -->
<configuration>
???<property>
???????<name>fs.default.name</name>
???????<value>hdfs://localhost:9000</value>
???</property>
???<property>
???????<name>hadoop.tmp.dir</name>
???????<value>/home/hadoop/hdfs/tmp</value>
???</property>
</configuration>
<5>hdfs-site.xml
? ? ?這里的dfs.replication用來設(shè)置每份數(shù)據(jù)塊的副本數(shù)目,默認(rèn)是3,因?yàn)槲覀兪窃趩螜C(jī)上配置的偽分布模式,因此設(shè)為1。dfs.name.dir和dfs.data.dir非常重要,用來設(shè)置存放hdfs中namenode和datanode數(shù)據(jù)的本地存放位置。這里如果設(shè)置不好,后續(xù)會出現(xiàn)多個(gè)錯(cuò)誤。當(dāng)然你也可以不設(shè)置采用默認(rèn)的/tmp下的目錄,但是同樣重啟會丟失數(shù)據(jù)。
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl"?href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
???<property>
???????<name>dfs.replication</name>
???????<value>1</value>
???</property>
???<property>
???????<name>dfs.name.dir</name>
???????<value>/home/hadoop/hdfs/name</value>
???</property>
???<property>
???????<name>dfs.data.dir</name>
???????<value>/home/hadoop/hdfs/data</value>
???</property>
</configuration>
<6>mapred-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl"?href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
???<property>
???????<name>mapred.job.tracker</name>
???????<value>localhost:9001</value>
???</property>
</configuration>
? ? ? 然后就是運(yùn)行測試了,把hadoop-1.0.3/bin加入到/etc/profile中的PATH路徑中,方便我們執(zhí)行Hadoop命令。運(yùn)行start-all.sh后出現(xiàn)了問題,jps查看namenode無法啟動,使用hadoop namenode -format也不能成功,查看日志:
? ? 提示我們存儲的HDFS目錄要么不存在要么沒有權(quán)限:
FSNamesystem initialization failed.
org.apache.hadoop.hdfs.server.common.InconsistentFSStateException:Directory /home/hadoop/hdfs/name is in an inconsistent state: storage directory does not exist or is not accessible.
查看發(fā)現(xiàn)已經(jīng)生成了hdfs目錄,那么問題就是權(quán)限了,將/home下的hadoop目錄權(quán)限由755設(shè)為775,然后重新運(yùn)行hadoop,成功:
? ? ? 在進(jìn)行安裝hbase之前,我們先來按照官方的方法測試一下偽分布式的hadoop,看看安裝是否成功:首先將conf下的所有文件拷貝到hdfs上的input目錄中,然后運(yùn)行jar文件將結(jié)果存儲到hdfs中的output目錄中,最后從output目錄中查看結(jié)果:
$ bin/hadoop fs -put conf input
$ bin/hadoop jar hadoop-examples-*.jar grep input output 'dfs[a-z.]+'
Copy the output?files?from?the distributed filesystem to the local filesytem and examine them:
$ bin/hadoop fs -get?output output?
$ cat output/*
or
View the output?files?on?the distributed filesystem:
$ bin/hadoop fs -cat output/*
When you're done,?stop the daemons with:
$ bin/stop-all.sh
二、安裝hbase
? ? ?這里選擇的版本是hbase-0.90.0,首先從google中直接搜索該版本,下載后解壓得到hbase-0.90.0。同hadoop一樣,這里我們的主要工作同樣是修改配置文件:
<1> 修改/etc/hosts文件,將127.0.1.1 hadoop修改為127.0.0.1
<2> 設(shè)置ulimits:
修改 /etc/security/limits.conf ,添加:
hadoop - ?nofile 32768
hadoop soft/hard nproc 32000
修改/etc/pam.d/common-session?,添加
session required pam_limits.so
<3>修改conf/hbase-env.xml
? ? ?這里主要設(shè)置JAVA_HOME目錄,HBASE_LOG_DIR路徑以及啟用hbase自帶的zookeeper
#
#/**
#?*?Copyright 2007 The Apache Software Foundation
#?*
#?*?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.
#?*/
# Set environment variables here.
# The java implementation to use. Java 1.6 required.
?export JAVA_HOME=/home/hadoop/platform/jdk1.6.0_45?
# Extra Java CLASSPATH elements. Optional.
# export HBASE_CLASSPATH=
# The maximum amount of heap to use,?in MB. Default is 1000.
# export HBASE_HEAPSIZE=1000
# Extra Java runtime?options.
# Below are what we set by default. May only work with SUN JVM.
# For more?on?why as well as other possible settings,
# see http://wiki.apache.org/hadoop/PerformanceTuning
export HBASE_OPTS="$HBASE_OPTS -ea -XX:+HeapDumpOnOutOfMemoryError -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode"
# Uncomment below to enable java garbage collection logging.
# export HBASE_OPTS="$HBASE_OPTS -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:$HBASE_HOME/logs/gc-hbase.log"?
# Uncomment and adjust to enable JMX exporting
# See jmxremote.password and jmxremote.access in $JRE_HOME/lib/management to configure remote password access.
# More details at:?http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html
#
# export HBASE_JMX_BASE="-Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
# export HBASE_MASTER_OPTS="$HBASE_MASTER_OPTS $HBASE_JMX_BASE -Dcom.sun.management.jmxremote.port=10101"
# export HBASE_REGIONSERVER_OPTS="$HBASE_REGIONSERVER_OPTS $HBASE_JMX_BASE -Dcom.sun.management.jmxremote.port=10102"
# export HBASE_THRIFT_OPTS="$HBASE_THRIFT_OPTS $HBASE_JMX_BASE -Dcom.sun.management.jmxremote.port=10103"
# export HBASE_ZOOKEEPER_OPTS="$HBASE_ZOOKEEPER_OPTS $HBASE_JMX_BASE -Dcom.sun.management.jmxremote.port=10104"
# File naming hosts?on?which HRegionServers will run. $HBASE_HOME/conf/regionservers by default.
# export HBASE_REGIONSERVERS=${HBASE_HOME}/conf/regionservers
# Extra ssh?options.?Empty by default.
# export HBASE_SSH_OPTS="-o ConnectTimeout=1 -o SendEnv=HBASE_CONF_DIR"
# Where log?files?are stored. $HBASE_HOME/logs by default.
export HBASE_LOG_DIR=${HBASE_HOME}/logs
# A string representing this instance of hbase. $USER?by default.
# export HBASE_IDENT_STRING=$USER
# The scheduling priority for daemon processes. See 'man nice'.
# export HBASE_NICENESS=10
# The?directory?where pid?files?are stored. /tmp by default.
# export HBASE_PID_DIR=/var/hadoop/pids
# Seconds to sleep between slave commands. Unset by default. This
# can be useful in large clusters,?where,?e.g.,?slave rsyncs can
# otherwise arrive faster than the master can service them.
# export HBASE_SLAVE_SLEEP=0.1
# Tell HBase whether?it?should manage?it's own instance of Zookeeper or not.
?export HBASE_MANAGES_ZK=true
<4>配置conf/hbase-site.xml
? ? ?這里要將我們的hbase設(shè)置為偽分布模式,因此除了設(shè)置hbase的根目錄hbase.rootdir外,還需要設(shè)置hbase.cluster.distributed和hbase.zookeeper.quorum兩個(gè)參數(shù);至于zookeeper.znode.parent是指定zookeeper的相對目錄。
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl"?href="configuration.xsl"?>
<!--
/**
?*?Copyright 2010 The Apache Software Foundation
?*
?*?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://localhost:9000/hbase</value>
????</property>
????????<property>
????????<name>hbase.cluster.distributed</name>
????????<value>true</value>
????</property>
????<property>
????????<name>hbase.zookeeper.quorum</name>
????????<value>localhost</value>
????</property>
????<property>
????????<name>zookeeper.znode.parent</name>
????????<value>/hbase</value>
????</property>
</configuration>
<5>運(yùn)行測試 ? ? ?
? ? ??然后同樣將hbase下的bin目錄加入到PATH中,運(yùn)行start-hbase.sh后發(fā)現(xiàn)HMaster未啟動,查看日志發(fā)現(xiàn)以下提示:
FATAL: org.apache.hadoop.hbase.master.HMaster: Unhandled exception. Starting shutdown. java.io.IOException:
Call to localhost/127.0.0.1:9000 failed on local exception: java.io.EOFException
? ? ??原因是需要將hadoop中的hadoop-core-1.0.4.jar覆蓋掉hbase-0.90.0/lib下的hadoop-core-0.20-append-r1056947.jar文件,再次運(yùn)行提示了新錯(cuò)誤:java.lang.NoClassDefFoundError
? ? ?看來是找不到相關(guān)的類,所以我們需要將hadoop-1.0.3下lib目錄的jar文件全部拷貝到hbase下的lib目錄下,再次運(yùn)行,順利通過:
<5>運(yùn)行hbase shell
? ? ?Hbase為我們提供了shell接口進(jìn)行測試,可以使用create命令創(chuàng)建一個(gè)新表,然后利用put命令添加新的行,使用scan命令查看建立的表:
? ? ?好了,hadoop和hbase的安裝到此基本結(jié)束,明天開始配置Sleuthkit。
一、安裝Hadoop
? ? ?自己使用的軟件版本是hadoop-1.0.3,比較早的一個(gè)版本,可以去hadoop的官方網(wǎng)站去下載。在安裝hadoop以前首先要設(shè)置系統(tǒng)環(huán)境:
<1> 安裝java-1.6版本,之前自己安裝的java-1.7,但是沒有成功,不曉得是不是java版本的緣故;無論如何,這次自己選擇了比較保守的方案,從oracle官方注冊后下載jdk-6u45-linux-i586.bin后解包得到【jdk-1.6.0_45】。注意到這里都是bin文件,因此需要chmod該文件以775的可執(zhí)行權(quán)限,然后./filename.bin即可;
<2> 安裝ssh,并且設(shè)置ssh無密碼登錄hadoop
<2.1>運(yùn)行sudo apt-get install ssh/rsync,運(yùn)行sudo apt-get install openjava1.6-jdk (for jps command)
<2.2>配置ssh本機(jī)免口令登錄主要有兩步:
運(yùn)行ssh-keygen -t dsa -P '' -f /.ssh/id_dsa
? ?-t用來指定加密算法,可以選擇dsa和rsa兩種加密方式;
? ?-P用來指定密碼,兩個(gè)單引號表示空密碼'';
? ?-f用來指定存放密鑰的文件
運(yùn)行cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
? ?這一步將公鑰添加進(jìn)本機(jī)的authorized_keys中,完成這兩步后可以ssh localhost驗(yàn)證是否成功。接下來需要進(jìn)入已經(jīng)解好的hadoop-1.0.3中進(jìn)行配置。hadoop的偽分布模式主要需要配置以下幾個(gè)配置文件:
<3>conf/hbase-env.sh:主要用來配置hadoop的運(yùn)行環(huán)境,這里需要修改JAVA_HOME到你的jdk1.6目錄(見黑體)
點(diǎn)擊(此處)折疊或打開
? ? ?這里主要配置fs.default.name(用來指定namenode)和hadoop.tmp.dir(默認(rèn)的hdfs的tmp目錄位置),這里可以不設(shè)置hadoop.tmp.dir,那么就會保存在默認(rèn)的/tmp下,每次重啟機(jī)器都會丟失數(shù)據(jù)。
點(diǎn)擊(此處)折疊或打開
? ? ?這里的dfs.replication用來設(shè)置每份數(shù)據(jù)塊的副本數(shù)目,默認(rèn)是3,因?yàn)槲覀兪窃趩螜C(jī)上配置的偽分布模式,因此設(shè)為1。dfs.name.dir和dfs.data.dir非常重要,用來設(shè)置存放hdfs中namenode和datanode數(shù)據(jù)的本地存放位置。這里如果設(shè)置不好,后續(xù)會出現(xiàn)多個(gè)錯(cuò)誤。當(dāng)然你也可以不設(shè)置采用默認(rèn)的/tmp下的目錄,但是同樣重啟會丟失數(shù)據(jù)。
點(diǎn)擊(此處)折疊或打開
點(diǎn)擊(此處)折疊或打開
? ? 提示我們存儲的HDFS目錄要么不存在要么沒有權(quán)限:
FSNamesystem initialization failed.
org.apache.hadoop.hdfs.server.common.InconsistentFSStateException:Directory /home/hadoop/hdfs/name is in an inconsistent state: storage directory does not exist or is not accessible.
查看發(fā)現(xiàn)已經(jīng)生成了hdfs目錄,那么問題就是權(quán)限了,將/home下的hadoop目錄權(quán)限由755設(shè)為775,然后重新運(yùn)行hadoop,成功:
? ? ? 在進(jìn)行安裝hbase之前,我們先來按照官方的方法測試一下偽分布式的hadoop,看看安裝是否成功:首先將conf下的所有文件拷貝到hdfs上的input目錄中,然后運(yùn)行jar文件將結(jié)果存儲到hdfs中的output目錄中,最后從output目錄中查看結(jié)果:
點(diǎn)擊(此處)折疊或打開
二、安裝hbase
? ? ?這里選擇的版本是hbase-0.90.0,首先從google中直接搜索該版本,下載后解壓得到hbase-0.90.0。同hadoop一樣,這里我們的主要工作同樣是修改配置文件:
<1> 修改/etc/hosts文件,將127.0.1.1 hadoop修改為127.0.0.1
<2> 設(shè)置ulimits:
修改 /etc/security/limits.conf ,添加:
hadoop - ?nofile 32768
hadoop soft/hard nproc 32000
修改/etc/pam.d/common-session?,添加
session required pam_limits.so
<3>修改conf/hbase-env.xml
? ? ?這里主要設(shè)置JAVA_HOME目錄,HBASE_LOG_DIR路徑以及啟用hbase自帶的zookeeper
點(diǎn)擊(此處)折疊或打開
? ? ?這里要將我們的hbase設(shè)置為偽分布模式,因此除了設(shè)置hbase的根目錄hbase.rootdir外,還需要設(shè)置hbase.cluster.distributed和hbase.zookeeper.quorum兩個(gè)參數(shù);至于zookeeper.znode.parent是指定zookeeper的相對目錄。
點(diǎn)擊(此處)折疊或打開
<5>運(yùn)行測試 ? ? ?
? ? ??然后同樣將hbase下的bin目錄加入到PATH中,運(yùn)行start-hbase.sh后發(fā)現(xiàn)HMaster未啟動,查看日志發(fā)現(xiàn)以下提示:
FATAL: org.apache.hadoop.hbase.master.HMaster: Unhandled exception. Starting shutdown. java.io.IOException:
Call to localhost/127.0.0.1:9000 failed on local exception: java.io.EOFException
? ? ??原因是需要將hadoop中的hadoop-core-1.0.4.jar覆蓋掉hbase-0.90.0/lib下的hadoop-core-0.20-append-r1056947.jar文件,再次運(yùn)行提示了新錯(cuò)誤:java.lang.NoClassDefFoundError
? ? ?看來是找不到相關(guān)的類,所以我們需要將hadoop-1.0.3下lib目錄的jar文件全部拷貝到hbase下的lib目錄下,再次運(yùn)行,順利通過:
<5>運(yùn)行hbase shell
? ? ?Hbase為我們提供了shell接口進(jìn)行測試,可以使用create命令創(chuàng)建一個(gè)新表,然后利用put命令添加新的行,使用scan命令查看建立的表:
? ? ?好了,hadoop和hbase的安裝到此基本結(jié)束,明天開始配置Sleuthkit。
總結(jié)
以上是生活随笔為你收集整理的Hadoop与Hbase基本配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Fedora 安装
- 下一篇: Hadoop DFS源码研究之---Ha