[原]Hadoop分布式集群搭建

周攀 17/07/14 18:50:05

前面分享了hadoop伪分布式的搭建方法,这次来分享一下分布式方式的搭建方法。
主机安装或虚拟机安装这里就不再赘述,下面直接进入正题:

1.下面是网络配置,全部为静态:

master : 192.168.80.128
slave-1 : 192.168.80.129
slave-2 : 192.168.80.130
slave-3 : 192.168.80.131
slave-4 : 192.168.80.132

2.修改hosts,加入如下内容:

192.168.80.128 master
192.168.80.129 slave1
192.168.80.130 slave2
192.168.80.131 slave3
192.168.80.132 slave4

3.修改各个主机的hostname,为对应的名字

4.配置SSH免密码登陆,保证五台主机任意之间可以免密码访问

5.关闭五台主机防火墙

$ sudo systemctl stop firewalld.service
$ sudo systemctl disable firewalld.service

必须关闭防火网,否则在存储文件时,可能会出现以下错误:

[zhoupan@master ~]$ hadoop-2.8.0/bin/hadoop fs -put hadoop-2.8.0.tar.gz /data
17/07/14 01:47:58 WARN hdfs.DataStreamer: DataStreamer Exception
org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /input/hadoop-2.8.0.tar.gz._COPYING_ could only be replicated to 0 nodes instead of minReplication (=1).  There are 0 datanode(s) running and no node(s) are excluded in this operation.
    at org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.chooseTarget4NewBlock(BlockManager.java:1733)
    at org.apache.hadoop.hdfs.server.namenode.FSDirWriteFileOp.chooseTargetForNewBlock(FSDirWriteFileOp.java:265)
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem.java:2496)
    at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.addBlock(NameNodeRpcServer.java:828)
    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.addBlock(ClientNamenodeProtocolServerSideTranslatorPB.java:506)
    at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)
    at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:447)
    at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:989)
    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:845)
    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:788)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:422)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1807)
    at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2455)

    at org.apache.hadoop.ipc.Client.getRpcResponse(Client.java:1481)
    at org.apache.hadoop.ipc.Client.call(Client.java:1427)
    at org.apache.hadoop.ipc.Client.call(Client.java:1337)
    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:227)
    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:116)
    at com.sun.proxy.$Proxy10.addBlock(Unknown Source)
    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.addBlock(ClientNamenodeProtocolTranslatorPB.java:440)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:398)
    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invokeMethod(RetryInvocationHandler.java:163)
    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invoke(RetryInvocationHandler.java:155)
    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invokeOnce(RetryInvocationHandler.java:95)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:335)
    at com.sun.proxy.$Proxy11.addBlock(Unknown Source)
    at org.apache.hadoop.hdfs.DataStreamer.locateFollowingBlock(DataStreamer.java:1733)
    at org.apache.hadoop.hdfs.DataStreamer.nextBlockOutputStream(DataStreamer.java:1536)
    at org.apache.hadoop.hdfs.DataStreamer.run(DataStreamer.java:658)
put: File /input/hadoop-2.8.0.tar.gz._COPYING_ could only be replicated to 0 nodes instead of minReplication (=1).  There are 0 datanode(s) running and no node(s) are excluded in this operation.
[zhoupan@master ~]$ ls

6.配置java环境

export JAVA_HOME=/usr/local/jdk1.8.0_131
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH

7.下载hadoop二进制安装文件

$ wget http://www.apache.org/dyn/closer.cgi/hadoop/common/hadoop-2.8.0/hadoop-2.8.0.tar.gz

8.假设安装包放在家目录下,解压文件:

$ tar -zvxf hadoop-2.8.0.tar.gz

9.在~/hadoop-2.8.0下创建tmp,hdfs/data/,hdfs/name 目录

$ mkdir ~/hadoop-2.8.0/tmp
$ mkdir ~/hadoop-2.8.0/hdfs
$ mkdir ~/hadoop-2.8.0/hdfs/data
$ mkdir ~/hadoop-2.8.0/hdfs/name

