Amazon Web Services はFlinkを実行することができるクラウド計算サービスを提供します。
Amazon Elastic MapReduce (Amazon EMR) はHadoopクラスタを簡単に素早くセットアップwebサービスです。全てのセットアップの面倒を見るので、これはAWS上でFlinkを実行するお勧めの方法です。
Flink is a supported application on Amazon EMR. Amazon’s documentation describes configuring Flink, creating and monitoring a cluster, and working with jobs.
Amazon EMR services are regularly updated to new releases but a version of Flink which is not available can be manually installed in a stock EMR cluster.
EMR クラスタの作成
EMR ドキュメントはどうやってEMRクラスタを開始するかを示す例を含んでいます。そのガイドに従って任意のEMRリリースをインストールすることができます。You don’t need to install the All Applications part of the EMR release, but can stick to Core Hadoop.
Note Access to S3 buckets requires configuration of IAM roles when creating an EMR cluster.
EMRクラスタ上にFlinkをインストール
クラスタを作成した後で、マスターノードに接続し、Flinkをインストールします:
Amazon Simple Storage Service (Amazon S3) は様々な使い方のためのクラウド オブジェクト ストレージを提供します。You can use S3 with Flink for reading and writing data as well in conjunction with the streaming state backends or even as a YARN object storage.
以下の形式のパスを指定することでS3オブジェクトを通常のファイルのように使うことができます:
終端は1つのファイルまたはディレクトリのどちらかが成りえます。例えば:
これらの例は精緻なものではなく、高可用性セットアップ あるいは RocksDBStateBackendを含めて、S3を他の場所でも使えることに注意してください; FlinkがファイルシステムURIを期待するどこでも。
For most use cases, you may use one of our shaded flink-s3-fs-hadoop
and flink-s3-fs-presto
S3
filesystem wrappers which are fairly easy to set up. For some cases, however, e.g. for using S3 as
YARN’s resource storage dir, it may be necessary to set up a specific Hadoop S3 FileSystem
implementation. Both ways are described below.
To use either flink-s3-fs-hadoop
or flink-s3-fs-presto
, copy the respective JAR file from the
opt
directory to the lib
directory of your Flink distribution before starting Flink, e.g.
Both flink-s3-fs-hadoop
and flink-s3-fs-presto
register default FileSystem wrappers for URIs with the s3://
scheme, flink-s3-fs-hadoop
also registers for s3a://
.
After setting up the S3 FileSystem wrapper, you need to make sure that Flink is allowed to access your S3 buckets.
AWS上で証明書をセットアップするお勧めの方法は Identity and Access Management (IAM)を使います。S3バケットにアクセスするためにFlinkインスタンスに証明書を安全に渡すために、IAM機能を使うことができます。これを行う方法の詳細はこのドキュメントの範囲を超えます。AWSユーザガイドを参照してください。探すものはIAM Rolesです。
これを正しくセットアップすると、AWS内のS3へのアクセスを管理することができ、Flinkに何もアクセスキーを配布する必要がありません。
S3へのアクセスはアクセスおよび秘密キーのペアを使って保証されます。IAM rolesの紹介なので、これは非推奨であることに注意してください。
You need to configure both s3.access-key
and s3.secret-key
in Flink’s flink-conf.yaml
:
This setup is a bit more complex and we recommend using our shaded Hadoop/Presto file systems
instead (see above) unless required otherwise, e.g. for using S3 as YARN’s resource storage dir
via the fs.defaultFS
configuration property in Hadoop’s core-site.xml
.
Interaction with S3 happens via one of Hadoop’s S3 FileSystem clients:
S3AFileSystem
(recommended for Hadoop 2.7 and later): file system for reading and writing regular files using Amazon’s SDK internally. ファイルの最大サイズが無く、IAM roleと連携します。NativeS3FileSystem
(for Hadoop 2.6 and earlier): file system for reading and writing regular files. 最大オブジェクトサイズは5GBで、IAM role と連携しません。S3AFileSystem
(お勧め)使うことをお勧めするS3ファイルシステム実装です。It uses Amazon’s SDK internally and works with IAM roles (see Configure Access Credentials).
Flinkが有効なHadoop設定を示す必要があります。これはcore-site.xml
内で以下のプロパティを含みます:
This registers S3AFileSystem
as the default FileSystem for URIs with the s3a://
scheme.
NativeS3FileSystem
This file system is limited to files up to 5GB in size and it does not work with IAM roles (see Configure Access Credentials), meaning that you have to manually configure your AWS credentials in the Hadoop config file.
Flinkが有効なHadoop設定を示す必要があります。これはcore-site.xml
内で以下のプロパティを含みます:
これはs3://
スキーマを使うURIのためのデフォルトのファイルシステムとしてNativeS3FileSystem
を登録します。
You can specify the Hadoop configuration in various ways pointing Flink to the path of the Hadoop configuration directory, for example
HADOOP_CONF_DIR
, orfs.hdfs.hadoopconf
configuration option in flink-conf.yaml
:これはFlinkを使ってHadoopの設定ディレクトリとして/path/to/etc/hadoop
を登録します。Flinkは指定されたディレクトリのcore-site.xml
とhdfs-site.xml
ファイルを調べないでしょう。
S3ファイルシステムをセットアップした後で、FlinkがS3バケットにアクセスすることができることを確実にする必要があります。
When using S3AFileSystem
, the recommended way of setting up credentials on AWS is via Identity and Access Management (IAM). S3バケットにアクセスするためにFlinkインスタンスに証明書を安全に渡すために、IAM機能を使うことができます。これを行う方法の詳細はこのドキュメントの範囲を超えます。AWSユーザガイドを参照してください。探すものはIAM Rolesです。
これを正しくセットアップすると、AWS内のS3へのアクセスを管理することができ、Flinkに何もアクセスキーを配布する必要がありません。
これは S3AFileSystem
とだけ連携し、NativeS3FileSystem
とは連携しないことに注意してください。
S3AFileSystem
(Discouraged)S3へのアクセスはアクセスおよび秘密キーのペアを使って保証されます。IAM rolesの紹介なので、これは非推奨であることに注意してください。
S3AFileSystem
のために、Hadoopのcore-site.xml
の中でfs.s3a.access.key
と fs.s3a.secret.key
の両方を設定する必要があります :
NativeS3FileSystem
(Discouraged)S3へのアクセスはアクセスおよび秘密キーのペアを使って保証されます。しかし、これは非推奨で、必要とされるIAM ロールを持つS3AFileSystem
を使う必要があります。
NativeS3FileSystem
のために、Hadoopのcore-site.xml
の中でfs.s3.awsAccessKeyId
と fs.s3.awsSecretAccessKey
の両方を設定する必要があります :
Hadoop’s S3 FileSystem clients are packaged in the hadoop-aws
artifact (Hadoop version 2.6 and later). このJARと全ての依存はFlinkのクラスパスに追加される必要があります。別の言い方をすると、ジョブとタスクマネージャーの両方のクラスパスです。どのファイルシステム実装およびどのFlinkおよびHadoopバージョンを使うかに依存して、異なる依存を提供する必要があります(以下を見てください)。
There are multiple ways of adding JARs to Flink’s class path, the easiest being simply to drop the JARs in Flink’s lib
folder. 全ての依存と一緒にhadoop-aws
JARをコピーする必要があります。全てのマシーン上でHADOOP_CLASSPATH
環境変数の一部としてこれらのJARを含むディレクトリもエクスポートします。
どのファイルシステムを使っているかに依存して、以下の依存を追加してください。hadoop-2.7/share/hadoop/tools/lib
の中のHadoopバイナリの一部として見つけることができます:
S3AFileSystem
:
hadoop-aws-2.7.3.jar
aws-java-sdk-s3-1.11.183.jar
and its dependencies:
aws-java-sdk-core-1.11.183.jar
aws-java-sdk-kms-1.11.183.jar
jackson-annotations-2.6.7.jar
jackson-core-2.6.7.jar
jackson-databind-2.6.7.jar
joda-time-2.8.1.jar
httpcore-4.4.4.jar
httpclient-4.5.3.jar
NativeS3FileSystem
:
hadoop-aws-2.7.3.jar
guava-11.0.2.jar
hadoop-common
はFlinkの一部として利用可能ですが、GuavaはFlinkによって共有されます。
どのファイルシステムを使っているかに依存して、以下の依存を追加してください。hadoop-2.6/share/hadoop/tools/lib
の中のHadoopバイナリの一部として見つけることができます:
S3AFileSystem
:
hadoop-aws-2.6.4.jar
aws-java-sdk-1.7.4.jar
and its dependencies:
jackson-annotations-2.1.1.jar
jackson-core-2.1.1.jar
jackson-databind-2.1.1.jar
joda-time-2.2.jar
httpcore-4.2.5.jar
httpclient-4.2.5.jar
NativeS3FileSystem
:
hadoop-aws-2.6.4.jar
guava-11.0.2.jar
hadoop-common
はFlinkの一部として利用可能ですが、GuavaはFlinkによって共有されます。
これらのHadoopのバージョンはNativeS3FileSystem
のためのサポートのみを持ちます。これはhadoop-common
の一部としてHadoop 2 のためのFlinkと一緒に事前パッケージ化されて同梱されています。クラスパスには何も追加する必要はありません。
以下の章はAWS上でFlinkと連携する時の一般的な問題をリスト化します。
ジョブのサブミットがNo file system found with scheme s3
に注目した例外メッセージを伴って失敗した場合、このことはS3のために設置されたファイルシステムが無いことを意味します。Please check out the configuration sections for our shaded Hadoop/Presto or generic Hadoop file systems for details on how to configure this properly.
ジョブがAWS Access Key ID and Secret Access Key must be specified as the username or password
に注目した例外を伴って失敗した場合、アクセス証明書が適切にセットアップされていません。Please refer to the access credential section for our shaded Hadoop/Presto or generic Hadoop file systems for details on how to configure this.
この例外を見た場合は、S3ファイルシステムがFlinkのクラスパスの一部ではありません。これを適切に設定する方法の詳細は S3 ファイルシステム依存の章を参照してください。
400: Bad Request
If you have configured everything properly, but get a Bad Request
Exception and your S3 bucket is located in region eu-central-1
, you might be running an S3 client, which does not support Amazon’s signature version 4.
あるいは
This should not apply to our shaded Hadoop/Presto S3 file systems but can occur for Hadoop-provided
S3 file systems. In particular, all Hadoop versions up to 2.7.2 running NativeS3FileSystem
(which
depend on JetS3t 0.9.0
instead of a version >= 0.9.4)
are affected but users also reported this happening with the S3AFileSystem
.
Except for changing the bucket region, you may also be able to solve this by
requesting signature version 4 for request authentication,
e.g. by adding this to Flink’s JVM options in flink-conf.yaml
(see
configuration):
This Exception is usually caused by skipping the local buffer directory configuration fs.s3a.buffer.dir
for the S3AFileSystem
. S3AFileSystem
を適切に設定する方法を理解するために、S3AFileSystem 設定を参照してください。