集群机器
创建三台机器node101,node102,node103
附加组件
https://flink.apache.org/downloads.html
启动集群-Hadoop
假设已经部署和启动好Hadoop集群

启动Flink-YARN-Session
## -n(--container):TaskManager 的数量,可以不设置,由YARN分配资源## -s(--slots): 每个TaskManager的slot数量,默认1个core对应1个slot,我们的例子中,1个core对应2个slot## -jm:JobManager 的内存(单位 MB)## -tm:每个 taskmanager 的内存,单位 MB## -nm:显示在yarn web ui的appName## -d:在后台执行[java@node101 bin]$ ./yarn-session.sh -n 2 -s 2 -jm 1600 -tm 1024 -nm flinkapp -d--------------------------------------------------------------------------------------2021-07-19 20:29:22,065 INFO org.apache.flink.configuration.GlobalConfiguration [] - Loading configuration property: jobmanager.rpc.address, node1012021-07-19 20:29:22,069 INFO org.apache.flink.configuration.GlobalConfiguration [] - Loading configuration property: jobmanager.rpc.port, 61232021-07-19 20:29:22,069 INFO org.apache.flink.configuration.GlobalConfiguration [] - Loading configuration property: jobmanager.memory.process.size, 1600m2021-07-19 20:29:22,069 INFO org.apache.flink.configuration.GlobalConfiguration [] - Loading configuration property: taskmanager.memory.process.size, 1728m2021-07-19 20:29:22,070 INFO org.apache.flink.configuration.GlobalConfiguration [] - Loading configuration property: taskmanager.numberOfTaskSlots, 22021-07-19 20:29:22,070 INFO org.apache.flink.configuration.GlobalConfiguration [] - Loading configuration property: parallelism.default, 12021-07-19 20:29:22,070 INFO org.apache.flink.configuration.GlobalConfiguration [] - Loading configuration property: jobmanager.execution.failover-strategy, region2021-07-19 20:29:22,495 WARN org.apache.hadoop.util.NativeCodeLoader [] - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable2021-07-19 20:29:22,606 INFO org.apache.flink.runtime.security.modules.HadoopModule [] - Hadoop user set to java (auth:SIMPLE)2021-07-19 20:29:22,638 INFO org.apache.flink.runtime.security.modules.JaasModule [] - Jaas file will be created as /tmp/jaas-56853801744925321.conf.2021-07-19 20:29:22,663 WARN org.apache.flink.yarn.configuration.YarnLogConfigUtil [] - The configuration directory ('/opt/module/flink-1.13.1/conf') already contains a LOG4J config file.If you want to use logback, then please delete or rename the log configuration file.2021-07-19 20:29:22,735 INFO org.apache.hadoop.yarn.client.RMProxy [] - Connecting to ResourceManager at node102/192.168.89.102:80322021-07-19 20:29:22,888 INFO org.apache.flink.runtime.util.config.memory.ProcessMemoryUtils [] - The derived from fraction jvm overhead memory (160.000mb (167772162 bytes)) is less than its min value 192.000mb (201326592 bytes), min value will be used instead2021-07-19 20:29:22,910 INFO org.apache.flink.runtime.util.config.memory.ProcessMemoryUtils [] - The derived from fraction jvm overhead memory (172.800mb (181193935 bytes)) is less than its min value 192.000mb (201326592 bytes), min value will be used instead2021-07-19 20:29:23,167 WARN org.apache.flink.yarn.YarnClusterDescriptor [] - Neither the HADOOP_CONF_DIR nor the YARN_CONF_DIR environment variable is set. The Flink YARN Client needs one of these to be set to properly load the Hadoop configuration for accessing YARN.2021-07-19 20:29:23,302 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - The configured JobManager memory is 1600 MB. YARN will allocate 2048 MB to make up an integer multiple of its minimum allocation memory (1024 MB, configured via 'yarn.scheduler.minimum-allocation-mb'). The extra 448 MB may not be used by Flink.2021-07-19 20:29:23,302 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - The configured TaskManager memory is 1728 MB. YARN will allocate 2048 MB to make up an integer multiple of its minimum allocation memory (1024 MB, configured via 'yarn.scheduler.minimum-allocation-mb'). The extra 320 MB may not be used by Flink.2021-07-19 20:29:23,306 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Cluster specification: ClusterSpecification{masterMemoryMB=1600, taskManagerMemoryMB=1728, slotsPerTaskManager=2}2021-07-19 20:29:33,322 INFO org.apache.flink.runtime.util.config.memory.ProcessMemoryUtils [] - The derived from fraction jvm overhead memory (160.000mb (167772162 bytes)) is less than its min value 192.000mb (201326592 bytes), min value will be used instead2021-07-19 20:29:33,339 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Submitting application master application_1626694871823_00012021-07-19 20:29:34,194 INFO org.apache.hadoop.yarn.client.api.impl.YarnClientImpl [] - Submitted application application_1626694871823_00012021-07-19 20:29:34,195 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Waiting for the cluster to be allocated2021-07-19 20:29:34,199 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Deploying cluster, current state ACCEPTED2021-07-19 20:29:50,062 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - YARN application has been deployed successfully.2021-07-19 20:29:50,064 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Found Web Interface node102:36065 of application 'application_1626694871823_0001'.JobManager Web Interface: http://node102:36065
查看YARN
http://node102:8088/cluster/apps


NC监听
[java@node101 bin]$ nc -lkv 7777Ncat: Version 7.70 ( https://nmap.org/ncat )Ncat: Listening on :::7777Ncat: Listening on 0.0.0.0:7777
提交任务
[java@node101 bin]$ ./flink run -c online.javabook.flink.quickstart.SocketWordCount /opt/module/flink-jobs/javabook.apache.flink-1.0-SNAPSHOT.jar --host 192.168.89.101 --port 77772021-07-19 20:47:12,813 INFO org.apache.flink.yarn.cli.FlinkYarnSessionCli [] - Found Yarn properties file under /tmp/.yarn-properties-java.2021-07-19 20:47:12,813 INFO org.apache.flink.yarn.cli.FlinkYarnSessionCli [] - Found Yarn properties file under /tmp/.yarn-properties-java.2021-07-19 20:47:13,357 WARN org.apache.flink.yarn.configuration.YarnLogConfigUtil [] - The configuration directory ('/opt/module/flink-1.13.1/conf') already contains a LOG4J config file.If you want to use logback, then please delete or rename the log configuration file.2021-07-19 20:47:13,463 INFO org.apache.hadoop.yarn.client.RMProxy [] - Connecting to ResourceManager at node102/192.168.89.102:80322021-07-19 20:47:13,621 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - No path for the flink jar passed. Using the location of class org.apache.flink.yarn.YarnClusterDescriptor to locate the jar2021-07-19 20:47:13,623 WARN org.apache.flink.yarn.YarnClusterDescriptor [] - Neither the HADOOP_CONF_DIR nor the YARN_CONF_DIR environment variable is set.The Flink YARN Client needs one of these to be set to properly load the Hadoop configuration for accessing YARN.2021-07-19 20:47:13,745 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Found Web Interface node103:33459 of application 'application_1626694871823_0002'.Job has been submitted with JobID e5206edf1f6902c7cc7906c56fb2b1fb
杀掉任务
[java@node101 bin]$ yarn application --kill [Yarn-applicatinId]


