Step1:下载
为了运行Flink,请提前安装好Java8环境,可通过以下命令检查是否安装成功:
> Java -version
FLink官方下载地址:[https://flink.apache.org/zh/downloads.html](https://flink.apache.org/zh/downloads.html),下载之后解压:
> tar -xzf flink-1.14.2-bin-scala_2.11.tgz> cd flink-1.14.2-bin-scala_2.11
Step2:启动
Flink自带了一个启动脚本,用于启动本地集群:
> ./bin/start-cluster.shStarting cluster.Starting standalonesession daemon on host.Starting taskexecutor daemon on host.
启动之后,通过jps -l命令查看进程是否启动成功。<br /><br />访问localhost:8081,确认界面正常启动。<br />注:Flink在1.9版本之前还提供了Windows版本的bat启动脚本,1.9版本之后不再提供,如若搭建Windows环境,可使用下述脚本:<br />在Flink安装目录的bin目录下,新建名为flink的文件,内容如下:
#!/usr/bin/env bash################################################################################# 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.################################################################################target="$0"# For the case, the executable has been directly symlinked, figure out# the correct bin path by following its symlink up to an upper bound.# Note: we can't use the readlink utility here if we want to be POSIX# compatible.iteration=0while [ -L "$target" ]; doif [ "$iteration" -gt 100 ]; thenecho "Cannot resolve path: You have a cyclic symlink in $target."breakfils=`ls -ld -- "$target"`target=`expr "$ls" : '.* -> \(.*\)$'`iteration=$((iteration + 1))done# Convert relative path to absolute pathbin=`dirname "$target"`# get flink config. "$bin"/config.shif [ "$FLINK_IDENT_STRING" = "" ]; thenFLINK_IDENT_STRING="$USER"fiCC_CLASSPATH=`constructFlinkClassPath`log=$FLINK_LOG_DIR/flink-$FLINK_IDENT_STRING-client-$HOSTNAME.loglog_setting=(-Dlog.file="$log" -Dlog4j.configuration=file:"$FLINK_CONF_DIR"/log4j-cli.properties -Dlogback.configurationFile=file:"$FLINK_CONF_DIR"/logback.xml)# Add HADOOP_CLASSPATH to allow the usage of Hadoop file systemsexec $JAVA_RUN $JVM_ARGS "${log_setting[@]}" -classpath "`manglePathList "$CC_CLASSPATH:$INTERNAL_HADOOP_CLASSPATHS"`" org.apache.flink.client.cli.CliFrontend "$@"
新建名为flink.bat文件,内容如下:
::###############################################################################:: 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.::###############################################################################@echo offsetlocalSET bin=%~dp0SET FLINK_HOME=%bin%..SET FLINK_LIB_DIR=%FLINK_HOME%\libSET FLINK_PLUGINS_DIR=%FLINK_HOME%\pluginsSET JVM_ARGS=-Xmx512mSET FLINK_JM_CLASSPATH=%FLINK_LIB_DIR%\*java %JVM_ARGS% -cp "%FLINK_JM_CLASSPATH%"; org.apache.flink.client.cli.CliFrontend %*endlocal
Step3:测试
Flink自带了许多示例作业,你可以任选一个快速部署到已搭建的集群上。
> ./bin/flink run examples/streaming/WordCount.jar> tail log/flink-*-taskexecutor-*.out(nymph,1)(in,3)(thy,1)(orisons,1)(be,4)(all,2)(my,1)(sins,1)(remember,1)(d,4)
你也可以通过Flink的Web UI来监视集群的状态和正在运行的作业。
Step4:停止集群
如果你需要停止正在运行的集群,可通过如下脚本停止:
> ./bin/stop-cluster.sh
