尚硅谷Flink教程学习笔记(部署提交)

课程地址
先来分析一下文件flink-1.10.0-bin-scala_2.11.tgz
压缩包
解压之后是这样的:
flink-scala
conf文件夹下存储了flink的所有配置文件:
在这里插入图片描述
打开flink-conf.yaml分析一下

################################################################################
#  Licensed to the Apache Software Foundation (ASF) under one
#  or more contributor license agreements.  See the NOTICE file
#  distributed with this work for additional information
#  regarding copyright ownership.  The ASF licenses this file
#  to you under the Apache License, Version 2.0 (the
#  "License"); you may not use this file except in compliance
#  with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
# limitations under the License.
################################################################################


#==============================================================================
# Common
#==============================================================================

# The external address of the host on which the JobManager runs and can be
# reached by the TaskManagers and any clients which want to connect. This setting
# is only used in Standalone mode and may be overwritten on the JobManager side
# by specifying the --host <hostname> parameter of the bin/jobmanager.sh executable.
# In high availability mode, if you use the bin/start-cluster.sh script and setup
# the conf/masters file, this will be taken care of automatically. Yarn/Mesos
# automatically configure the host name based on the hostname of the node where the
# JobManager runs.

jobmanager.rpc.address: localhost
# 本机jobmanager的远程过程调用地址,即在哪里启动当前的集群,就以当前的localhost作为当前集群的
# jobmanager,如果配置高可用可能有多个,一般情况下一个集群里就一个jobmanager

# The RPC port where the JobManager is reachable.

jobmanager.rpc.port: 6123


# The heap size for the JobManager JVM


# 以下参数重要,在真正部署提交时可能需要更改的参数
jobmanager.heap.size: 1024m
# 对内存大小,默认1G

# The total process memory size for the TaskManager.
# TaskManager的总进程内存大小

# Note this accounts for all memory usage within the TaskManager process, including JVM metaspace and other overhead.
# 注意,这包括TaskManager进程中的所有内存使用,包括JVM元空间和其他开销。
taskmanager.memory.process.size: 1568m

# To exclude JVM metaspace and overhead, please, use total Flink memory size instead of 'taskmanager.memory.process.size'.
# 要排除JVM元空间和开销,请使用总Flink内存大小而不是“taskmanager.memory.process.size”。
# It is not recommended to set both 'taskmanager.memory.process.size' and Flink memory.
# 不建议同时设置两个'taskmanager.memory.process。大小和内存。
# taskmanager.memory.flink.size: 1280m

# The number of task slots that each TaskManager offers. Each slot runs one parallel pipeline.
# 每个TaskManager提供的任务槽数。每个槽运行一个并行管道。即能执行多少个Task
taskmanager.numberOfTaskSlots: 1

# The parallelism used for programs that did not specify and other parallelism.
# 用于没有指定的程序的并行度和其他并行度。即默认并行度
parallelism.default: 1

# The default file system scheme and authority.
# 
# By default file paths without scheme are interpreted relative to the local
# root file system 'file:///'. Use this to override the default and interpret
# relative paths relative to a different file system,
# for example 'hdfs://mynamenode:12345'
#
# fs.default-scheme

#==============================================================================
# High Availability
#==============================================================================

# The high-availability mode. Possible options are 'NONE' or 'zookeeper'.
# 高可用性模式。可能的选项是“NONE”或“zookeeper”
# high-availability: zookeeper

# The path where metadata for master recovery is persisted. While ZooKeeper stores
# the small ground truth for checkpoint and leader election, this location stores
# the larger objects, like persisted dataflow graphs.
# 保存master持久化元数据的路径。当ZooKeeper管理员存储small ground truth作为checkpoint和leader选举,
# 这个地点储存较大的Objects,比如持久数据流图。
# Must be a durable file system that is accessible from all nodes
# 必须是可从所有节点访问的持久文件系统
# (like HDFS, S3, Ceph, nfs, ...) 
#
# high-availability.storageDir: hdfs:///flink/ha/

# The list of ZooKeeper quorum peers that coordinate the high-availability
# setup. This must be a list of the form:
# "host1:clientPort,host2:clientPort,..." (default clientPort: 2181)
# 协调高可用性配置的ZooKeeper quorum节点的列表,这必须是一个表单的列表:
#
# high-availability.zookeeper.quorum: localhost:2181


# ACL options are based on https://zookeeper.apache.org/doc/r3.1.2/zookeeperProgrammers.html#sc_BuiltinACLSchemes
# It can be either "creator" (ZOO_CREATE_ALL_ACL) or "open" (ZOO_OPEN_ACL_UNSAFE)
# The default value is "open" and it can be changed to "creator" if ZK security is enabled
#
# high-availability.zookeeper.client.acl: open

