hadoop 完全分佈式搭建(帶配置文件)

 首先是 n 臺 建立好的虛擬機, 我用的是3臺.

在虛擬機上安裝 好java

修改etc/hosts 文件
192.168.1.111   h1
192.168.1.112   h2
192.168.1.113   h3
 
  1. 192.168.1.111   h1 
  2. 192.168.1.112   h2 
  3. 192.168.1.113   h3 
  4.  
  5.  
  6. # Do not remove the following line, or various programs 
  7. # that require network functionality will fail. 
  8. 127.0.0.1        localhost.localdomain localhost 
  9. ::1     localhost6.localdomain6 localhost6 
添加 hadoop 運行賬號
 
添加ssh 密鑰
ssh-keygen -t rsa
cp id_rsa.pub authorized_keys

配置hadoop-env.sh 
 
  1. # The java implementation to use.  Required. 
  2. export JAVA_HOME=/usr/java/jdk1.7.0_15 
然後是 3大配置文件 
core-site.xml
 
  1. <?xml version="1.0"?> 
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> 
  3.  
  4. <!-- Put site-specific property overrides in this file. --> 
  5.  
  6. <configuration> 
  7. <property> 
  8.   <name>fs.default.name</name> 
  9.   <value>hdfs://h1:9000</value> 
  10. </property> 
  11.  
  12. <!--臨時文件存放路徑--> 
  13. <property> 
  14.   <name>hadoop.tmp.dir</name> 
  15.   <value>/home/root/hadoop/tmp</value> 
  16. </property> 
  17.  
  18. <!--垃圾回收 如果是0 的話關閉--> 
  19. <property> 
  20.   <name>fs.trash.interval</name> 
  21.   <value>1400</value> 
  22.   <description>Number of minutes between trash checkpoints. 
  23.   If zero, the trash feature is disabled. 
  24.   </description> 
  25. </property> 
  26. </configuration> 
附加:
fs.trash.interval  垃圾間隔
如果爲0 則取消垃圾回收
 
 
hdfs-site.xml
 
  1. <?xml version="1.0"?> 
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> 
  3.  
  4. <!-- Put site-specific property overrides in this file. --> 
  5.  
  6. <configuration> 
  7.  
  8. <property> 
  9.   <name>dfs.data.dir</name> 
  10.   <value>${hadoop.tmp.dir}/dfs/data</value> 
  11.   <description>Determines where on the local filesystem an DFS data node 
  12.   should store its blocks.  If this is a comma-delimited 
  13.   list of directories, then data will be stored in all named 
  14.   directories, typically on different devices. 
  15.   Directories that do not exist are ignored. 
  16.   </description> 
  17. </property> 
  18. <!--備份的節點數  一共3臺虛擬機 一個是master 兩個是 slaves  備份數就是2 --> 
  19. <property> 
  20.   <name>dfs.replication</name> 
  21.   <value>2</value> 
  22.   <description>Default block replication.  
  23.   The actual number of replications can be specified when the file is created. 
  24.   The default is used if replication is not specified in create time. 
  25.   </description> 
  26. </property> 
  27. <!--指定塊的百分比,應該滿足 
  28. 最小的複製要求定義爲最小dfs複製。 
  29. 值小於或等於0的意思不是在安全模式啓動。 
  30. 值大於1將使安全模式永久。 
  31. --> 
  32. <property> 
  33.   <name>dfs.safemode.threshold.pct</name> 
  34.   <value>1</value> 
  35.   <description> 
  36.     Specifies the percentage of blocks that should satisfy  
  37.     the minimal replication requirement defined by dfs.replication.min. 
  38.     Values less than or equal to 0 mean not to start in safe mode. 
  39.     Values greater than 1 will make safe mode permanent. 
  40.   </description> 
  41. </property> 
  42.  
  43. <!--hdfs 的權限 設置, 由於是在win 下邊的eclipse開發,爲防止權限問題 ,把權限設置爲false 關閉掉--> 
  44. <property> 
  45.   <name>dfs.permissions</name> 
  46.   <value>false</value> 
  47.   <description> 
  48.     If "true", enable permission checking in HDFS. 
  49.     If "false", permission checking is turned off, 
  50.     but all other behavior is unchanged. 
  51.     Switching from one parameter value to the other does not change the mode, 
  52.     owner or group of files or directories. 
  53.   </description> 
  54. </property> 
  55. </configuration> 
mapred-site.xml
 
  1. <?xml version="1.0"?> 
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> 
  3.  
  4. <!-- Put site-specific property overrides in this file. --> 
  5.  
  6. <configuration> 
  7. <property> 
  8.   <name>mapred.job.tracker</name> 
  9.   <value>h1:9001</value> 
  10. </property> 
  11. </configuration> 
 
配置 master 和slaves
 
master 
 
  1. h1 
slaves
 
  1. h2 
  2. h3 
複製到 其他節點
scp -r ./hadoop h1:~  
 
然後格式化 節點
hadoop namenode -format
 
注意事項:
如果沒有吧 hadoop 添加到環境變量中 ,需要在 hadoop /bin  中執行 命令;

防火牆最好關掉,否則會連接不上

iptables 防火牆的設置

查看防火牆狀態:sudo service iptables status
暫時關閉防火牆:sudo service  iptables stop
禁止防火牆在開機時啓動chkconfig iptables off
設置防火牆在開機時啓動chkconfig iptables on

 

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