【发布时间】:2017-01-09 20:42:08
【问题描述】:
我有一个将数据推送到 S3 存储桶的小型测试项目。但是,看起来我没有读取 core-site.xml 文件,因为我收到了错误java.io.IOException: No file system found with scheme s3a。如何正确读取 core-site.xml 文件并将数据推送到 S3?
这是代码:
public class S3Sink {
public static void main(String[] args) throws Exception {
Map<String, String> configs = ConfigUtils.loadConfigs(“path/to/config.yaml");
final ParameterTool parameterTool = ParameterTool.fromMap(configs);
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.getConfig().disableSysoutLogging();
env.getConfig().setGlobalJobParameters(parameterTool);
DataStream<String> messageStream = env
.addSource(new FlinkKafkaConsumer09<String>(
parameterTool.getRequired("kafka.topic"),
new SimpleStringSchema(),
parameterTool.getProperties()));
String id = UUID.randomUUID().toString();
messageStream.writeAsText("s3a://flink-test/" + id + ".txt").setParallelism(1);
env.execute();
}
这是 flink-conf.yaml 文件中的配置更改以引用 core-site.xml 文件:
fs.hdfs.hadoopconf: /path/to/core-site/etc/hadoop/
这是我的 core-site.xml:
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
<property>
<name>fs.s3.impl</name>
<value>org.apache.hadoop.fs.s3a.S3AFileSystem</value>
</property>
<!-- Comma separated list of local directories used to buffer
large results prior to transmitting them to S3. -->
<property>
<name>fs.s3a.buffer.dir</name>
<value>/tmp</value>
</property>
<!-- set your AWS ID using key defined in org.apache.hadoop.fs.s3a.Constants -->
<property>
<name>fs.s3a.awsAccessKeyId</name>
<value>*****</value>
</property>
<!-- set your AWS access key -->
<property>
<name>fs.s3a.awsSecretAccessKey</name>
<value>*****</value>
</property>
【问题讨论】:
-
如果将
fs.hdfs.hadoopconf设置为包含core-site.xml的文件夹,它会起作用吗?还要确保$HADOOP_HOME环境变量设置正确。 -
我正在使用 IntelliJ 并将环境变量 HADOOP_HOME 设置为 core-site.xml 路径。我在本地运行程序,所以 fs.hdfs.hadoopconf 设置没有帮助。
标签: xml hadoop amazon-s3 apache-flink