hadoop-2.6分布式集群环境搭建

1.背景

   上篇记录了hadoop的核心配置和zookeeper的基本配置,这篇将我的配置记录下,包括启动过程的总结!简单的分布式环境搭建了四遍,也算是懂些了皮毛,总算是可以启动了!我的运行环境这里不在详述。还是声明一点,所有的均是在root用户下完成的!


2.Hadoop 配置

   2.1 etc/hadoop 目录下

        先进入 该目录下 :

[plain]  view plain  copy
  1. root@note1:~/hadoop-2.6/etc/hadoop#   

     (1)hadoop-env.sh 

              配置JAVA运行环境 , JAVA_HOME ;

[html]  view plain  copy
  1. root@note1:~/hadoop-2.6/etc/hadoop# vi hadoop-env.sh   

              

 

   (2) core-site.xml

[html]  view plain  copy
  1. root@note1:~/hadoop-2.6/etc/hadoop# more core-site.xml   

   全部配置如下 :

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  
  3. <!--  
  4.   Licensed under the Apache License, Version 2.0 (the "License");  
  5.   you may not use this file except in compliance with the License.  
  6.   You may obtain a copy of the License at  
  7.   
  8.     http://www.apache.org/licenses/LICENSE-2.0  
  9.   
  10.   Unless required by applicable law or agreed to in writing, software  
  11.   distributed under the License is distributed on an "AS IS" BASIS,  
  12.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  13.   See the License for the specific language governing permissions and  
  14.   limitations under the License. See accompanying LICENSE file.  
  15. -->  
  16.   
  17. <!-- Put site-specific property overrides in this file. -->  
  18.   
  19. <configuration>  
  20.   
  21. <property>  
  22.   <name>fs.defaultFS</name>  
[html]  view plain  copy
  1. <pre name="code" class="html">  <value>hdfs://yuannews</value>  
</property>   

<property> <name>ha.zookeeper.quorum</name> <value>note1:2181,note3:2181,note4:2181</value> </property><property> <name>hadoop.tmp.dir</name> <value>/opt/hadoop2</value></property></configuration>

 


  (3)hdfs-site.xml

[html]  view plain  copy
  1. root@note1:~/hadoop-2.6/etc/hadoop# cat hdfs-site.xml   


配置如下 :


