Ubuntu下偽分布式模式Hadoop的安裝及配置


1、Hadoop運行模式
Hadoop有三種運行模式,分別如下:
單機(非分布式)模式
偽分布式(用不同進程模仿分布式運行中的各類節點)模式
完全分布式模式
注:前兩種可以在單機運行,最后一種用於真實的集群環境,通常用在生產環境上。我們可以搭建本地的偽分布式模式來模擬分布式環境的執行。

2、Hadoop的安裝及配置
環境:Ubuntu10.10,Hadoop 0.21.0
安裝步驟如下:
1、准備工作:
1)、安裝ssh server,如何安裝ssh server請看http://www.tieguanyin168.com/index.php/ubuntu-ssh-1650.html
2)、安裝sun jdk6,切忌一定要java6及其以上版本,如何安裝jdk6請看http://www.tieguanyin168.com/index.php/ubuntu-jdk-1631.html

2、增加一個用戶組用戶,用於hadoop運行及訪問。
root@ubuntu:~# sudo addgroup hadoop
root@ubuntu:~# sudo adduser –ingroup hadoop hadoop

3、生成SSH證書,配置SSH加密key
hadoop@ubuntu:~$ su – hadoop
Password:
hadoop@ubuntu:~$ ssh-keygen -t rsa -P ""
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hadoop/.ssh/id_rsa):
Your identification has been saved in /home/hadoop/.ssh/id_rsa.
Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub.
The key fingerprint is:
a8:67:6f:bd:04:13:41:5f:a7:13:2d:84:e7:8a:8c:43 hadoop@ubuntu
The key's randomart image is:
+–[ RSA 2048]—-+
|       .o  o+..  |
|         o..o+.  |
|        . .oo.   |
|      E. .  ..   |
|     ..oS. .     |
|     .o oo.      |
|    . o. ..      |
|     o ….      |
|       .. ..     |
+—————–+
hadoop@ubuntu:~$

hadoop@ubuntu:~$ cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
hadoop@ubuntu:~$

4、配置完成,測試一下:
hadoop@ubuntu:~$ ssh localhost
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is d7:87:25:47:ae:02:00:eb:1d:75:4f:bb:44:f9:36:26.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
Linux ubuntu 2.6.32-22-generic #33-Ubuntu SMP Wed Apr 28 13:27:30 UTC 2010 i686 GNU/Linux
Ubuntu 10.04 LTS
[...snipp...]
hadoop@ubuntu:~$

5、禁用ipV6配置:
打開sudo gedit /etc/sysctl.conf,此文件需要root權限。
再次打開文件中,追加如下:
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

重啟,測試是否配置成功:
$ cat /proc/sys/net/ipv6/conf/all/disable_ipv6
如果是1就ok了。

下面就是安裝Hadoop(Hadoop保存在/home目錄下)了。
首先是:下載,解壓縮,分配權限。
下載就不說了。
下載后運行如下:
root@ubuntu:~# cd /home
root@ubuntu:/home# ls
apache-tomcat-6.0.18  jdk1.6.0_30              study
hadoop                jdk-6u30-linux-i586.bin  ubuntu
hadoop-0.21.0.tar.gz  ljq                      web.war
root@ubuntu:/home# sudo tar xzf hadoop-0.21.0.tar.gz
root@ubuntu:/home# ls
apache-tomcat-6.0.18  hadoop-0.21.0.tar.gz     ljq     web.war
hadoop                jdk1.6.0_30              study
hadoop-0.21.0         jdk-6u30-linux-i586.bin  ubuntu
root@ubuntu:/home# sudo mv hadoop-0.21.0 hadoop
root@ubuntu:/home# sudo chown -R hadoop:hadoop hadoop #chown [OPTION]  [OWNER][:[GROUP]]  FILE
root@ubuntu:/home#

到此就安裝完畢。

配置環境變量(共有4處要配置)
1、在/home/hadoop/hadoop-0.21.0/conf/hadoop-env.sh文件中添加環境變量信息。
2、在/etc/profile文件中添加環境變量信息。
3、在/home/.bash_profile文件中添加環境變量信息。
4、在/home/hadoop/.bashrc文件中添加環境變量信息。

