Hadoop2.7.4+Spark2.2.0滴滴云分布式集群搭建过程

1.在滴滴云申请三台服务器(CentOS系统64位7.3)

Master Worker1 Worker2
公网116.85.9.118 公网116.85.9.117 公网116.85.9.119
内网10.254.0.58 内网10.254.0.94 内网10.254.0.88
单核2G内存 单核1G内存 单核1G内存

2.修改hosts文件

修改三台服务器的hosts文件,vim /etc/hosts(需要权限加上sudo vim /etc/hosts),在原文件的基础最后面加上:

10.254.0.58 Master
10.254.0.94 Worker1
10.254.0.88 Worker2

修改完成后保存执行如下命令,可以让修改立即生效

source /etc/hosts

3.ssh无密码验证配置

参考ssh免密登陆,为了让几台机器之间可以互相免密登陆,可以把公私钥对上传到三台服务器上(为了方便使用同样的密钥,你也可以重新生成)

4.安装基础环境(JAVA和SCALA环境)

4.1安装Java

下载jdk-8u171-linux-x64.tar.gz,解压到/usr/local目录,配置环境变量,在/etc/profile中添加

export JAVA_HOME=/usr/local/jdk1.8.0_121
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/rt.jar
4.2安装scala

下载scala安装包scala-2.11.8.rpm安装,rpm -ivh scala-2.11.8.rpm
添加Scala环境变量,在/etc/profile中添加:

export SCALA_HOME=/usr/share/scala
export PATH=$SCALA_HOME/bin:$PATH
5.Hadoop2.7.4完全分布式搭建

首先在本地下载hadoop-2.7.4.tar.gz,使用命令将hadoop上传到Master

scp -r Documents/hadoop-2.7.4.tar.gz [email protected]:  
tar -zxvf hadoop-2.7.4.tar.gz
mv hadoop-2.7.4 /opt

修改/etc/profile,增加如下内容:

 export HADOOP_HOME=/opt/hadoop-2.7.4/
 export PATH=$PATH:$HADOOP_HOME/bin
 export PATH=$PATH:$HADOOP_HOME/sbin
 export HADOOP_MAPRED_HOME=$HADOOP_HOME
 export HADOOP_COMMON_HOME=$HADOOP_HOME
 export HADOOP_HDFS_HOME=$HADOOP_HOME
 export YARN_HOME=$HADOOP_HOME
 export HADOOP_ROOT_LOGGER=INFO,console
 export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
 export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib"

修改完成后执行:source /etc/profile
修改$HADOOP_HOME/etc/hadoop/hadoop-env.sh,修改JAVA_HOME 如下:

 export JAVA_HOME=/usr/local/jdk1.8.0_171

修改$HADOOP_HOME/etc/hadoop/slaves,将原来的localhost删除,改成如下内容:

Worker1
Worker2

修改$HADOOP_HOME/etc/hadoop/core-site.xml


      
          fs.defaultFS
          hdfs://Master:9000
      
      
         io.file.buffer.size
         131072
     
     
          hadoop.tmp.dir
          /opt/hadoop-2.7.4/tmp
     

修改$HADOOP_HOME/etc/hadoop/hdfs-site.xml


    
      dfs.namenode.secondary.http-address
      Master:50090
    
    
      dfs.replication
      2
    
    
      dfs.namenode.name.dir
      file:/opt/hadoop-2.7.4/hdfs/name
    
    
      dfs.datanode.data.dir
      file:/opt/hadoop-2.7.4/hdfs/data
    

修改$HADOOP_HOME/etc/hadoop/mapred-site.xml


 
    mapreduce.framework.name
    yarn
  
  
          mapreduce.jobhistory.address
          Master:10020
  
  
          mapreduce.jobhistory.address
          Master:19888
  

修改$HADOOP_HOME/etc/hadoop/yarn-site.xml


     
         yarn.nodemanager.aux-services
         mapreduce_shuffle
     
     
         yarn.resourcemanager.address
         Master:8032
     
     
         yarn.resourcemanager.scheduler.address
         Master:8030
     
     
         yarn.resourcemanager.resource-tracker.address
         Master:8031
     
     
         yarn.resourcemanager.admin.address
         Master:8033
     
     
         yarn.resourcemanager.webapp.address
         Master:8088
     

复制Master节点的hadoop文件夹到Worker1和Worker2上。

scp -r /opt/hadoop-2.7.4 dc2-user@Worker1:
scp -r /opt/hadoop-2.7.4 dc2-user@Worker2:

然后在mv到/opt目录下

在Worker1和Worker2上分别修改/etc/profile,过程同Master一样。

在Master节点启动集群

启动之前格式化一下namenode:

hadoop namenode -format
启动:
/opt/hadoop-2.7.4/sbin/start-all.sh

至此hadoop的完全分布式环境搭建完毕。
查看集群是否启动成功:

jps

Master显示:

SecondaryNameNode
ResourceManager
NameNode

Slave显示:

NodeManager
DataNode

这里Master申请2G内存,如果申请1G,后面配置spark最少要1G,否则启动内存不够

Spark2.2.0完全分布式环境搭建

将spark-2.2.0-bin-hadoop2.7上传到Master,也是放在/opt目录下
修改/etc/profie,增加如下内容:

export SPARK_HOME=/opt/spark-2.2.0-bin-hadoop2.7/
export PATH=$PATH:$SPARK_HOME/bin
cp spark-env.sh.template spark-env.sh

修改$SPARK_HOME/conf/spark-env.sh,添加如下内容

export JAVA_HOME=/usr/local/jdk1.8.0_171
export SCALA_HOME=/usr/share/scala
export HADOOP_HOME=/opt/hadoop-2.7.4
export HADOOP_CONF_DIR=/opt/hadoop-2.7.4/etc/hadoop
export SPARK_MASTER_IP=10.254.0.58
export SPARK_MASTER_HOST=10.254.0.58
export SPARK_LOCAL_IP=10.254.0.58
export SPARK_WORKER_MEMORY=1g
export SPARK_WORKER_CORES=2
export SPARK_HOME=/opt/spark-2.2.0-bin-hadoop2.7
export SPARK_DIST_CLASSPATH=$(/opt/hadoop-2.7.4/bin/hadoop classpath)
cp slaves.template slaves

修改$SPARK_HOME/conf/slaves,添加如下内容:

Worker1
Worker2

注意这里如果把Master也添加到这里,Master将即使主机又做工作机
将配置好的spark文件复制到Worker1和Worker2节点。

scp /opt/spark-2.2.0-bin-hadoop2.7 dc2-user@Worker1:
scp /opt/spark-2.2.0-bin-hadoop2.7 dc2-user@Worker2:

修改Worker1和Worker2配置,在Worker1和Worker2上分别修改/etc/profile,增加Spark的配置,过程同Master一样。
在Worker1和Worker2修改$SPARK_HOME/conf/spark-env.sh,将export SPARK_LOCAL_IP改成Worker1和Worker2对应节点的IP。

在Master节点启动集群。
/opt/spark-2.2.0-bin-hadoop2.7/sbin/start-all.sh
查看集群是否启动成功:
jps

Master在Hadoop的基础上新增了:

Master

Slave在Hadoop的基础上新增了:

Worker

你可能感兴趣的:(Hadoop2.7.4+Spark2.2.0滴滴云分布式集群搭建过程)