UnsupportedFileSystemSchemeException: Could not find a file system implementation for scheme ‘s3‘

在使用Flink的yarn-session模式运行任务时遇到UnsupportedFileSystemSchemeException,问题在于缺少对S3的支持。解决方案是添加flink-s3-fs-hadoop和flink-s3-fs-presto插件到plugins目录下,并重启yarn-session。按照提示,将两个插件的jar文件分别复制到对应目录后,问题得到解决。

flink UnsupportedFileSystemSchemeException: Could not find a file system implementation for scheme ‘s3’

Caused by: org.apache.flink.core.fs.UnsupportedFileSystemSchemeException: Could not find a file system implementation for scheme 's3'. The scheme is directly supported by Flink through the following plugins: flink-s3-fs-hadoop, flink-s3-fs-presto. Please ensure that each plugin resides within its own subfolder within the plugins directory. See https://ci.apache.org/projects/flink/flink-docs-stable/ops/plugins.html for more information. If you want to use a Hadoop file system for that scheme, please add the scheme to the configuration fs.allowed-fallback-filesystems. For a full list of supported file systems, please see https://ci.apache.org/projects/flink/flink-docs-stable/ops/filesystems/.
	at org.apache.flink.core.fs.FileSystem.getUnguardedFileSystem(FileSystem.java:513)
	at org.apache.flink.core.fs.FileSystem.get(FileSystem.java:407)
	at org.apache.flink.streaming.api.functions.source.ContinuousFileMonitoringFunction.run(ContinuousFileMonitoringFunction.java:214)
	at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:110)
	at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:66)
	at org.apache.flink.streaming.runtime.tasks.SourceStreamTask$LegacySourceFunctionThread.run(SourceStreamTask.java:269)

yarn-session模式提交task,出现UnsupportedFileSystemSchemeException,
查看 flink-conf.yaml文件,参数fs.allowed-fallback-filesystems已经配置。
在这里插入图片描述
回看错误,发现以下提示信息

The scheme is directly supported by Flink through the following plugins: 
flink-s3-fs-hadoop, flink-s3-fs-presto.
 Please ensure that each plugin resides within its own subfolder within the plugins directory. 
 See https://ci.apache.org/projects/flink/flink-docs-stable/ops/plugins.html

应该是在升级flink版本的时候,忘记配置flink的plugins,查看plugins目录,果然没有flink-s3-fs-hadoop, flink-s3-fs-presto
在这里插入图片描述
如何配置这些插件,好在提示信息中给了参考网址,打开对应的网址,我得到了如何配置的信息。
在这里插入图片描述
按提示配置了s3-fs-hadoop和 flink-s3-fs-presto插件,命令如下:

# s3-fs-hadoop
mkdir ./plugins/s3-fs-hadoop
cp ./opt/flink-s3-fs-hadoop-1.13.1.jar ./plugins/s3-fs-hadoop/

#flink-s3-fs-presto
mkdir ./plugins/s3-fs-presto
cp ./opt/flink-s3-fs-presto-1.13.1.jar ./plugins/s3-fs-presto/

重启一下yarn-session, 然后重新提交task,没有错误了。

在这里插入图片描述

在使用 Apache Flink 时,如果遇到 `Could not find a file system implementation for scheme &#39;hdfs&#39;` 错误,这通常表示 Flink 无法识别或加载 HDFS 文件系统的实现类。该问题常见于尝试访问 HDFS 上的文件但缺少必要的依赖项或配置不正确的情况下。 ### 原因分析与解决方案 #### 1. 缺少 Hadoop 依赖 Flink 使用 Hadoop 的文件系统接口来支持 HDFS。因此,必须确保 Flink 环境中包含了 Hadoop 客户端库。可以通过以下方式解决: - **Maven 项目**:在 `pom.xml` 中添加 Hadoop 客户端依赖: ```xml <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-client</artifactId> <version>3.3.6</version> <!-- 根据你的 Hadoop 版本进行调整 --> </dependency> ``` - **独立运行模式(Standalone 或集群)**:将 Hadoop 客户端 JAR 包放入 Flink 的 `lib/` 目录下,例如 `hadoop-client-3.3.6.jar`[^1]。 #### 2. 配置文件缺失或错误 HDFS 连接需要 `core-site.xml` 和 `hdfs-site.xml` 等配置文件。这些文件应放置在 Flink 配置目录(如 `conf/`)下的 `flink-conf.yaml` 所指定的位置,或者通过代码显式加载。 - 在 Java/Scala 代码中显式设置 Hadoop 配置路径: ```java Configuration config = new Configuration(); config.addResource(new Path("file:///path/to/core-site.xml")); config.addResource(new Path("file:///path/to/hdfs-site.xml")); FileSystem.initialize(config); // 初始化文件系统 ``` #### 3. Scheme 未注册 有时即使有正确的依赖和配置,Flink 仍可能无法自动识别 `hdfs://` 协议。可以手动注册文件系统实现类: ```java Configuration config = new Configuration(); FileSystem.initialize(config); ``` 并在 `flink-conf.yaml` 中添加如下配置: ```yaml fs.hdfs.impl: org.apache.hadoop.hdfs.DistributedFileSystem ``` #### 4. 检查 Flink 版本兼容性 某些旧版本的 FlinkHadoop 的支持有限。建议使用与 Hadoop 兼容的 Flink 发行版,例如带有 Hadoop 支持的捆绑包(如 `flink-1.17.0-bin-hadoop3-scala_2.12.tgz`)。 #### 5. 日志与调试信息 启用详细日志有助于诊断问题根源。可以在 `log4j.properties` 中设置日志级别为 DEBUG: ```properties logger.org.apache.flink.fs=DEBUG ``` --- ### 示例代码:读取 HDFS 文件 以下是一个使用 FlinkHDFS 读取文本文件的示例: ```java import org.apache.flink.api.common.functions.MapFunction; import org.apache.flink.api.java.DataSet; import org.apache.flink.api.java.ExecutionEnvironment; import org.apache.flink.core.fs.FileSystem; public class HDFSReadExample { public static void main(String[] args) throws Exception { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); // 设置 Hadoop 配置 org.apache.hadoop.conf.Configuration hadoopConf = new org.apache.hadoop.conf.Configuration(); hadoopConf.addResource(new org.apache.hadoop.fs.Path("file:///path/to/core-site.xml")); hadoopConf.addResource(new org.apache.hadoop.fs.Path("file:///path/to/hdfs-site.xml")); FileSystem.initialize(hadoopConf); // 读取 HDFS 文件 DataSet<String> text = env.readFile(FileSystem.getDefaultFileSystem().createInput(new Path("hdfs://namenode:9000/user/input/file.txt"))); // 处理数据 DataSet<String> upperText = text.map((MapFunction<String, String>) String::toUpperCase); // 输出结果 upperText.print(); } } ``` ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值