#==============================================================================
# Fault tolerance and checkpointing
#==============================================================================

# The backend that will be used to store operator state checkpoints if
# checkpointing is enabled.
# 如果启用了检查点,backend就会用于存储操作符状态检查点。
#
# Supported backends are 'jobmanager', 'filesystem', 'rocksdb', or the
# <class-name-of-factory>.
#
# state.backend: filesystem

# Directory for checkpoints filesystem, when using any of the default bundled
# state backends.
#
# state.checkpoints.dir: hdfs://namenode-host:port/flink-checkpoints

# Default target directory for savepoints, optional.
#
# state.savepoints.dir: hdfs://namenode-host:port/flink-checkpoints

# Flag to enable/disable incremental checkpoints for backends that
# support incremental checkpoints (like the RocksDB state backend). 
#
# state.backend.incremental: false

# The failover strategy, i.e., how the job computation recovers from task failures.
# Only restart tasks that may have been affected by the task failure, which typically includes
# downstream tasks and potentially upstream tasks if their produced data is no longer available for consumption.
# 故障转移策略,即。,作业计算如何从任务失败中恢复。
# 仅重启那些可能受到任务失败影响的任务,通常包括下游任务和潜在的上游任务(如果它们产生的数据不再可用)。
jobmanager.execution.failover-strategy: region

#==============================================================================
# Rest & web frontend REST或web前端
#==============================================================================

# The port to which the REST client connects to. If rest.bind-port has
# not been specified, then the server will bind to this port as well.
# REST客户端连接到的端口。如果rest.bind-port未指定,则服务器也将绑定到此端口
#rest.port: 8081

# The address to which the REST client will connect to
#
#rest.address: 0.0.0.0

# Port range for the REST and web server to bind to.
#
#rest.bind-port: 8080-8090

# The address that the REST & web server binds to
#
#rest.bind-address: 0.0.0.0

# Flag to specify whether job submission is enabled from the web-based
# runtime monitor. Uncomment to disable.
# 标记,以指定是否从基于web runtime监视器的启用作业提交。取消禁用
#web.submit.enable: false

#==============================================================================
# Advanced高级配置
#==============================================================================

# Override the directories for temporary files. If not specified, the
# system-specific Java temporary directory (java.io.tmpdir property) is taken.
#
# For framework setups on Yarn or Mesos, Flink will automatically pick up the
# containers' temp directories without any need for configuration.
#
# Add a delimited list for multiple directories, using the system directory
# delimiter (colon ':' on unix) or a comma, e.g.:
#     /data1/tmp:/data2/tmp:/data3/tmp
#
# Note: Each directory entry is read from and written to by a different I/O
# thread. You can include the same directory multiple times in order to create
# multiple I/O threads against that directory. This is for example relevant for
# high-throughput RAIDs.
#
# io.tmp.dirs: /tmp

# The classloading resolve order. Possible values are 'child-first' (Flink's default)
# and 'parent-first' (Java's default).
#
# Child first classloading allows users to use different dependency/library
# versions in their application than those in the classpath. Switching back
# to 'parent-first' may help with debugging dependency issues.
#
# classloader.resolve-order: child-first

# The amount of memory going to the network stack. These numbers usually need 
# no tuning. Adjusting them may be necessary in case of an "Insufficient number
# of network buffers" error. The default min is 64MB, the default max is 1GB.
# 
# taskmanager.memory.network.fraction: 0.1
# taskmanager.memory.network.min: 64mb
# taskmanager.memory.network.max: 1gb

#==============================================================================
# Flink Cluster Security Configurationflink集群安全性配置
#==============================================================================

# Kerberos authentication for various components - Hadoop, ZooKeeper, and connectors -
# may be enabled in four steps:
# 1. configure the local krb5.conf file
# 2. provide Kerberos credentials (either a keytab or a ticket cache w/ kinit)
# 3. make the credentials available to various JAAS login contexts
# 4. configure the connector to use JAAS/SASL

# The below configure how Kerberos credentials are provided. A keytab will be used instead of
# a ticket cache if the keytab path and principal are set.

# security.kerberos.login.use-ticket-cache: true
# security.kerberos.login.keytab: /path/to/kerberos/keytab
# security.kerberos.login.principal: flink-user

# The configuration below defines which JAAS login contexts

# security.kerberos.login.contexts: Client,KafkaClient

#==============================================================================
# ZK Security Configuration  ZK的安全性配置
#==============================================================================

