上篇文章中讲完了如何配置免密码登录的问题,现在讲述下,三个节点的环境配置过程。
所需要的hadoop-2.7.3.tar.gz 、 jdk-7u79-linux-x64.tar.gz 、 scala-2.11.6.tgz 、 spark-2.0.1-bin-hadoop2.7.tgz 可以点击这里获取,资源存放在百度云盘。
首先需要在三个节点中分别创建spark目录
master节点、worker1节点、worker2节点同时执行:下面以master节点为例,部分操作worker1与worker2不需要执行,不需要worker1,worker2执行的将给出注释,请仔细看清。
[email protected]:~/.ssh$ cd .. [email protected]:~$ mkdir spark
注意所创建的spark目录属于spark用户,hadoop组
[email protected]:~$ cd spark/
在这里要介绍一个工具winSCP,功能是能够在windows 与ubuntu 之间传递文件,之所以不推荐使用lrzsz包中的rz 进行传递是因为rz只能够传递比较小的文件,对于大的文件,使用这个将会传递失败,有趣的是可以使用命令sudo rz 进行传递,但是,当上传之后,你可以看到所上传的文件所属的用户将变成了root,这将会导致后面配置的错误。因此,必须使用winSCP进行传递。winSCP也在刚才的百度云盘中。
上图显示了winSCP工具界面,根据自己的文件目录进行上传,或者可以直接拖
依次对上传的包进行解压,注意:在worker1和worker2中只需上传jdk-7u79-linux-x64.tar.gz 、 scala-2.11.6.tgz ,而在master中则要全部上传四个文件
[email protected]:~/spark$ tar -zxvf hadoop-2.7.3 #只在master节点执行
[email protected]:~/spark$ tar -zxvf jdk-7u79-linux-x64.tar.gz #三个节点都要执行
[email protected]:~/spark$ tar -zxvf scala-2.11.6.tgz #三个节点都要执行
[email protected]:~/spark$ tar -zxvf spark-2.0.1-bin-hadoop2.7.tgz #只在master节点执行
解压之后,为方便调用,建立软连接
[email protected]:~/spark$ ln -s hadoop-2.7.3 hadoop #只在master节点执行 [email protected]:~/spark$ ln -s jdk1.7.0_79/ jdk #三个节点都要执行 [email protected]:~/spark$ ln -s scala-2.11.6 scala #三个节点都要执行 [email protected]:~/spark$ ln -s spark-2.0.1-bin-hadoop2.7 spark #只在master节点执行
切换到root下进行环境配置
[email protected]:~/spark$ sudo su [sudo] password for spark: [email protected]:/home/spark/spark# vim /etc/profile
在文件最底部添加:
export JAVA_HOME=/home/spark/spark/jdk #三个节点都要添加 export SCALA_HOME=/home/spark/spark/scala #三个节点都要添加 export HADOOP_HOME=/home/spark/spark/hadoop #三个节点都要添加 export SPARK_HOME=/home/spark/spark/spark #三个节点都要添加 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop export PATH=$PATH:$JAVA_HOME/bin:$SCALA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$SPARK_HOME/bin
保存,使其生效,并退回到spark用户
[email protected]:/home/spark/spark# source /etc/profile [email protected]:/home/spark/spark# exit exit [email protected]:~/spark$
至此可以查看下java环境,scala,hadoop 环境是否已经安装成功
[email protected]:~/spark$ java -version java version "1.7.0_79" Java(TM) SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
java环境已经配置成功
[email protected]:~/spark$ scala -version Scala code runner version 2.11.6 -- Copyright 2002-2013, LAMP/EPFL
scala已经配置成功
至此上述是三个节点同时执行的。
接下来,master节点上的配置
[email protected]:~/spark$ hadoop version Hadoop 2.7.3 Subversion https://git-wip-us.apache.org/repos/asf/hadoop.git -r baa91f7c6bc9cb92be5982de4719c1c8af91ccff Compiled by root on 2016-08-18T01:41Z Compiled with protoc 2.5.0 From source with checksum 2e4ce5f957ea4db193bce3734ff29ff4 This command was run using /home/spark/spark/hadoop-2.7.3/share/hadoop/common/hadoop-common-2.7.3.jar
hadoop环境成功
接下来开始配置hadoop
[email protected]:~/spark$ cd hadoop/etc/hadoop/ [email protected]:~/spark/hadoop/etc/hadoop$ vim slaves
删除里面内容,并添加一下内容:
保存即可
依照下述命令进行文件的更改
[email protected]:~/spark/hadoop/etc/hadoop$ vim hadoop-env.sh
添加或更改文件中相关的变量,本人在这个地方踩了不少坑,如果不添加,会在后面报错。
添加完毕后,记得保存。
[email protected]:~/spark/hadoop/etc/hadoop$ vim core-site.xml
添加内容到
<configuration>内容</configuration>
内容如下:
<property> <name>fs.default.name</name> <value>hdfs://master:9000</value> <description>The name of the default file system. A URI whose scheme and authority determine the FileSystem implementation. The uri‘s scheme determines the config property (fs.SCHEME.impl) naming the FileSystem implementation class. The uri‘s authority is used to determine the host, port, etc. for a filesystem. </description> </property> <property> <name>hadoop.tmp.dir</name> <value>/home/spark/spark/hadoop/tmp</value> <description>A base for other temporary directories.</description> </property>
[email protected]:~/spark/hadoop/etc/hadoop$ vim hdfs-site.xml
添加内容到
<configuration>内容</configuration>
内容如下:
<property> <name>dfs.replication</name> <value>3</value> <description>Default block replication.The actual number of replications can be specified when the file iscreated.The default is used if replication is not specified in create time. </description> </property>
[email protected]:~/spark/hadoop/etc/hadoop$ vim yarn-site.xml
添加内容到
<configuration>内容</configuration>
内容如下:
<property> <name>yarn.resourcemanager.hostname</name> <value>master</value> </property> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property>
[email protected]:~/spark/hadoop/etc/hadoop$ cp mapred-site.xml.template mapred-site.xml [email protected]:~/spark/hadoop/etc/hadoop$ vim mapred-site.xml
添加内容到
<configuration>内容</configuration>
内容如下:
<property> <name>mapreduce.framework.name</name> <value>yarn</value> <description>The runtime framework for executing MapReduce jobs. Can be one of local, classic or yarn.默认是local,适合单机 </description> </property>
[email protected]:~/spark/hadoop/etc/hadoop$ vim yarn-site.xml
添加内容到
<configuration>内容</configuration>
内容如下:
<property> <name>yarn.resourcemanager.hostname</name> <value>master</value> </property> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property>
[email protected]:~/spark/hadoop/etc/hadoop$ vim yarn-env.sh
添加以下内容在文件中地开始
export JAVA_HOME=/home/spark/spark/jdk export YARN_PID_DIR=/home/spark/spark/hadoop/tmp/pid
保存文件
切换到worker1节点中
执行
[email protected]:~/spark$ scp -r [email protected]:/home/spark/spark/hadoop ./hadoop
注意:./hadoop,代表将master中spark用户下的/home/spark/spark/hadoop复制为hadoop,此名称要跟之前在/etc/profile中设置的hadoop环境变量名称一致。
在worker1中做下测试。
[email protected]:~/spark$ hadoop version Hadoop 2.7.3 Subversion https://git-wip-us.apache.org/repos/asf/hadoop.git -r baa91f7c6bc9cb92be5982de4719c1c8af91ccff Compiled by root on 2016-08-18T01:41Z Compiled with protoc 2.5.0 From source with checksum 2e4ce5f957ea4db193bce3734ff29ff4 This command was run using /home/spark/spark/hadoop/share/hadoop/common/hadoop-common-2.7.3.jar
显示成功
切换到worker2节点中
[email protected]:~/spark$ scp -r [email protected]:/home/spark/spark/hadoop ./hadoop
在worker2下做下测试。
[email protected]:~/spark$ hadoop version Hadoop 2.7.3 Subversion https://git-wip-us.apache.org/repos/asf/hadoop.git -r baa91f7c6bc9cb92be5982de4719c1c8af91ccff Compiled by root on 2016-08-18T01:41Z Compiled with protoc 2.5.0 From source with checksum 2e4ce5f957ea4db193bce3734ff29ff4 This command was run using /home/spark/spark/hadoop/share/hadoop/common/hadoop-common-2.7.3.jar
显示成功
初始化hadoop集群
[email protected]:~/spark/hadoop/etc/hadoop$ hadoop namenode -format
若红色方框中的status为0则代表初始化成功,若为1,则为失败
启动集群
[email protected]:~/spark/hadoop/etc/hadoop$ $HADOOP_HOME/sbin/start-all.sh
然后在浏览器中输入 http://master_ip:50070/ master_ip代表master的ip地址端口号为50070