10.修改~/hadoop-2.8.0/etc/hadoop/core-site.xml 文件为一下内容:

<configuration>
    <property>
        <!--下面配置文件用来指出NameNode的IP地址及其端口-->
        <name>fs.default.name</name>
        <value>hdfs://192.168.80.128:9000</value>
    </property>
    <property>
        <!--hadoop的本地临时文件夹,默认是在/tmp下的,为了方式由于重启被清空,建议将其修改至其他目录-->
        <name>hadoop.tmp.dir</name>
        <value>file:/home/zhoupan/hadoop-2.8.0/tmp</value>
    </property>
</configuration>

11.创建~/hadoop-2.8.0/etc/hadoop/mapred-site.xml 文件

cp ~/hadoop-2.8.0/etc/hadoop/mapred-site.xml.template ~/hadoop-2.8.0/etc/hadoop/mapred-site.xml

12.修改~/hadoop-2.8.0/etc/hadoop/mapred-site.xml文件为一下内容

<configuration>
    <property>
            <!--JobTracker的IP地址及端口-->
             <name>mapred.job.tracker</name>
            <value>192.168.80.128:9001</value>
    </property>
</configuration>

13.修改~/hadoop-2.8.0/etc/hadoop/yarn-site.xml为如下内容

<configuration>
    <property>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce_shuffle</value>
    </property>
    <property>
        <name>yarn.nodemanager.auxservices.mapreduce.shuffle.class</name>
        <value>org.apache.hadoop.mapred.ShuffleHandler</value>
    </property>
    <property>
        <name>yarn.resourcemanager.address</name>
        <value>master:8032</value>
    </property>
    <property>
        <name>yarn.resourcemanager.scheduler.address</name>
        <value>master:8030</value>
    </property>
    <property>
        <name>yarn.resourcemanager.resource-tracker.address</name>
        <value>master:8031</value>
    </property>
    <property>
        <name>yarn.resourcemanager.admin.address</name>
        <value>master:8033</value>
    </property>
    <property>
        <name>yarn.resourcemanager.webapp.address</name>
        <value>master:8088</value>
    </property>
</configuration>

14.修改~/hadoop-2.8.0/etc/hadoop/hdfs-site.xml为如下内容

<configuration>
    <property>
        <!--NameNode存储命名空间和汇报日志的位置-->
        <name>dfs.namenode.name.dir</name>
        <value>file:/home/zhoupan/hadoop-2.8.0/hdfs/name</value>
    </property>
    <property>
        <!--DataNode存储数据块的位置-->
        <name>dfs.datanode.data.dir</name>
        <value>file:/home/zhoupan/hadoop-2.8.0/hdfs/data</value>
    </property>
</configuration>

15.修改修改~/hadoop-2.8.0/etc/hadoop/slaves为如下内容

slave1
slave2
slave3
slave4

16.格式化Namenode

$ ~/hadoop-2.8.0/bin/hadoop namenode -format

17.启动集群:

$ ~/hadoop-2.8.0/sbin/start-all.sh

18.查看运行情况:

$ jps

master

这里写图片描述

slave

这里写图片描述

19.测试文件存储

$ ~/hadoop-2.8.0/bin/hadoop fs -mkdir /data
$ ~/hadoop-2.8.0/bin/hadoop fs -ls 

这里写图片描述

$ ~/hadoop-2.8.0/bin/hadoop fs -put hadoop-2.8.0.tar.gz /data/
$ ~/hadoop-2.8.0/bin/hadoop fs -ls /
$ ~/hadoop-2.8.0/bin/hadoop fs -ls /data/

这里写图片描述

至此,hadoop算是搭建成功了。

作者:IT_DREAM_ER 发表于 2017/07/14 18:50:05 原文链接 https://blog.csdn.net/IT_DREAM_ER/article/details/75126020
阅读:403