[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  
  3. <!--  
  4.   Licensed under the Apache License, Version 2.0 (the "License");  
  5.   you may not use this file except in compliance with the License.  
  6.   You may obtain a copy of the License at  
  7.   
  8.     http://www.apache.org/licenses/LICENSE-2.0  
  9.   
  10.   Unless required by applicable law or agreed to in writing, software  
  11.   distributed under the License is distributed on an "AS IS" BASIS,  
  12.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  13.   See the License for the specific language governing permissions and  
  14.   limitations under the License. See accompanying LICENSE file.  
  15. -->  
  16.   
  17. <!-- Put site-specific property overrides in this file. -->  
  18.   
  19. <configuration>  
  20.   
  21.  <property>  
  22.   <name>dfs.nameservices</name>  
  23.   <value>yuannews</value>  
  24.  </property>  
  25.   
  26. <property>  
  27.   <name>dfs.ha.namenodes.yuannews</name>  
  28.   <value>nn1,nn2</value>  
  29. </property>  
  30.   
  31. <property>  
  32.   <name>dfs.namenode.rpc-address.yuannews.nn1</name>  
  33.   <value>note1:8020</value>  
  34. </property>  
  35. <property>  
  36.   <name>dfs.namenode.rpc-address.yuannews.nn2</name>  
  37.   <value>note3:8020</value>  
  38. </property>  
  39.   
  40. <property>  
  41.   <name>dfs.namenode.http-address.yuannews.nn1</name>  
  42.   <value>note1:50070</value>  
  43. </property>  
  44. <property>  
  45.   <name>dfs.namenode.http-address.yuannews.nn2</name>  
  46.   <value>note3:50070</value>  
  47. </property>  
  48.   
  49. <property>  
  50.   <name>dfs.namenode.shared.edits.dir</name>  
  51.   <value>qjournal://note3:8485;note4:8485;note5:8485/yuannews</value>  
  52. </property>  
  53.   
  54. <property>  
  55.   <name>dfs.client.failover.proxy.provider.yuannews</name>  
  56.   <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>  
  57. </property>  
  58.   
  59. <property>  
  60.   <name>dfs.ha.fencing.methods</name>  
  61.   <value>sshfence</value>  
  62. </property>  
  63.   
  64. <property>  
  65.   <name>dfs.ha.fencing.ssh.private-key-files</name>  
  66.   <value>/root/.ssh/id_rsa</value>  
  67. </property>  
  68.   
  69. <property>  
  70.   <name>dfs.journalnode.edits.dir</name>  
  71.   <value>/opt/hadoop/jn/data/</value>  
  72. </property>  
  73.   
  74. <property>  
  75.    <name>dfs.ha.automatic-failover.enabled</name>  
  76.    <value>true</value>  
  77.  </property>  
  78.   
  79.   
  80. </configuration>  

 (4)maperd-site.xml

          将 maperd-site.xml.template 重命名为 mapred-site.xml 

[html]  view plain  copy
  1. root@note1:~/hadoop-2.6/etc/hadoop# mv mapred-site.xml.template mapred-site.xml  

        配置如下 :

 

[html]  view plain  copy
  1. <?xml version="1.0"?>  
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  
  3. <!--  
  4.   Licensed under the Apache License, Version 2.0 (the "License");  
  5.   you may not use this file except in compliance with the License.  
  6.   You may obtain a copy of the License at  
  7.   
  8.     http://www.apache.org/licenses/LICENSE-2.0  
  9.   
  10.   Unless required by applicable law or agreed to in writing, software  
  11.   distributed under the License is distributed on an "AS IS" BASIS,  
  12.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  13.   See the License for the specific language governing permissions and  
  14.   limitations under the License. See accompanying LICENSE file.  
  15. -->  
  16.   
  17. <!-- Put site-specific property overrides in this file. -->  
  18.   
  19. <configuration>  
  20.  <property>  
  21.    <name>mapreduce.framework.name</name>  
  22.    <value>yarn</value>  
  23.  </property>  
  24. </configuration>  

  (5)yarn-site.xml

[html]  view plain  copy
  1. root@note1:~/hadoop-2.6/etc/hadoop# more yarn-site.xml   

   配置如下 :配置 主运行节点,我的是 note1 ;

[html]  view plain  copy
  1. <?xml version="1.0"?>  
  2. <!--  
  3.   Licensed under the Apache License, Version 2.0 (the "License");  
  4.   you may not use this file except in compliance with the License.  
  5.   You may obtain a copy of the License at  
  6.   
  7.     http://www.apache.org/licenses/LICENSE-2.0  
  8.   
  9.   Unless required by applicable law or agreed to in writing, software  
  10.   distributed under the License is distributed on an "AS IS" BASIS,  
  11.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  12.   See the License for the specific language governing permissions and  
  13.   limitations under the License. See accompanying LICENSE file.  
  14. -->  
  15. <configuration>  
  16.   
  17. <!-- Site specific YARN configuration properties -->  
  18.   
  19.     <property>  
  20.         <name>yarn.resourcemanager.hostname</name>  
  21.         <value>note1</value>  
  22.     </property>  
[html]  view plain  copy
  1.     <property>  
  2.         <name>yarn.nodemanager.aux-services</name>  
  3.         <value>mapreduce_shuffle</value>  
  4.     </property>  
  5.   
  6.     <property>  
  7.         <name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>  
  8.         <value>org.apache.hadoop.mapred.ShuffleHandler</value>  
  9.     </property>  
  10.   
  11. </configuration>  


   (6)slaves

        配置其他集群机子地址,相当于 datanode 所在的地址!

配置如下 :

[html]  view plain  copy
  1. 192.168.56.3  
  2. 192.168.56.4  
  3. 192.168.56.5  

     (7) 配置总结

          上面配置的 dfs.journalnode.edits.dir 的时候,需要手动创建该目录,其余的就是服务名称了,一定要对!



3.zookeeper配置

   (1)zoo.cfg

[html]  view plain  copy
  1. root@note1:~/zookeeper-3.4.6/conf# more zoo.cfg   


            将 zoo.simple.cfg 重命名为 zoo.cfg , 配置如下 :

  

[html]  view plain  copy
  1. # The number of milliseconds of each tick  
  2. tickTime=2000  
  3. # The number of ticks that the initial   
  4. # synchronization phase can take  
  5. initLimit=10  
  6. # The number of ticks that can pass between   
  7. # sending a request and getting an acknowledgement  
  8. syncLimit=5  
  9. # the directory where the snapshot is stored.  
  10. # do not use /tmp for storage, /tmp here is just   
  11. # example sakes.  
  12. dataDir=/opt/zookeeper  
  13. # the port at which the clients will connect  
  14. clientPort=2181  
  15. # the maximum number of client connections.  
  16. # increase this if you need to handle more clients  
  17. maxClientCnxns=60  
  18. #  
  19. # Be sure to read the maintenance section of the   
  20. # administrator guide before turning on autopurge.  
  21. #  
  22. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance  
  23.   
  24. # The number of snapshots to retain in dataDir  
  25. autopurge.snapRetainCount=3  
  26. # Purge task interval in hours  
  27. # Set to "0" to disable auto purge feature  
  28. autopurge.purgeInterval=1  
  29. server.1=note1:2888:3888  
  30. server.2=note3:2888:3888  
  31. server.3=note4:2888:3888  


         注意 :
      (1)手动创建 dataDir 目录,我的是 /opt/zookeeper 

        (2)   在该目录下创建 /opt/zookeeper 目录下,创建 myid 文件 ,文件内容为 上面zoo.cfg配置文件的最后的 server.x 的x , 规则 如下: 

            1)m节点机子运行zookeeper,在m上,复制zookeeper的程序,即解压出来的,并且相同的配置!

            2)每个节点机子上都创建 dataDir目录,并创建myid文件

            3)myid 文件内容与 zoo.cfg 最后的对应,比如 server.2=note3:2888:3888 , 那么note3节点机子上的myid 内容为 2,仅仅一个2 ,就可以了,依次类推!

            

    (2)全局配置

            将 zookeeper的bin 目录配置到 /etc/profile文件中,我的如下 :

