Hadoop僞分佈模式搭建

        這兩天在看《Hadoop in Action》,嘗試着搭建僞分佈模式,即在“單節點集羣”運行Hadoop,步驟:

                1. 配置conf文件夾下hadoop-env.sh文件的JAVA_HOME環境變量指向Java安裝目錄

export JAVA_HOME=/usr/java/jre1.6.0_23

                2. 安裝SSH:包括ssh, sshd, ssh-keygen;

                3. 生成SSH密鑰對,不設置口令:

ssh-keygen -t rsa

                4. 設置授權密鑰:

ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
                 5. 配置conf下的幾個XML文件

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>
	<description>The name of the default file system. A URI whose scheme and authority determine the FileSystem implementation.
	</description>
</property>

</configuration>
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>
	<description>The host and port that the MapReduce job tracker runs at.
	</description>
</property>

</configuration>
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>
	<description>The actual number of replication can be specified when the file is created.
	</description>
</property>

</configuration>
                6. 啓動Hadoop的幾個守護進程
bin/start-all.sh

                7. 查看Hadoop的幾個守護進程,

jps

                如果正常應該可以看到以下結果,包括NameNode, DataNode, SecondaryNameNode, JobTracker, TaskTracker。

16982 DataNode
17249 SecondaryNameNode
16730 NameNode
17746 Jps
17364 JobTracker
17629 TaskTracker

                由於我之前配置的時候,SSH沒有設置密鑰授權,所以每次啓動一個守護進程時總要手動輸入一次機器密碼,進行步驟4之後可以解決這個問題。

                第一次啓動時可以看到NameNode,關掉再啓動時通過jps看不到NameNode解決方法:關掉這些進程(bin/stop-all.sh),重新格式化,再啓動,這時發現少了DataNode這個守護進程,重新格式化還是沒有,又重頭開始配置Hadoop,結果還是不行

                上網搜了一下,找到了解決方法

有時數據結構出現問題會產生無法啓動datanode的問題。
然後用 hadoop namenode -format  重新格式化後仍然無效,/tmp中的文件並沒有清除。
其實還需要清除/tmp/hadoop*裏的文件。
執行步驟:
     一、先刪除hadoop:/tmp 
       bin/hadoop fs -rmr /tmp
    二、停止 hadoop   
       bin/stop-all.sh
    三、刪除/tmp/hadoop*
       rm -rf /tmp/hadoop*
    四、格式化hadoop
       bin/hadoop namenode -format
    五、啓動hadoop 
        bin/start-all.sh
之後即可解決這個datanode沒法啓動的問題

                8. 檢查運行狀態

Hadoop管理界面:http://localhost:50030


Hadoop Task Tracker 狀態:http://localhost:50060


Hadoop DFS 狀態:http://localhost:50070


                9. 結束Hadoop

bin/stop-all.sh

參考文獻:

http://hi.baidu.com/xixitie/item/60da2daa926537ab29ce9d9a

http://blog.csdn.net/hitwengqi/article/details/8008203

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章