Step 1:
下载Spark版本:根据HDFS的版本进行下载,—–本文对应的是Spark 1.6.0 HDFS 2.6.0
http://spark.apache.org/downloads.html
Step 2:
在node11节点执行命令:
mkdir -p /opt/apps/spark
cd /opt/apps/spark
Step 3:
使用xftp将下载的spark包上传到上述路径
Step 4:
执行命令:
tar -xvf /opt/apps/spark/spark-1.6.0-bin-hadoop2.6.tgz
Step 5:
执行命令:
cp /opt/apps/spark/spark-1.6.0-bin-hadoop2.6/conf/slaves.template /opt/apps/spark/spark-1.6.0-bin-hadoop2.6/conf/slaves
Step 6:
执行命令:删除localhost,添加从节点
vi /opt/apps/spark/spark-1.6.0-bin-hadoop2.6/conf/slaves
Step 7:
执行命令:
cp /opt/apps/spark/spark-1.6.0-bin-hadoop2.6/conf/spark-env.sh.template /opt/apps/spark/spark-1.6.0-bin-hadoop2.6/conf/spark-env.sh
Step 8:
执行命令:
vi /opt/apps/spark/spark-1.6.0-bin-hadoop2.6/conf/spark-env.sh
在文件的最下面添加如下属性:
export JAVA_HOME=/usr/java/jdk1.7.0_79
export SPARK_MASTER_IP=node11
export SPARK_MASTER_PORT=7077
export SPARK_WORKER_CORES=1
export SPARK_WORKER_INSTANCES=1
export SPARK_WORKER_MEMORY=1g
Step 9:
分别在node12和node13上执行命令:
mkdir -p /opt/apps/spark
cd /opt/apps/spark
Step 10:
在node11执行命令,进行文件的分发
scp -r /opt/apps/spark/spark-1.6.0-bin-hadoop2.6 node12:/opt/apps/spark/
scp -r /opt/apps/spark/spark-1.6.0-bin-hadoop2.6 node13:/opt/apps/spark/
Step 11:
在node11节点上执行命令:
/opt/apps/spark/spark-1.6.0-bin-hadoop2.6/sbin/start-all.sh
Step 12:
分别在三个节点上执行命令:
jps
Step 13:
打开浏览器,输入
192.168.80.11:8080
Step 14:
在node11节点上执行命令,运行一个示例
cd /opt/apps/spark/spark-1.6.0-bin-hadoop2.6
./bin/spark-submit --class org.apache.spark.examples.SparkPi --master spark://node11:7077 --executor-memory 1G --total-executor-cores 1 ./lib/spark-examples-1.6.0-hadoop2.6.0.jar 100
得到PI的结果
Step 15:
写一个wordcount程序,达成jar包使用xftp上传到node11中某一个路径下
在node11上执行命令:
mkdir -p /opt/apps/spark/spark-1.6.0-bin-hadoop2.6/test
cd /opt/apps/spark/spark-1.6.0-bin-hadoop2.6/test
Step 16:
执行命令:
vi /opt/apps/spark/spark-1.6.0-bin-hadoop2.6/test/test_word_count.txt
Step 17:
在node11节点上执行命令:——当jar包和文件在节点上时
.- -- . -- --- ---- . -..--..
Step 18:
在node11节点上执行命令:——当jar包和文件在hdfs上
.- -- . -- --- ---- . .
Step 19:
在node11节点上执行命令:——当jar包在hdfs上,文件在节点上
.- -- . -- --- ---- . -..--..
Step 20:
Cluster模式
jar包和文件都在本地节点上
.- -- . -- --- --- ---- . -..--..
Step 21:
jar包和文件都在HDFS上
.- -- . -- --- --- ---- . .