image.png

集群机器

创建三台机器node101,node102,node103

附加组件

https://flink.apache.org/downloads.html
image.png

下载hadoop组件放到flink lib目录

image.png

启动集群-Hadoop

假设已经部署和启动好Hadoop集群

image.png

不启动Flink-YARN-Session

  1. ## 不启动 yarn-session.sh
  2. ## [java@node101 bin]$ ./yarn-session.sh -n 2 -s 2 -jm 1600 -tm 1024 -nm flinkapp -d

NC监听

  1. [java@node101 bin]$ nc -lkv 7777
  2. Ncat: Version 7.70 ( https://nmap.org/ncat )
  3. Ncat: Listening on :::7777
  4. Ncat: Listening on 0.0.0.0:7777

提交任务

  1. [java@node101 bin]$ ./flink run -m yarn-cluster -c online.javabook.flink.quickstart.SocketWordCount /opt/module/flink-jobs/javabook.apache.flink-1.0-SNAPSHOT.jar --host 192.168.89.101 --port 7777
  2. 2021-07-19 19:02:30,959 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.
  3. 2021-07-19 19:02:31,113 INFO org.apache.hadoop.yarn.client.RMProxy [] - Connecting to ResourceManager at node102/192.168.89.102:8032
  4. 2021-07-19 19:02:31,337 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 jar
  5. 2021-07-19 19:02:31,814 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.
  6. 2021-07-19 19:02:31,992 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.
  7. 2021-07-19 19:02:31,993 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.
  8. 2021-07-19 19:02:31,993 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Cluster specification: ClusterSpecification{masterMemoryMB=1600, taskManagerMemoryMB=1728, slotsPerTaskManager=2}
  9. 2021-07-19 19:02:45,828 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Submitting application master application_1626692284287_0001
  10. 2021-07-19 19:02:47,225 INFO org.apache.hadoop.yarn.client.api.impl.YarnClientImpl [] - Submitted application application_1626692284287_0001
  11. 2021-07-19 19:02:47,225 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Waiting for the cluster to be allocated
  12. 2021-07-19 19:02:47,230 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Deploying cluster, current state ACCEPTED
  13. 2021-07-19 19:03:19,572 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - YARN application has been deployed successfully.
  14. 2021-07-19 19:03:19,573 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Found Web Interface node102:39069 of application 'application_1626692284287_0001'.
  15. Job has been submitted with JobID 3f9f08072db5596d7d70460da206c637

查看YARN

  1. http://node102:8088/cluster/apps

  • application

    image.png

    image.png

  • Log

    [java@node101 bin]$ nc -lkv 7777
    Ncat: Version 7.70 ( https://nmap.org/ncat )
    Ncat: Listening on :::7777
    Ncat: Listening on 0.0.0.0:7777
    hello flink
    hello yarn
    

    image.png

    杀掉任务

    [java@node101 bin]$ yarn application --kill [Yarn-applicatinId]