当前位置: 首页 > news >正文

FLINK单机版安装部署入门-1

文章目录

    • FLINK单机版安装部署
    • 高于1.9.3需要修改配置文件flink-conf.yaml(低于1.9.3可以跳过)
    • linux启动集群
    • windows下启动
    • Flink实例运行(单机)
    • 还有一种方式是上传任务包运行examples\streaming
    • java: Compilation failed: internal java compiler error
    • 高版本启动脚本

FLINK单机版安装部署

官网下载Downloads | Apache Flink

下载文件历史版本的1.9.3

https://archive.apache.org/dist/flink/flink-1.9.3/flink-1.9.3-bin-scala_2.11.tgz

# 下载Flink安装包(笔者这里测试使用Flink1.9版本,其它版本下载目录 https://flink.apache.org/downloads.html)
wget https://archive.apache.org/dist/flink/flink-1.9.3/flink-1.9.3-bin-scala_2.11.tgz# 解压
tar -xzvf flink-1.9.3-bin-scala_2.11.tgz

netCat是linux下自带的支持TCP、UDP、Unix域协议套接字小工具,nc命令允许你创建一个连接、侦听另一个连接和传输数据。在windows环境中也可以使用
使用命令:nc -lk port号
说明: -l listen监听某个端口 k:保持住当前的连接,程序终止的话,当前server不断开
功能:启动了一个可以发送socket文本流的服务器,端口:7777

下载地址 netcat 1.11 for Win32/Win64

https://eternallybored.org/misc/netcat/

注意:

服务启动依赖jdk环境变量(确保已经安装了Java_jdk)

加上环境变量

vi source /etc/profile

export JAVA_HOME=/opt/zulu_jdk11.68.17
export PATH=$JAVA_HOME/bin:$PATHexport PATH=/opt/flink-1.9.3/bin:$PATAT

source /etc/profile

高于1.9.3需要修改配置文件flink-conf.yaml(低于1.9.3可以跳过)

修改端口号(默认端口不影响的可以直接跳过端口配置)

进入conf目录下 flink-conf.yaml 修改rest.port (8081端口过于常用,容易出现端口冲突,笔者这里改为8001)

#rest.port: 8081
rest.port: 8001

windows下需要加入如下配置,否则执行start-cluster.bat会导致TaskManager进程会退出

taskmanager.cpu.cores: 2
taskmanager.memory.task.heap.size: 512m
taskmanager.memory.managed.size: 512m
taskmanager.memory.network.min: 64m
taskmanager.memory.network.max: 64m

加上后会启动JobManager和TaskManager

linux启动集群

进入bin目录执行下面命令

# 启动Flink集群
./start-cluster.sh# 停止Flink集群
#./stop-cluster.sh

访问Flink UI,链接http://host:8778/#/overview,查看dashboard (这里的host为部署flink的机器host)

windows下启动

windows当前能支持的最高版本是1.9.3,直接安装就行;更高的版本已经不支持windos启动了,连启动脚本都已经没有

高版本参考如下:仅供参考但是不保证能成功,基本会失败;

cmd命令行启动

flink-1.9.3\bin>.\start-cluster.bat

启动后可以在管理页面看到Available Task Slots有一个可用的slots,如果没有参考上面的flink-config.yaml缺少windows下配置项

Flink实例运行(单机)

Flink安装包自带了测试样例,这里可以运行WordCount样例程序

flink-\flink-1.9.3\bin> ./flink run D:\workspace\IDE\flink-1.9.3\examples\batch\WordCount.jar

还有一种方式是上传任务包运行examples\streaming

examples\streaming\SocketWindowWordCount.jar

该样例为从一个ip端口获取数据,并进行单词数量统计,用来模拟数据流

运行样例分为本地运行命令行和UI界面提交运行,也就是分为本地模式和服务器模式两种

先启动端口TCP字符流

nc -lp 8888

./flink sun -c org.apache.flink.streaming.examples.socket.SocketWindowWordCount -p 1 D:\workspace\IDE\flink-1.9.3\examples\streaming\SocketWindowWordCount.jar --host localhost --port 8888

-m:指定主机名后面的端口为 JobManager的 REST 通信端口,而不是 RPC的端口,RPC通信端口是 6123(在提交任务时,是通过 REST 端口号(HTTP端口号),将任务上传到 JobManager.)

-c: 执行的主类,指定 main 方法的全类名

-p:运行的slot实例数=最大为当前所有实例数

-jar包路径

-host port :外部参数这里指参数接收的ip和端口号

在管理页面的submit new job中上传 任务jar即可

http://localhost:8001/#/submit

–hostname localhost --port 8888

这里我们依然以example中的WordCount.jar为例提交,点击该明细会出现执行的main文件路径合参数配置,默认即可,点击submit提交

job样例源码

https://gitee.com/jian_yang_lv

flink视频教程

https://www.bilibili.com/video/BV1eg4y1V7AN?p=1&vd_source=439eb7a06dc0a72103551f415ea81556

java: Compilation failed: internal java compiler error

https://blog.csdn.net/weixin_42923363/article/details/126698963

高版本启动脚本

Windows下是没有启动脚本的,这里贴上CMD启动脚本

参考资料:https://blog.csdn.net/xuexijava85/article/details/114803489

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 off
setlocalSET bin=%~dp0
SET FLINK_HOME=%bin%..
SET FLINK_LIB_DIR=%FLINK_HOME%\lib
SET 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

start-cluster.bat

这里,我把start-cluster.bat放在bin文件夹同级目录中,而没有放在bin目录里面

