I. Download of Flink
Installation package: http://flink.apache.org/downloads.html, select Flink version for Hadoop download
[Email protected] software]$ wget http://MIRRORS.TUNA.TSINGHUA.EDU.CN/APACHE/FLINK/FLINK-1.6.1/ Flink-1.6.1-bin-hadoop27-scala_2.11.tgz[[email protected] software]$ ll1301867081 the : flink- 1.6. 1-bin-hadoop27-scala_2. tgz.
Flink has three deployment modes, namely Local, Standalone Cluster, and Yarn Cluster.
Two.Local mode
For the Local mode, JobManager and TaskManager will have a common JVM to complete the Workload. Local mode is most convenient if you want to validate a simple application. Most applications use Standalone or Yarn Cluster, while local mode simply extracts the installation package (./bin/start-local.sh), which is not shown here.
Three.Standalone Mode
Quick Start Tutorial Address: https://ci.apache.org/projects/flink/flink-docs-release-1.6/quickstart/setup_quickstart.html
1. Software Requirements
- Java version 1.8.x or later,
- SSH(you must run sshd to use the Flink script that manages remote components)
Cluster deployment planning
| Node name |
Master |
Worker |
Zookeeper |
| Node21 |
Master |
|
Zookeeper |
| Node22 |
Master |
Worker |
Zookeeper |
| Node23 |
|
Worker |
Zookeeper |
2.Unzip
[Email protected] software]$ tar zxvf flink-1.6. 1-bin-hadoop27-scala_2. tgz-c/opt/module//opt/module/[[email protected] module]$ lldrwxr8125 £ º flink- 1.6. 1
3.Modifying a configuration file
[email protected] conf]$ lsflink-conf.yaml log4j-console.properties Log4j-yarn-session.properties logback.xml Masters sql-client-defaults.yamllog4j- Cli.properties log4j.properties logback-console.xml logback-yarn.xml slaves zoo.cfg
Modify Flink/conf/masters,slaves,flink-conf.yaml
[email protected] conf]$ sudo vi mastersnode21: 8081 [[email protected] conf]$ sudo vi slavesnode22node23[[email protected] conf]$ sudo vi flink-Conf.yaml Tas Kmanager.numberoftaskslots:2jobmanager.rpc.address:node21
Optional configuration:
- each jobmanager (
jobmanager.heap.mb ) of the available memory ,
- each taskmanager (
taskmanager.heap.mb ) of the available memory ,
- the number of available CPUs per machine (
taskmanager.numberOfTaskSlots ),
- total number of CPUs in the cluster (
parallelism.default ) and
- Temp directory (
taskmanager.tmp.dirs )
4.Copy the installation package to each node
[Email protected] module]$ scp-r flink-1.6. 1/-R flink-1.6. 1/[email protected]: ' pwd '
5.Configuring environment Variables
Configuring environment variables for all node Flink
[Email protected] flink-1.6. 1] $ sudo vi/etc/profileexport flink_home=/opt/module/flink-1.6. 1 export PATH= $PATH: $FLINK _home/bin[[email protected] FLINK-1.6. 1]$ Source/etc/profile
6.Start Flink
[Email protected] flink-1.6. 1] $./bin/start-cluster.sh starting cluster. Starting standalonesession daemon on host node21. Starting Taskexecutor daemon on host Node22. Starting Taskexecutor daemon on host Node23.
JPS Viewing processes
7. WebUI View
http://node21:8081
8.Flink of HA
First, we need to know that Flink has two modes of deployment, namely Standalone and Yarn Cluster mode. For Standalone, Flink must rely on Zookeeper to implement JobManager ha (Zookeeper has become an essential module for most open source framework ha). With the help of Zookeeper, a Standalone Flink cluster will have multiple live jobmanager at the same time, only one of which is in the working state and the other in Standby state. When a working JobManager loses connectivity (such as downtime or Crash), Zookeeper will elect a new JobManager from Standby to take over the Flink cluster.
For yarn cluaster mode, Flink will rely on yarn itself to do HA for JobManager. In fact, this is a purely Yarn mechanism. For yarn Cluster mode, both JobManager and TaskManager are yarn-initiated in yarn Container. At this time, JobManager, in fact, should be called Flink application Master. It is also said that its failure to recover, it is entirely dependent on Yarn in the ResourceManager (and MapReduce appmaster the same). Due to the full reliance on yarn, different versions of yarn may have subtle differences. It's no longer a dig.
1)Modifying a configuration file
Modify Flink-conf.yaml
high-availability:zookeeper #指定高可用模式 (must)high-availability.zookeeper.quorum:node21:2181, Node22:2181, Node23:2181 #ZooKeeper仲裁是ZooKeeper服务器的复制组, which provides distributed coordination services (must)high- Availability.storageDir:hdfs://flink/harecovery/ #JobManager元数据保存在文件系统storageDir中, Only pointers pointing to this state are stored in zookeeper (must)High-availability.zookeeper.path.root:/flink
High-availability.cluster-id:/flinkcluster # Custom clusters (recommended)
Modify Conf/zoo.cfg
Server. 1=node21:2888:3888server. 2=node22:2888:3888server. 3=node23:2888:3888
Modify Conf/masters
NODE21:8081node22:8081
Modify Slaves
Node22node23
Synchronizing profiles conf to each node
2)start Ha
Start the DFS, and then start the Zookeeper cluster nodes (you can also use the Flink start-zookeeper-quorum.sh in the test environment). Flink
[email protected] flink-1.6. 1
3)Verifying ha
Manually kill Master on Node21, at which point the alternate master on the Node22 is converted to the master Mater.
4) Manually add the Jobmanager/taskmanager instance to the cluster
You can use bin/jobmanager.sh and the bin/taskmanager.sh The script adds JobManager and TaskManager instances to the running cluster .
Add JobManager
bin/jobmanager.sh ((start|start-foreground) [host] [webui-port])|stop|stop-all
Add TaskManager
bin/taskmanager.sh start|start-foreground|stop|stop-all
[Email protected] flink-1.6. 1] $ jobmanager.sh Start Node21
The newly added is from master.
9.Run a test task
[Email protected] flink-1.6. 1] $ flink run-m node21:8081 ./examples/batch/wordcount.jar--input/opt/wcinput/wc.txt--output/opt/wcoutput/< C3>[[email protected] Flink-1.6. 1] $ flink run-m node21:8081 ./examples/batch/wordcount.jar--input HDFs:///user/admin/input/ Wc.txt--output HDFs://user/admin/output2
Four.Yarn cluster mode1.introduced
In an enterprise, in order to maximize the use of cluster resources, it is common to run multiple types of Workload in one cluster at the same time. Therefore Flink also supports running on Yarn. First, let's understand the relationship between Yarn and Flink.
As can be seen in the figure, the relationship between Flink and yarn is the same as the relationship between MapReduce and yarn. The Flink implements its own App Master via the Yarn interface. When Flink,yarn is deployed in Yarn, it uses its own Container to launch Flink JobManager (i.e. App Master) and TaskManager.
When you start a new Flink yarn session, the client first checks that the requested resource (container and memory) is available. after that, it uploads the jar containing the Flink and configuration to HDFs (step 1).
the next step for the client is to request (step 2) yarn container to start Applicationmaster (step 3). Because the client registers the configuration and the jar file as a resource for the container, the NodeManager of yarn running on that particular machine will be responsible for preparing the container (for example, downloading the file). when complete, applicationmaster(AM) is started.
the JobManager run in the same container as AM. Once they start successfully, am knows the address of the JobManager (its own host). It is generating a new flink configuration file for taskmanagers (so that they can connect to JobManager). The file is also uploaded to HDFs. In addition,theAM Container also provides a Flink web interface. all the ports that yarn code assigns are ephemeral ports . This allows users to perform multiple flink yarn sessions in parallel.
after that, am begins allocating containers for Flink's taskmanagers, which will download the jar file and the modified configuration from HDFs. After you complete these steps, you can establish a flink and prepare to accept the job.
2.Modifying environment Variables
Export hadoop_conf_dir=/opt/module/hadoop-2.7.6/etc/hadoop
3.Deployment Startup
[Email protected] flink-1.6. 1 2 - 2
The number of-n:taskmanager, equal to the number of executor-s: The number of cores per JobManager, executor-cores. It is recommended to set the number of slots per machine-TM: the memory size of each TaskManager, Executor-memory-jm:jobmanager memory size, driver-memory
The above command means that at the same time apply to Yarn 3 Container, of which 2 Container start TaskManager (-N 2), each taskmanager has two Task slots (-S 2), and to each TaskManager The Container request 800M of memory, as well as a applicationmaster (Job Manager).
After the Flink is deployed to yarn cluster, the connection details for the job manager are displayed.
Flink on yarn will overwrite the following parameters, if you do not want to change the parameters in the configuration file, you can dynamically specify through the-D option, such as-dfs.overwrite-files=true- dtaskmanager.network.numberofbuffers=16368
Jobmanager.rpc.address: Because JobManager are often assigned to different machines.
Taskmanager.tmp.dirs: Using the TMP directory provided by yarn
Parallelism.default: If there is a specified number of slots
Yarn-session.sh suspends the process, so you can stop yarn-session by using CTRL + C at the terminal or by entering stop.
If you do not want Flink yarn client to run long, Flink provides a detached yarn session with the parameter-D or-detached when starting up
After the above command is successful, we can see the Flink record on the Yarn application page. Such as.
If you are testing in a virtual machine, you may experience errors. It is important to note that the size of the memory, Flink to yarn will apply for multiple Container, but yarn configuration may limit the amount of memory Container can request, even the yarn itself manages the memory is very small. This is likely to fail to start the TaskManager normally, especially if multiple taskmanager are specified. Therefore, after starting Flink, you need to check the status of Flink in the Flink page. Here you can jump directly from the RM page (click Tracking UI). This time the Flink page
The yarn-session.sh startup command parameters are as follows:
[Email protected] flink-1.6.1]$ yarn-session.sh-- Helpusage:required-N,--Container <arg> number of YARN container to allocate (=Number of Task Managers) Optional-D <property=value> Use value forgiven property-D,--detached If present, runs the jobinchdetached mode-H,--Help forThe Yarn session CLI. -id,--ApplicationID <arg>Attach to running YARN session-j,--Jar <arg>Path to Flink jar file-JM,--jobmanagermemory <arg> Memory forJobManager Container with optional unit (default: MB)-M,--JobManager <arg> Address of the JobManager (master) to which to connect. Use Thisflag to connect to a different jobmanager than the one specified in the configuration. -N,--Container <arg> number of YARN container to allocate (=Number of Task Managers)-NL,--nodelabel <arg> specify YARN node label forThe YARN application-NM,--name <arg> Set a custom name forThe application on YARN-Q,--Query Display available YARN resources (memory, cores)-qu,--Queue <arg>Specify YARN queue. -S,--Slots <arg>Number of slots per TaskManager-st,--streaming Start FlinkinchStreaming Mode-T,--ship <arg> ship filesinchThe specified directory (t fortransfer)-tm,--taskmanagermemory <arg> Memory per taskmanager Container with optional unit (default: MB)-yd,--yarndetached If present, runs the jobinchDetached mode (deprecated; Use non-YARN specific option instead)-Z,--zookeepernamespace <arg> Namespace to create the Zookeeper sub-paths forHigh Availability mode
4.Submit a Task
After that we can submit our mission in this way
[Email protected] flink-1.6. 1 2 ./examples/batch/wordcount.jar--input/opt/wcinput/wc.txt--output/opt/wcoutput/
The above command adds a Y prefix to the parameter and-yn indicates the number of TaskManager.
In this mode, you can also use the-M yarn-cluster to submit a "burn-on" detached yarn (-yd) job to yarn cluster.
5.Stop yarn Cluster
Yarn Application-kill application_1539058959130_0001
Five. Error exception 1. Timeout
caused by:java.util.concurrent.TimeoutException:Heartbeat of TaskManager with ID 96ab53853de9c9e56035d140d849c3bd Timed out.
Flink (ii) CentOS7.5 build Flink1.6.1 distributed cluster