# Below configurations are applicable if ZK ensemble is configured for security
# 如果ZK集成被配置为安全的,下面的配置是适用的
# Override below configuration to provide custom ZK service name if configured
# 重写下面的配置,以在配置时提供自定义ZK服务名称
# zookeeper.sasl.service-name: zookeeper

# The configuration below must match one of the values set in "security.kerberos.login.contexts"
# 下面的配置必须匹配“security.kerberos.login.contexts”中的一个值
# zookeeper.sasl.login-context-name: Client

#==============================================================================
# HistoryServer	历史服务器
#==============================================================================

# The HistoryServer is started and stopped via bin/historyserver.sh (start|stop)
# 通过bin/ HistoryServer.sh(启动|停止)启动和停止HistoryServer
# Directory to upload completed jobs to. Add this directory to the list of
# monitored directories of the HistoryServer as well (see below).
# 要上传已完成的作业的目录。同时将此目录添加到HistoryServer的监听目录列表(参见下面)。
#jobmanager.archive.fs.dir: hdfs:///completed-jobs/

# The address under which the web-based HistoryServer listens.
#historyserver.web.address: 0.0.0.0

# The port under which the web-based HistoryServer listens.
#historyserver.web.port: 8082

# Comma separated list of directories to monitor for completed jobs.
#historyserver.archive.fs.dir: hdfs:///completed-jobs/

# Interval in milliseconds for refreshing the monitored directories.
#historyserver.archive.fs.refresh-interval: 10000


命令
windows 用start-cluster.bat启动flink
linux 用start-cluster.sh
在windows下装一个linux子系统就好了,具体怎么装参考网上教程,简单的一批什么配置都不需要,只要你的windows10够新哈哈哈
然后linux+windows并行,真香
在这里插入图片描述
cd /代表进入我的linux根目录
cd mnt是我的windows目录,下面有c d e三个盘符,进入就可以看到相应文件
另外安装子系统之后要配置jdk才能跑起来flink-scala的脚本,一种方法是wget+rpm文件的网址,另一种方法是tar -xvzf ***.tar.gz文件直接解压压缩包到想要安装的目录(中间可以用mv 源目录 目标目录的命令格式把文件移动到想要安装的目录下)
因为里面有一个conf目录下的什么什么文件需要JAVA_HOME的配置,而且在jdk1.4版本之后的都不需要配置classpath,vi \etc\profile,i或a进入编辑模式,然后在末尾添加下面的PATH

JAVA_HOME=/usr/local/jdk1.8.0_141 # jdk在哪里这里就是哪里,下面的不需要动的 
JAVA_BIN=$JAVA_HOME/bin
JRE_HOME=$JAVA_HOME/jre
JRE_BIN=$JRE_HOME/bin
PATH=$JAVA_BIN:$JRE_BIN:$PATH
export JAVA_HOME JRE_HOME PATH

激活环境变量

source \etc\profile

所以装完系统之后装一个jdk,配置好jdk的环境变量,我是配置在\etc\profile里面的,也就是针对全部用户进行配置,看教程还有什么配置在.bashrc和.bashfile乱七八糟的文件里,对应的就是系统的安全性问题,我是想反正电脑就我一个人用,我就自己配个全局就行了,以后多用户的时候可能就要好好配环境了。配环境变量的时候用vim命令进入编辑界面,然后a或i进行编辑,按Esc输入 :wq(保存并退出),如果不想保存就用 :q! 强制退出或者 :q 退出就可以了
装完jdk直接起我们的flink目录下的bin目录下的start-cluster.sh脚本就可以启动我们的集群了,jps命令可以查到进程信息
在这里插入图片描述
6116 StandaloneSessionClusterEntrypoint单机会话集群进入点
6475 TaskManagerRunner TaskManger运行器
6556 Jps
这三个东西的具体含义是啥?前面的数字每发送一次jps命令都是会变化的
shell下运行提交一个job

./bin/flink run -c com.atguigu.wc.StreamWordCount -p 1 /mnt/d/MyCodeforIDEA/JAVA/Second_Java/target/Second_Java-1.0-SNAPSHOT-jar-with-dependencies.jar --host localhost --port 7777

bin目录下的flink脚本+run±c+主类名±p+并行度+打包的jar包位置+运行参数
运行之后会出现:Job has been submitted with JobID 51b585aef6a7f2e7c04dd61caad24719
在这里插入图片描述

shell下取消cancel一个job

./bin/flink cancel 51b585aef6a7f2e7c04dd61caad24719

根据运行时起的jobID取消job,如果不记得全部可以用./bin/flink list查看所有的jobID,然后根据jobID取消:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_33472663/article/details/106118106
今日推荐