環境:ubuntu 10.10 JDK1.6.0.27 hadoop 0.20.2
一. ubuntu 下JDK 的安裝:
1. 下載jdk-6u27-linux-i586.bin
2. 拷貝到/usr/java,設定檔案的操作許可權
3. $ ./jdk-6u27-linux-i586.bin開始安裝
4. 設定環境變數vi /etc/profile 在檔案最後添加
JAVA_HOME=/usr/Java/jdk1.6.0_27
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH JAVA_HOME CLASSPATH
5. 設定使用者安裝的JDK為預設JDK,執行
$ update-alternatives --install /usr/bin/java java /usr/lib/jvm/java/jdk1.6.0_12/bin/java 300
$ update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java/jdk1.6.0_12/bin/javac 300
$ update-alternatives --config java
6. 輸入java -version 成功安裝
二.ubuntu下安裝ssh:
1. $ sudo apt-get install openssh-server
2. 啟動ssh /etc/init.d/ssh start
3. $ ps -e | grep ssh 來驗證是否啟動sshserver
4. 免密碼化
$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
三.ubuntu 下安裝hadoop:
1. 下載hadoop-0.20.2.tar.gz,放在/usr/hadoop http://apache.etoak.com//hadoop/core/
2. 解壓$ tar zxvf hadoop-0.20.2.tar.gz
3. 修改hadoop設定檔
conf/hadoop-env.sh 修改JAVA_HOME選項:
export JAVA_HOME=/usr/java/jdk.1.6.0_27
4. 偽分布式單機配置
conf/core-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>fs.default.name</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
conf/hdfs-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>dfs.replication</name>
<value>1</value>
</property>
</configuration>
conf/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>
5. 建立hdfs檔案系統
$ bin/hadoop namenode -format
6. 啟動hadoop 需要先啟動ssh $ /etc/init.d/ssh start
$ bin/hadoop start-all.sh
7. 在hadoop下建立test目錄,然後建立file1.txt file2.txt 寫入幾個單詞;將hadoop/test下的測試檔案上傳到hadoop 檔案系統中
$ bin/hadoop dfs -put ./test input
8. 運行wordCount例子
$ bin/hadoop jar hadoop-0.20.2-examples.jar wordcount input output
9. 把結果從dfs上拷貝下來
$ bin/hadoop dfs -get output output
10. 查看結果
$ cat output/* 也可以直接查看$ bin/hadoop dfs -cat output/*
11. 停止hadoop運行
$ bin/hadoop stop-all.sh
12. 關閉ssh-server
$ /etc/init.d/ssh stop
摘自:daniel的專欄