flink问题集锦

报错一:

Could not get job jar and dependencies from JAR file: JAR file does not exist: -yn

原因:flink1.8版本之后已弃用该参数,ResourceManager将自动启动所需的尽可能多的容器,以满足作业请求的并行性。解决方法:去掉即可

报错二:

java.lang.IllegalStateException: No Executor found. Please make sure to export the HADOOP_CLASSPATH environment variable or have hadoop in your classpath.

方法1:

配置环境变量

export HADOOP_CLASSPATH=`hadoop classpath`
方法2:

下载对应版本flink-shaded-hadoop-2-uber,放到flink的lib目录下

报错三:

Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.2:compile (default) on project book-stream: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)

在这里插入图片描述

产生这个问题的原因有很多,重要的是查看error报错的信息,我这边主要是scala中调用了java的方法,但build时只指定了打包scala的资源,所以会找不到类报错,下面是build出错的行,把它注释掉、删掉,不指定sourceDirectory,所有的sourceDirectory都会打包进去就可解决。

<sourceDirectory>src/main/scala</sourceDirectory>
报错四:

org.apache.flink.client.program.ProgramInvocationException: The main method caused an error: Could not find a suitable table factory for ‘org.apache.flink.table.planner.delegation.ParserFactory’ in
the classpath.

这个错误也是因为打包时候没有将依赖打包进去、或者需要将依赖放到flink的lib目录下

maven换成了如下的build 的pulgin

 <build>
        <plugins>
 
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <version>2.15.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
 
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
 
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
 
        </plugins>
    </build>
警告五:

Multiple versions of scala libraries detected!
Expected all dependencies to require Scala version: 2.11.12
org.apache.flink:flink-runtime_2.11:1.13.2 requires scala version: 2.11.12
org.apache.flink:flink-scala_2.11:1.13.2 requires scala version: 2.11.12
org.apache.flink:flink-scala_2.11:1.13.2 requires scala version: 2.11.12
org.scala-lang:scala-reflect:2.11.12 requires scala version: 2.11.12
org.apache.flink:flink-streaming-scala_2.11:1.13.2 requires scala version: 2.11.12
org.apache.flink:flink-streaming-scala_2.11:1.13.2 requires scala version: 2.11.12
org.scala-lang:scala-compiler:2.11.12 requires scala version: 2.11.12
org.scala-lang.modules:scala-xml_2.11:1.0.5 requires scala version: 2.11.7

这是由于scala-maven-plugin打包插件版本低的问题

Starting from Scala 2.10 all changes in bugfix/patch version should be backward compatible, so these warnings don’t really have the point in this case. But they are still very important in case when, let’s say, you somehow end up with scala 2.9 and 2.11 libraries. It happens that since version 3.1.6 you can fix this using scalaCompatVersion configuration

方法1:指定scalaCompatVersion一样的版本
 <configuration>
        <scalaCompatVersion>${scala.binary.version}</scalaCompatVersion>                  <scalaVersion>${scala.version}</scalaVersion> 
 </configuration>

下面是完整的

<plugin>    
    <groupId>net.alchim31.maven</groupId>    
    <artifactId>scala-maven-plugin</artifactId>    
    <version>3.1.6</version>    
    <configuration>        
        <scalaCompatVersion>${scala.binary.version}</scalaCompatVersion>                   <scalaVersion>${scala.binary.version}</scalaVersion>    
    </configuration>    
    <executions>        
        <execution>            
            <goals>                
                <goal>compile</goal>            
            </goals>        
        </execution>    
    </executions>
</plugin>
方法2:打包插件换成4.x的版本
<plugin>    
    <groupId>net.alchim31.maven</groupId>    
    <artifactId>scala-maven-plugin</artifactId>    
    <version>4.2.0</version>    
    <executions>        
        <execution>            
            <goals>                
                <goal>compile</goal>            
            </goals>        
        </execution>    
    </executions>
</plugin>
### 常见问题及解决方案 #### 1. **任意JAR包上传导致远程代码执行** Apache Flink允许用户通过Web界面上传JAR文件,这一功能可能被恶意利用以上传包含恶意代码的JAR包,从而导致远程代码执行。为解决此问题,建议限制对Flink Web界面的访问权限,并确保仅授权用户能够上传JAR文件[^1]。 ```python # 示例:配置Flink Web界面的访问控制 # 在flink-conf.yaml中添加以下内容 web.submit: false # 禁用通过Web界面提交作业 ``` #### 2. **重启Flink作业时抛出异常** 在某些情况下,重启Flink作业可能会抛出`Wrong / missing exception when submitting job`的错误。这是由于Flink的一个已知BUG(FLINK-10312)引起的。该问题已在后续版本中修复,因此建议升级到最新版本的Flink[^2]。 #### 3. **依赖包重复问题** 当使用Flink连接Kafka时,需要同时引入`flink-connector-kafka`和`kafka-clients`两个依赖包。如果在打包过程中将这两个依赖包重复打入最终的JAR文件中,可能会导致运行时冲突或找不到依赖的问题。为了避免这种情况,可以将依赖范围设置为`provided`,并在运行时由Flink集群提供这些依赖[^4]。 ```xml <!-- Flink Kafka连接器 --> <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-connector-kafka_2.11</artifactId> <version>${flink-version}</version> <scope>provided</scope> </dependency> <!-- Kafka客户端 --> <dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka-clients</artifactId> <version>1.1.0</version> <scope>provided</scope> </dependency> ``` #### 4. **实时数据分析性能优化** 在构建基于Flink的实时数据分析系统时,性能优化是一个关键环节。可以通过调整并行度、优化状态管理、使用增量检查点等手段提升系统的吞吐量和稳定性[^3]。 ```java // 示例:调整Flink作业的并行度 streamExecutionEnvironment.setParallelism(4); ``` --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值