環境變量信息如下:

1
2
3
4
5
6
7
8
HADOOP_HOME= /home/hadoop/hadoop-0 .21.0
JAVA_HOME= /home/jdk1 .6.0_30
PATH=$JAVA_HOME /bin :$HADOOP_HOME /bin :$PATH
CLASSPATH=.:$JAVA_HOME /lib/dt .jar:$JAVA_HOME /lib/tools .jar:$HADOOP_HOME /lib :$CLASSPATH
export HADOOP_HOME
export JAVA_HOME
export PATH
export CLASSPATH

重啟,接着驗證環境變量是否配置成功,如下:
export、echo $HADOOP_HOME、java -version

下面說說如何配置和啟動:
基本思路是配置core-site.xml、mapred-site.xml、hdfs-site.xml。
首先建立一個用來存放數據的目錄:mkdir /home/hadoop/hadoop-datastore

打開/home/hadoop/hadoop-0.21.0/conf/core-site.xml,配置如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
< configuration >
   < property >
     < name >hadoop.tmp.dir</ name >
     < value >/home/hadoop/hadoop-datastore/</ value >
     < description >A base for other temporary directories.</ description >
   </ property >
 
   < property >
   <!-- fs.default.name 指定NameNode的IP地址和端口號-->
     < name >fs.default.name</ name >
     < value >hdfs://localhost:54310</ value >
     < description >The name of the default file system.  A URI whose
   scheme and authority determine the FileSystem implementation.  The
   uri's scheme determines the config property (fs.SCHEME.impl) naming
   the FileSystem implementation class.  The uri's authority is used to
   determine the host, port, etc. for a filesystem.</ description >
   </ property >
</ configuration >

打開/home/hadoop/hadoop-0.21.0/conf/mapred-site.xml,配置如下

1
2
3
4
5
6
7
8
9
10
< configuration >
< property >
   < name >mapred.job.tracker</ name >
   < value >localhost:54311</ value >
   < description >The host and port that the MapReduce job tracker runs
   at.  If "local", then jobs are run in-process as a single map
   and reduce task.
   </ description >
</ property >
</ configuration >

打開/home/hadoop/hadoop-0.21.0/conf/hdfs-site.xml,配置如下

1
2
3
4
5
6
7
8
9
10
< configuration >
< property >
<!--block的副本數,默認為3;你可以設置為1 這樣每個block只會存在一份。-->
   < name >dfs.replication</ name >
   < value >1</ value >
   < description >Default block replication.
   The actual number of replications can be specified when the file is created.
   The default is used if replication is not specified in create time.
   </ description >
</ property >
</ configuration >

ok,配置完畢

格式化HDFS:
hadoop@ubuntu:~$ /home/hadoop/hadoop-0.21.0/bin/hadoop namenode -format

啟動HDFS和MapReduce
hadoop@ubuntu:~/hadoop-0.21.0/bin$ ./start-all.sh

停止服務的腳本是:
hadoop@ubuntu:~/hadoop-0.21.0/bin$ ./stop-all.sh

通過jps查看進程是否啟動成功
hadoop@ubuntu:~/hadoop-0.21.0/bin$ jps
5695 DataNode
5503 NameNode
6181 TaskTracker
6222 Jps
5890 SecondaryNameNode
5991 JobTracker
hadoop@ubuntu:~/hadoop-0.21.0/bin$
出現如上信息,表示hadoop啟動成功,缺一不可。

netstat -at|grep 50030
netstat -at|grep 50070
查看端口是否正常

注意:有時候有些啟動不成功,可以在/home/hadoop/hadoop-0.21.0/logs/查看日志信息進行診斷。

訪問http://localhost:50070可以看到NameNode以及整個分布式文件系統的狀態,瀏覽分布式文件系統中的文件以及日志等。
訪問http://localhost:50030可以查看JobTracker的運行狀態。

50070是dfs的端口,50030是MR的端口。

參考資料
Ubuntu下安裝及配置單點hadoop
http://www.hadoopor.com/thread-2674-1-1.html
hadoop常見異常總結:
http://www.tieguanyin168.com/index.php/hadoop-exception-1706.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM