【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础008--flink分布式部署003
2017-11-12 16:42
1006 查看
三、flink第一个程序
1.创建文件夹并上传flink的readme文件
hadoop fs -mkdir -p /input/flink hadoop fs -put ${FLINK_HOME}/README.txt /input/flink/
执行效果:
2.打开start-scala-shell.sh
${FLINK_HOME}/bin/start-scala-shell.sh是flink提供的交互式clinet,可以用于代码片段的测试,方便开发工作。 它有两种启动方式,一种是工作在本地,另一种是工作到集群。本例中因为机器连接非常方便,就直接使用集群进行测试,在 开发中,如果集群连接不是非常方便,可以连接到本地,在本地开发测试通过后,再连接到集群进行部署工作。如果程序有依 赖的jar包,则可以使用 -a <path/to/jar.jar> 或 --addclasspath <path/to/jar.jar>参数来添加依赖。
start-scala-shell.sh常用命令
1.本地连接 ${FLINK_HOME}/bin/start-scala-shell.sh local 2.集群连接 ${FLINK_HOME}/bin/start-scala-shell.sh remote <hostname> <portnumber> 3.带有依赖包的格式 ${FLINK_HOME}/bin/start-scala-shell.sh[local|remote<host><port>]--addclasspath<path/to/jar.jar> 4.查看帮助 ${FLINK_HOME}/bin/start-scala-shell.sh --help
start-scala-shell.sh的帮助查询:
Flink Scala Shell Usage: start-scala-shell.sh [local|remote|yarn] [options] <args>... Command: local [options] Starts Flink scala shell with a local Flink cluster -a <path/to/jar> | --addclasspath <path/to/jar> Specifies additional jars to be used in Flink Command: remote [options] <host> <port> Starts Flink scala shell connecting to a remote cluster <host> Remote host name as string <port> Remote port as integer -a <path/to/jar> | --addclasspath <path/to/jar> Specifies additional jars to be used in Flink Command: yarn [options] Starts Flink scala shell connecting to a yarn cluster -n arg | --container arg Number of YARN container to allocate (= Number of TaskManagers) -jm arg | --jobManagerMemory arg Memory for JobManager container [in MB] -nm <value> | --name <value> Set a custom name for the application on YARN -qu <arg> | --queue <arg> Specifies YARN queue -s <arg> | --slots <arg> Number of slots per TaskManager -tm <arg> | --taskManagerMemory <arg> Memory per TaskManager container [in MB] -a <path/to/jar> | --addclasspath <path/to/jar> Specifies additional jars to be used in Flink --configDir <value> The configuration directory. -h | --help Prints this usage text
执行命令:
${FLINK_HOME}/bin/start-scala-shell.sh remote qingcheng11 6123
执行效果:
3.执行第一个flink程序
执行程序:val file=benv.readTextFile("hdfs://qingcheng11:9000/input/flink/README.txt") val flinks=file.filter(l =>l.contains("flink")) flinks.print() val count=flinks.count
shell执行效果:
web执行效果一:
web执行效果二:
相关文章推荐
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础0011--flink分布式部署006
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础0015--flink分布式部署0010
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础0017--IDEA搭建非maven管理的集成开发环境002
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础0019--IDEA搭建maven管理的集成开发环境001
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础003--flink特性:流处理,批处理珠联璧合
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础0020--IDEA搭建maven管理的集成开发环境002
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础002--flink特性:流处理特性介绍
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战008--DateSet实用API详解008
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础0012--flink分布式部署007
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础004--flink特性:类库和API示例
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink高级特性与高级应用008-Slot和Parallelism的深入分析003
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础0016--IDEA搭建非maven管理的集成开发环境001
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础0018--IDEA搭建非maven管理的集成开发环境003
- 【云星数据---Apache Flink实战系列(精品版)】:Flink基础--001:flink介绍
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础0013--flink分布式部署008
- 云星数据---Apache Flink实战系列(精品版)】:Flink流处理API详解与编程实战008-DataStream与MySql自定义sink和source(Scala版)003
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础006--flink分布式部署001
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础007--flink分布式部署002
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战024--DateSet实用API详解024
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink批处理API详解与编程实战027--DateSet实用API详解027