1、免秘钥登录配置:
ssh-keygen
cd .ssh
touch authorized_keys
cat id_rsa.pub > authorized_keys
chmod 600 authorized_keys
2、环境工具
2.1环境
系统 urbuntu jdk 1.7.0_79
scala 2.10.4
hadoop 2.6.0
spark 1.6.2
2.2打包工具
IDEA + sbt1.2打包工具
3.打包
3.1安装插件
需要预先安装scala插件,点击File ->Setting ->Plugins ->输入框输入scala->install
安装完成需要重启IDE
3.2创建项目
File -> New Project ->Scala -> SBT 选择相应版本 ->finish
3.3编写代码
build.sbt 添加spark相关依赖
name := "demoPro"
version := "1.0"
scalaVersion := "2.10.4"
libraryDependencies += "org.apache.spark" % "spark-core_2.10" % "1.6.2"
创建WordCount.scala,编写如下代码
import org.apache.spark.{SparkContext, SparkConf}
/**
* Created by Administrator on 2018/2/20.
*/
object WordCount {
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("wordcount")
val sc = new SparkContext(conf)
val input = sc.textFile("/home/dell/helloSpark.txt")
val lines = input.flatMap(line => (line.split(" ")))
val count = lines.map(word => (word, 1)).reduceByKey { case (x, y) => x + y }
val output=count.saveAsTextFile("/home/dell/helloSparkRes")
}
}
3.4打包
File -> Project Structure -> Aritifacts -> 点击+号 ->jar -> 第二个 -> 指定Module和 MainClass -> JAR files from libraries 选择第二个 ->点击ok
主题栏点击Build -> Build Aritifacts – Build
在工程目下out目录中生成相应jar包即打包成功
4.提交任务
4.1启动hadoop
#进入sbin目录
cd $Hadoop_HOME/sbin
#启动hadoop集群
start-all.sh
4.2上传测试文件到hdfs
hadoop fs -put test.txt /test/test.txt
4.3上传程序jar包
是同filelize 或者sftp 或者 rz -y命令上传程序jar
4.4 提交任务
4.4.1启动Master
sudo ./start-master.sh
访问localhost:8080 获取spark://xxx:7077
4.4.2启动Worker
sudo ./bin/spark-class org.apache.spark.deploy.worker.Worker spark://dell:7077
4.4.3提交作业
sudo ./bin/spark-submit –master spark://dell:7077 –class WordCount /home/dell/demopro.jar
5、查看测试程序是否正确
5.1、查看 是否生成文件夹 进入文件查看程序是否正确
5.2、进入文件查看程序是否正确
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/opensource/193791.html