[html]  view plain  copy
  1. export PATH=$PATH:/root/zookeeper-3.4.6/bin  

                        


别忘了 ,执行 source /etc/profile !

      (3)zookeeper 测试启动过程

[html]  view plain  copy
  1. zkServer.sh start  


 4.初始化过程

   (1)测试启动 journalnode 

            进入 hadoop/sbin 目录

[html]  view plain  copy
  1. ./hadoop-daemon.sh start journalnode  

   (2)格式化一台namenode

            我的有两台namenode , 在 所以在 一台机子上进行 格式化 namenode,这里成为namenode1 , 其他的不需要格式化,但是需要进行以后的操作;

          

[html]  view plain  copy
  1. root@note1:~/hadoop-2.6/bin# ./hdfs namenode -format  

   (3)初始化其他namenode

            已经格式化了 namenode1 , 现在初始化 namenode2 , 所以,先启动刚才格式化的 namenode1 :

[html]  view plain  copy
  1. root@note1:~/hadoop-2.6/sbin# ./hadoop-daemon.sh start namenode  

           后在 namenode2 的节点机子上执行 初始化操作:

[html]  view plain  copy
  1. root@note3:~/hadoop-2.6/bin# ./hdfs namenode -bootstrapStandby  

   (4)初始化 zkfc 

            前提是 ,在你配置的 zookeeper的机子上,启动 zookeeper (ZK), 然后才能格式化 zkfc , 否则,会报错!

   

[html]  view plain  copy
  1. root@note1:~/hadoop-2.6/bin# ./hdfs zkfc -formatZK  

   (5)启动与停止

[html]  view plain  copy
  1. start-dfs.sh 和 stop-dfs.sh  

     (6) 注意

           在启动的时候,如果发现没有启动的话,注意检查2点,节点机子ip是否可以 ping通 和 节点机子的防火墙是否关闭(有时候);


5.启动过程

      先启动 zookeeper , 在启动 hadoop -dfs , 后启动 hadoop - yarn ;  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值