当前位置: 首页 > news >正文

spark-submit提交任务到集群

2019独角兽企业重金招聘Python工程师标准>>> hot3.png


1.参数选取

当我们的代码写完,打好jar,就可以通过bin/spark-submit 提交到集群,命令如下:

./bin/spark-submit \  
 --class <main-class> 
 --master <master-url> \ 
 --deploy-mode <deploy-mode> \ 
 --conf <key>=<value> \  
     ... # other options  
 <application-jar> \  
 [application-arguments]

一般情况下使用上面这几个参数就够用了

  • --class: The entry point for your application (e.g. org.apache.spark.examples.SparkPi)

  • --master: The master URL for the cluster (e.g. spark://23.195.26.187:7077)

  • --deploy-mode: Whether to deploy your driver on the worker nodes (cluster) or locally as an external client (client) (default: client

  • --conf: Arbitrary Spark configuration property in key=value format. For values that contain spaces wrap “key=value” in quotes (as shown).

  • application-jar: Path to a bundled jar including your application and all dependencies. The URL must be globally visible inside of your cluster, for instance, an hdfs:// path or a file:// path that is present on all nodes.

  • application-arguments: Arguments passed to the main method of your main class, if any

    对于不同的集群管理,对spark-submit的提交列举几个简单的例子

# Run application locally on 8 cores

 ./bin/spark-submit \
 --class org.apache.spark.examples.SparkPi \
--master local[8] \ 
  /path/to/examples.jar \
100

 # Run on a Spark standalone cluster in client deploy mode
 
./bin/spark-submit \
 --class org.apache.spark.examples.SparkPi \
--master spark://207.184.161.138:7077 \
--executor-memory 20G \ 
--total-executor-cores 100 \
/path/to/examples.jar \ 
 1000 
 
 # Run on a Spark standalone cluster in cluster deploy mode with supervise 
 # make sure that the driver is automatically restarted if it fails with non-zero exit code
 
 ./bin/spark-submit \
 --class org.apache.spark.examples.SparkPi \
 --master spark://207.184.161.138:7077 \ 
 --deploy-mode cluster
--supervise 
 --executor-memory 20G \
--total-executor-cores 100 \
 /path/to/examples.jar \ 
   1000
   
# Run on a YARN cluster export HADOOP_CONF_DIR=XXX

./bin/spark-submit \ 
 --class org.apache.spark.examples.SparkPi \
--master yarn-cluster \  # can also be `yarn-client` for client mode 
 --executor-memory 20G \ 
  --num-executors 50 \ 
  /path/to/examples.jar \ 
 1000 
 
 # Run a Python application on a Spark standalone cluster
 
./bin/spark-submit \ 
  --master spark://207.184.161.138:7077 \ 
 examples/src/main/python/pi.py \ 
1000

2.具体提交步骤

代码实现一个简单的统计

public class SimpleSample {
	public static void main(String[] args) {
		String logFile = "/home/bigdata/spark-1.5.1/README.md"; 
		SparkConf conf = new SparkConf().setAppName("Simple Application");
		JavaSparkContext sc = new JavaSparkContext(conf);
		JavaRDD<String> logData = sc.textFile(logFile).cache();

		long numAs = logData.filter(new Function<String, Boolean>() {
			public Boolean call(String s) {
				return s.contains("a");
			}
		}).count();

		long numBs = logData.filter(new Function<String, Boolean>() {
			public Boolean call(String s) {
				return s.contains("b");
			}
		}).count();

		System.out.println("Lines with a: " + numAs + ", lines with b: " + numBs);
	}

}

打成jar

175703_LAu6_2529303.png

上传命令

./bin/spark-submit --class cs.spark.SimpleSample --master spark://spark1:7077 /home/jar/spark-test-0.0.1-SNAPSHOT.jar



转载于:https://my.oschina.net/u/2529303/blog/541685

相关文章:

  • 结合Scikit-learn介绍几种常用的特征选择方法
  • js图片处理
  • bconsole中相关命名说明
  • Oracle更改redo log的大小
  • parallels desktop克隆ubuntu虚拟机网卡丢失
  • 泛型vector
  • [转]SQLServer 2008数据库查看死锁、堵塞的SQL语句
  • Solr5安装部署
  • Scrapy 入门:Hello Scrapy
  • 李嘉诚储藏财富的背后隐藏着什么奥秘?
  • Bitnami Redmine 与 gerrit 整合问题解决
  • 电商项目系列文档(三):秒杀的设计
  • Gitlab数据迁移
  • js模块化开发——require.js学习总结
  • git版本控制实践纪录
  • 2017 年终总结 —— 在路上
  • Angular 2 DI - IoC DI - 1
  • Angular js 常用指令ng-if、ng-class、ng-option、ng-value、ng-click是如何使用的?
  • Bootstrap JS插件Alert源码分析
  • const let
  • gcc介绍及安装
  • Java程序员幽默爆笑锦集
  • KMP算法及优化
  • Linux学习笔记6-使用fdisk进行磁盘管理
  • Next.js之基础概念(二)
  • node学习系列之简单文件上传
  • overflow: hidden IE7无效
  • PHP面试之三:MySQL数据库
  • React-Native - 收藏集 - 掘金
  • Vue2.0 实现互斥
  • 高性能JavaScript阅读简记(三)
  • 收藏好这篇,别再只说“数据劫持”了
  • Oracle Portal 11g Diagnostics using Remote Diagnostic Agent (RDA) [ID 1059805.
  • 阿里云服务器如何修改远程端口?
  • $.type 怎么精确判断对象类型的 --(源码学习2)
  • (3)STL算法之搜索
  • (3)选择元素——(14)接触DOM元素(Accessing DOM elements)
  • (pojstep1.3.1)1017(构造法模拟)
  • (初研) Sentence-embedding fine-tune notebook
  • (简单) HDU 2612 Find a way,BFS。
  • (九)信息融合方式简介
  • (论文阅读32/100)Flowing convnets for human pose estimation in videos
  • (转) RFS+AutoItLibrary测试web对话框
  • (转)程序员技术练级攻略
  • ***微信公众号支付+微信H5支付+微信扫码支付+小程序支付+APP微信支付解决方案总结...
  • .NET Core Web APi类库如何内嵌运行?
  • .Net Core 中间件验签
  • .NET Remoting Basic(10)-创建不同宿主的客户端与服务器端
  • .NET 分布式技术比较
  • .NET 回调、接口回调、 委托
  • .NET分布式缓存Memcached从入门到实战
  • .NET中统一的存储过程调用方法(收藏)
  • @private @protected @public
  • @property括号内属性讲解
  • [].slice.call()将类数组转化为真正的数组