::###############################################################################
::  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.
:: author:zjcjava time:2023/05/24
::###############################################################################@echo off
setlocal EnableDelayedExpansion::#####这里我直接使用根目录拼接config和bin目录的path路径
SET FLINK_HOME=%cd%
SET bin==%FLINK_HOME%\bin
::### SET FLINK_HOME=%bin%..
echo ###############################################################################
echo FLINK_HOME %FLINK_HOME%
SET FLINK_LIB_DIR=%FLINK_HOME%\lib
SET FLINK_PLUGINS_DIR=%FLINK_HOME%\plugins
SET FLINK_CONF_DIR=%FLINK_HOME%\conf
SET FLINK_LOG_DIR=%FLINK_HOME%\logecho FLINK_CONF_DIR:%FLINK_CONF_DIR%
echo ###############################################################################
SET JVM_ARGS=-Xms1024m -Xmx1024mSET FLINK_CLASSPATH=%FLINK_LIB_DIR%\*SET logname_jm=flink-%username%-jobmanager.log
SET logname_tm=flink-%username%-taskmanager.log
SET log_jm=%FLINK_LOG_DIR%\%logname_jm%
SET log_tm=%FLINK_LOG_DIR%\%logname_tm%
SET outname_jm=flink-%username%-jobmanager.out
SET outname_tm=flink-%username%-taskmanager.out
SET out_jm=%FLINK_LOG_DIR%\%outname_jm%
SET out_tm=%FLINK_LOG_DIR%\%outname_tm%SET log_setting_jm=-Dlog.file="%log_jm%" -Dlogback.configurationFile=file:"%FLINK_CONF_DIR%/logback.xml" -Dlog4j.configuration=file:"%FLINK_CONF_DIR%/log4j.properties"
SET log_setting_tm=-Dlog.file="%log_tm%" -Dlogback.configurationFile=file:"%FLINK_CONF_DIR%/logback.xml" -Dlog4j.configuration=file:"%FLINK_CONF_DIR%/log4j.properties":: Log rotation (quick and dirty)
CD "%FLINK_LOG_DIR%"
for /l %%x in (5, -1, 1) do (
SET /A y = %%x+1
RENAME "%logname_jm%.%%x" "%logname_jm%.!y!" 2> nul
RENAME "%logname_tm%.%%x" "%logname_tm%.!y!" 2> nul
RENAME "%outname_jm%.%%x" "%outname_jm%.!y!"  2> nul
RENAME "%outname_tm%.%%x" "%outname_tm%.!y!"  2> nul
)
RENAME "%logname_jm%" "%logname_jm%.0"  2> nul
RENAME "%logname_tm%" "%logname_tm%.0"  2> nul
RENAME "%outname_jm%" "%outname_jm%.0"  2> nul
RENAME "%outname_tm%" "%outname_tm%.0"  2> nul
DEL "%logname_jm%.6"  2> nul
DEL "%logname_tm%.6"  2> nul
DEL "%outname_jm%.6"  2> nul
DEL "%outname_tm%.6"  2> nulfor %%X in (java.exe) do (set FOUND=%%~$PATH:X)
if not defined FOUND (echo java.exe was not found in PATH variablegoto :eof
)echo Starting a local cluster with one JobManager process and one TaskManager process.echo You can terminate the processes via CTRL-C in the spawned shell windows.echo Web interface by default on http://localhost:8081/.start java %JVM_ARGS% %log_setting_jm% -cp "%FLINK_CLASSPATH%"; org.apache.flink.runtime.entrypoint.StandaloneSessionClusterEntrypoint --configDir "%FLINK_CONF_DIR%" > "%out_jm%" 2>&1
start java %JVM_ARGS% %log_setting_tm% -cp "%FLINK_CLASSPATH%"; org.apache.flink.runtime.taskexecutor.TaskManagerRunner --configDir "%FLINK_CONF_DIR%" > "%out_tm%" 2>&1endlocal
http://www.lryc.cn/news/475054.html

相关文章:

  • 深度学习-学习率调整策略
  • 【学员提问bug】小程序在onUnload里面调接口,用来记录退出的时间, 但是接口调用还没成功, 页面就关闭了。如何让接口在onUnload关闭前调用成功?
  • 【刷题13】链表专题
  • Python Turtle模块详解与使用教程
  • 【PTA】4-2 树的同构【数据结构】
  • Node.js——fs模块-同步与异步
  • Java基于微信小程序的私家车位共享系统(附源码,文档)
  • vscode 创建 vue 项目时,配置文件为什么收缩到一起展示了?
  • PySpark任务提交
  • 【果蔬购物商城管理与推荐系统】Python+Django网页界面+协同过滤推荐算法+管理系统网站
  • 【大模型】海外生成式AI赛道的关键玩家:OpenAI、Anthropic之外还有谁?
  • kubevirt cloud-init配置
  • Oracle 大表添加索引的最佳方式
  • 速度了解云原生后端!!!
  • 云计算Openstack 虚拟机调度策略
  • 在 macOS 上添加 hosts 文件解析的步骤
  • RHCE【防火墙】
  • 基于springboot的招聘系统的设计与实现
  • 长度最小的子数组(滑动窗口)
  • 构建灵活、高效的HTTP/1.1应用:探索h11库
  • 大学英语救星!GPT助你完美解答完型填空和阅读理解
  • 【linux】centos编译安装openssl1.1.1
  • SpringBoot环境下的学生请假管理平台开发
  • 基于Transformer的路径规划 - 第五篇 GPT生成策略_解码方法优化
  • 项目模块十三:Util模块
  • 10款舞台剧免费音频剪辑软件分享,你用过哪款?
  • Redis常见面试题:ZSet底层数据结构,SDS、压缩列表ZipList、跳表SkipList
  • 496.下一个更大元素Ⅰ
  • C++类和对象上
  • 《图像边缘检测算法综述》