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

 

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