標籤:
在Mac上安裝Hadoop
對我這個之前從未接觸過*nix的使用者來說,使用命令列來做一系列的事情還是廢了一番功夫。特寫這個記錄,以做備份。
擷取Java
我的Mac啟動並執行作業系統是OS X 10.7 Lion,之前已經安裝過Java了,可以在工具 + 生產力->終端中使用java -version命令來確認java的版本。如果沒有安裝java,也可以進入下面網址下載:http://support.apple.com/kb/dl1421。
擷取Hadoop
具體的地址自己百度吧。我下載的是1.0.4的stable版本。
下載完之後解壓縮,我這裡放置的目錄是/users/Billy/Hadoop。
設定環境變數
在實際啟動Hadoop之前,有三個檔案需要進行配置。
但在這之前,我們需要設定一下幾個類似Windows的環境變數,方便以後在命令列敲命令。
export HADOOP_HOME=/users/billy/hadoop
export PATH=$PATH:$HADOOP_HOME/bin
配置hadoop-env.sh
在Hadoop->conf目錄下,找到hadoop-env.sh,開啟編輯進行如下設定:
export JAVA_HOME=/library/Java/Home(去掉注釋)
export HADOOP_HEAPSIZE=2000(去掉注釋)
export HADOOP_OPTS="-Djava.security.krb5.realm=OX.AC.UK -Djava.security.krb5.kdc=kdc0.ox.ac.uk:kdc1.ox.ac.uk"(去掉注釋)
注意第三個配置在OS X上最好進行配置,否則會報“Unable to load realm info from SCDynamicStore”。
配置core-site.xml <?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/users/billy/hadoop/tmp/hadoop-${user.name}</value>
<description>A base for other temporary directories.</description>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:8020</value>
</property>
</configuration>
配置hdfs-site.xml<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
配置mapred-site.xml
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>localhost:8021</value>
</property>
<property>
<name>mapred.tasktracker.map.tasks.maximum</name>
<value>2</value>
</property>
<property>
<name>mapred.tasktracker.reduce.tasks.maximum</name>
<value>2</value>
</property>
</configuration>
安裝HDFS
經過以上的配置,就可以進行HDFS的安裝了。
$HADOOP_HOME/bin/hadoop name node -format
如果順利的話,會得到類似如下的輸出:
BillymatoMacBook-Air:hadoop Billy$ $HADOOP_HOME/bin/hadoop namenode -format
Warning: $HADOOP_HOME is deprecated.
12/12/02 17:11:12 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG: host = BillymatoMacBook-Air.local/192.168.1.102
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 1.0.4
STARTUP_MSG: build = https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1.0 -r 1393290; compiled by ‘hortonfo‘ on Wed Oct 3 05:13:58 UTC 2012
************************************************************/
12/12/02 17:11:12 INFO util.GSet: VM type = 64-bit
12/12/02 17:11:12 INFO util.GSet: 2% max memory = 39.9175 MB
12/12/02 17:11:12 INFO util.GSet: capacity = 2^22 = 4194304 entries
12/12/02 17:11:12 INFO util.GSet: recommended=4194304, actual=4194304
12/12/02 17:11:12 INFO namenode.FSNamesystem: fsOwner=Billy
12/12/02 17:11:12 INFO namenode.FSNamesystem: supergroup=supergroup
12/12/02 17:11:12 INFO namenode.FSNamesystem: isPermissionEnabled=true
12/12/02 17:11:12 INFO namenode.FSNamesystem: dfs.block.invalidate.limit=100
12/12/02 17:11:12 INFO namenode.FSNamesystem: isAccessTokenEnabled=false accessKeyUpdateInterval=0 min(s), accessTokenLifetime=0 min(s)
12/12/02 17:11:13 INFO namenode.NameNode: Caching file names occuring more than 10 times
12/12/02 17:11:13 INFO common.Storage: Image file of size 111 saved in 0 seconds.
12/12/02 17:11:13 INFO common.Storage: Storage directory /users/Billy/hadoop/tmp/hadoop-Billy/dfs/name has been successfully formatted.
12/12/02 17:11:13 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at BillymatoMacBook-Air.local/192.168.1.102
************************************************************/
啟動Hadoop
很簡單,一條命令搞定。
$HADOOP_HOME/bin/start-all.sh
順利的話,一般會讓你輸入三次帳號的密碼。
簡單調試
如果想試試看是否已經成功啟動,可以用內建的例子實驗一下:
$hadoop jar $HADOOP_HOME/hadoop-example-1.0.4.jar pi 10 100
成功的話,會有類似結果:
BillymatoMacBook-Air:hadoop Billy$ hadoop jar $HADOOP_HOME/hadoop-examples-1.0.4.jar pi 10 100
Warning: $HADOOP_HOME is deprecated.
Number of Maps = 10
Samples per Map = 100
Wrote input for Map #0
Wrote input for Map #1
Wrote input for Map #2
Wrote input for Map #3
Wrote input for Map #4
Wrote input for Map #5
Wrote input for Map #6
Wrote input for Map #7
Wrote input for Map #8
Wrote input for Map #9
到這裡,單節點的Hadoop就在Mac OS X上安裝完成了。進入你的Hadoop世界吧!
基於MAC OS 作業系統安裝、配置hadoop