将flink提交到集群中运行,可以看到job的的执行计划、占用的资源情况、Task的数量和并行度、内存、checkpoint等信息。但是将必须先job打成jar包,然后通过web页面或命令行提交到集群中执行。
但是在开发测试时,想要看到job的执行计划和运行时的一些信息,就需要每一次都将程序打包并提交到集群中运行,这样就很麻烦。如果能在IEDA或Eclipse中本地运行时,也可以有一个web页面,那就更方便了!flink本身就支持local模式运行,并且local模式也可以有webui页面,只不过要添加一个maven的依赖即可。
- 第一步:在pom文件中添加依赖
<!– web ui的依赖 –> <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-runtime-web_2.12</artifactId> <version>1.12.0</version> </dependency> |
2. 第二部:创建local并且带ui的LocalEnvironmentWithWebUI
Configuration configuration = new Configuration(); StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(configuration); //带ui的Env |
3.在IDEA中运行程序,然后使用浏览器访问localhost:8081

web的rest端口号默认是8081,如果想改变端口号,可以在configuration中添加如下配置即可:
Configuration configuration = new Configuration(); configuration.setInteger(“rest.port”, 8082); StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(configuration); |
重启后用浏览器访问localhost:8082即可,就可以看到job的运行的信息了!
星哥原创,未经许可,不得转载