在pom.xml文件中添加flink-runtime-web依赖
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-runtime-web</artifactId>
<version>1.16.1</version>
<scope>provided</scope>
</dependency>
在初始化执行环境时传入的配置中添加rest.port项
public static void main(String[] args) throws Exception {
//获取Flink的运行环境
Configuration conf = new Configuration();
conf.setInteger(RestOptions.PORT, 0);//设置为0 每次启动端口都不一样 也可以设置一个固定的端口 如8081
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
//checkpoint配置
env.enableCheckpointing(5000);
env.getCheckpointConfig().setCheckpointingMode(CheckpointingMode.EXACTLY_ONCE);
env.getCheckpointConfig().setMinPauseBetweenCheckpoints(500);
env.getCheckpointConfig().setCheckpointTimeout(60000);
env.getCheckpointConfig().setMaxConcurrentCheckpoints(1);
这样启动后就可以在日志中看到web ui的链接了:
15:26:07.833 [main] INFO org.apache.flink.runtime.dispatcher.DispatcherRestEndpoint - Web frontend listening at http://localhost:40673.15:26:07.833 [mini-cluster-io-thread-1] INFO org.apache.flink.runtime.dispatcher.DispatcherRestEndpoint - http://localhost:40673 was granted leadership with leaderSessionID=f08dd1d9-359f-4403-84af-79d2e7e41c9b15:26:07.834 [mini-cluster-io-thread-1] INFO org.apache.flink.runtime.highavailability.nonha.embedded.EmbeddedLeaderService - Received confirmation of leadership for leader http://localhost:40673 , session=f08dd1d9-359f-4403-84af-79d2e7e41c9b15:26:07.843 [main] INFO org.apache.flink.runtime.highavailability.nonha.embedded.EmbeddedLeaderService - Proposing leadership to contender LeaderContender: DefaultDispatcherRunner15:26:07.844 [main] INFO org.apache.flink.runtime.resourcemanager.ResourceManagerServiceImpl - Starting resource manager service.15:26:07.844 [main] INFO org.apache.flink.runtime.highavailability.nonha.embedded.EmbeddedLeaderService - Proposing leadership to contender LeaderContender: ResourceManagerServiceImpl15:26:07.844 [mini-cluster-io-thread-2] INFO org.apache.flink.runtime.dispatcher.runner.DefaultDispatcherRunner - DefaultDispatcherRunner was granted leadership with leader id 07b5356f-c8c9-4b20-99b0-7491f48c89b4. Creating new DispatcherLeaderProcess.15:26:07.845 [pool-3-thread-1] INFO
在浏览器中访问对应链接就可以看到web ui了
Flink 1.16.1亲测可用, 先前的版本可能还需要使用
Configurationconf=newConfiguration();
env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(conf);
但这样发布运行时还需要改下代码,1.16.1的代码里看了下createLocalEnvironmentWithWebUI方法:
做的事情也无非就时往配置项里添加了个rest.port.
扫描二维码关注公众号,回复:
16275952 查看本文章
所以调用getExecutionEnvironment(conf) 时直接设置下这个参数就行了,需要发布运行时也不用再修改代码。