LoginSignup
33
33

More than 5 years have passed since last update.

Apache Spark ドキュメント和訳 - Apache Spark on AWS EC2

Last updated at Posted at 2014-06-09

Apache Sparkについて

Apache Software Foundationで最近トップレベルプロジェクトになり5月に最速でバージョン1がリリースされた分散処理基盤のオープンソースプロダクト。
MapReduce on HDFSとことなり繰り返し演算処理の情報をシェアードメモリで共有するため演算速度が爆速とうたわれています。

バッチでしか処理できなかった部分をリアルタイム化、タイムラグを減らすなど今後大きな期待ができるプロジェクトです。

参考他プロジェクト
Twitter Stormとか

EC2で簡単にクラスタを構築できるスクリプトが用意されています。

こちらの日本語訳をさらっと。変なところがあったらご指摘ください。

Quick StartやEC2での導入ガイドも和訳していますのであわせてご覧ください。

Running Spark on EC2 (Spark をEC2で起動する)

The spark-ec2 script, located in Spark’s ec2 directory, allows you to launch, manage and shut down Spark clusters on Amazon EC2. It automatically sets up Spark, Shark and HDFS on the cluster for you. This guide describes how to use spark-ec2 to launch clusters, how to run jobs on them, and how to shut them down. It assumes you’ve already signed up for an EC2 account on the Amazon Web Services site.

Sparkのec2フォルダに配置されているspark-ec2スクリプトを使えば、Amazon EC2上のSparkクラスターを起動・管理・停止することができる。
このスクリプトは自動的にSpark, Shark, HDFSをクラスタ上にセットアップする。
このガイドはspark-ec2スクリプトを利用してクラスターを構築したり、ジョブを実行したり、クラスタを停止したりするための方法を記述します。

spark-ec2 is designed to manage multiple named clusters. You can launch a new cluster (telling the script its size and giving it a name), shutdown an existing cluster, or log into a cluster.

spark-ec2スクリプトは複数の名前のクラスターを管理できるように設計されている。
あなたは(サイズと名前を指定して)新しいクラスターを起動したり、名前を指定して起動済みクラスタを停止したり、クラスタにログインすることができる。

Each cluster is identified by placing its machines into EC2 security groups whose names are derived from the name of the cluster.

それぞれのクラスターは配置されたマシンとクラスタ名から名付けられるEC2セキュリティーグループ名で完全に独立して動作する。

For example, a cluster named test will contain a master node in a security group called test-master, and a number of slave nodes in a security group called test-slaves.

例えばあるtestと名付けられたクラスタがマスターノードをtest-masterセキュリティグループに含まれる場合、スレーブノード群はtest-slavesとなる。

The spark-ec2 script will create these security groups for you based on the cluster name you request. You can also use them to identify machines belonging to each cluster in the Amazon EC2 Console.

spark-ec2スクリプトはこれらのセキュリティグループをあなたが要求したクラスタ名に基づいて生成する。あなたはそれらをAmazon EC2コンソールからそれぞれのインスタンスを所属させて利用することができる。

Before You Start (起動の前に)

Create an Amazon EC2 key pair for yourself. This can be done by logging into your Amazon Web Services account through the AWS console, clicking Key Pairs on the left sidebar, and creating and downloading a key. Make sure that you set the permissions for the private key file to 600 (i.e. only you can read and write it) so that ssh will work.

EC2でキーペアを登録しておいてください。AWSコンソールにログインして簡単に登録できます。(以下略)

Whenever you want to use the spark-ec2 script, set the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to your Amazon EC2 access key ID and secret access key. These can be obtained from the AWS homepage by clicking Account > Security Credentials > Access Credentials.

spark-ec2スクリプトを利用したいなら環境変数AWS_ACCESS_KEYとAWS_SECRET_ACCESS_KEYをアクセスキーIDを取得して作成してください。

(補足)ここに書いてあるクレデンシャル取得よりもIAMロールを作ってクレデンシャルを作った方が実運用ではよいと思います。

Launching a Cluster(クラスターを起動する)

Go into the ec2 directory in the release of Spark you downloaded.

Sparkをダウンロード・解凍したフォルダ内のec2ディレクトリにはいってください。

Run ./spark-ec2 -k -i -s launch , where is the name of your EC2 key pair (that you gave it when you created it), is the private key file for your key pair, is the number of slave nodes to launch (try 1 at first), and is the name to give to
your cluster.

以下のコマンドを実行してください。

./spark-ec2 -k <keypair> -i <key-file> -s <num-slaves> launch <cluster-name>

はあなたがEC2で登録したキーペア名、
はプライベートキーファイルパス、
はスレーブノードを起動する数(少なくとも1以上)
は起動するクラスターに与える任意の名前です。

After everything launches, check that the cluster scheduler is up and sees all the slaves by going to its web UI, which will be printed at the end of the script (typically http://:8080).

全て起動した後にクラスタースケジューラーが木同士全てのスレーブがweb UIから確認できるかチェックしてください。Web UIのURLはスクリプト実行の最後に表示されます。
(一般的に http://master-hostname>:8080/)

You can also run ./spark-ec2 --help to see more usage options. The following options are worth pointing out:

./spark-ec2 --helpを実行すれば利用可能なオプションを表示できる。下記のオプションは有用な一部オプションの抜粋です。

--instance-type= can be used to specify an EC2 instance type to use. For now, the script only supports 64-bit instance types, and the default type is m1.large (which has 2 cores and 7.5 GB RAM). Refer to the Amazon pages about EC2 instance types and EC2 pricing for information about other instance types.

EC2インスタンスタイプを指定できます。現在は64bitインスタンスタイプのみサポートしています。デフォルトのタイプはm2.large(2コア:7.5GBメモリ)です。他のインスタンスタイプについてはAmazon EC2のインスタンスタイプと料金表のページを参照してください。

--region= specifies an EC2 region in which to launch instances. The default region is us-east-1.

EC2のリージョンを指定できます。デフォルトのリージョンはus-east-1(バージニア)です。

--zone= can be used to specify an EC2 availability zone to launch instances in. Sometimes, you will get an error because there is not enough capacity in one zone, and you should try to launch in another.

EC2のインスタンスを起動するアベイラビリティゾーンを指定できます。まれに一つのゾーンに十分なキャパシティがないためのエラーが発生しますので、他のゾーンを指定して解決してください。

--ebs-vol-size=GB will attach an EBS volume with a given amount of space to each node so that you can have a persistent HDFS cluster on your nodes across cluster restarts (see below).

強固なHDFSクラスタをノード上に再構築する為にそれぞれのノードのEBSボリュームをGB単位で指定します。

--spot-price=PRICE will launch the worker nodes as Spot Instances, bidding for the given maximum price (in dollars).

ワーカーノードをスポットインスタンスとして最大料金を指定しベッドします。最大料金はUSドルで指定してください。

--spark-version=VERSION will pre-load the cluster with the specified version of Spark. VERSION can be a version number (e.g. “0.7.3”) or a specific git hash. By default, a recent version will be used.

明示的にバージョンを指定してsparkのプレロードをおこないます。バージョン番号は"0.7.3"のように指定するかgitのハッシュで指定してください。
デフォルトは最新のバージョンです。(2014/06/09現在は1.0.0)

If one of your launches fails due to e.g. not having the right permissions on your private key file, you can run launch with the --resume option to restart the setup process on an existing cluster.

もしも[not having the righe permissions on your private key file,]等表示されて起動に失敗した場合は、--resumeオプションをつけてリスタートさせることで存在するクラスタのセットアッププロセスを利用できます。

Running Applications (アプリケーションを稼働させる)

Go into the ec2 directory in the release of Spark you downloaded.

Sparkのec2フォルダに入ってください。

Run ./spark-ec2 -k -i login to SSH into the cluster, where and are as above. (This is just for convenience; you could also use the EC2 console.)

以下のコマンドで指定のクラスタにSSHログインしてください。

./spark-ec2 -k <keypair> -i <key-file> login <cluster-name>

とは前述の通りです。(これは利便性のためだけの機能です。EC2コンソールを利用することもできます。)

To deploy code or data within your cluster, you can log in and use the provided script ~/spark-ec2/copy-dir, which, given a directory path, RSYNCs it to the same location on all the slaves.

コードやデータをあなたのクラスターに配置してください。
用意されたスクリプト、/spark-ec2/copy-dirを利用して指定したディレクトリパス、RSYNCsで、スレーブの同じロケーションに配備できます。

If your application needs to access large datasets, the fastest way to do that is to load them from Amazon S3 or an Amazon EBS device into an instance of the Hadoop Distributed File System (HDFS) on your nodes. The spark-ec2 script already sets up a HDFS instance for you. It’s installed in /root/ephemeral-hdfs, and can be accessed using the bin/hadoop script in that directory. Note that the data in this HDFS goes away when you stop and restart a machine.

もしあなたのアプリケーションが巨大なデータセットにアクセスする必要があるなら、もっとも早い方法はAmazonS3かAmazon EBSでバイスからノード上のインスタンスのHDFS(Hadoop Distributed File System)に読み込むことです。
spark-ec2スクリプトはHDFSを自動的にインスタンスに構築しています。
/root/ephemeral-hdfsにインストールされており、bin/hadoopスクリプトを利用してディレクトリにアクセスできます。
マシンをストップしたりリスタートするとこのHDFSクラスタは消えてしまうことに注意してください。

There is also a persistent HDFS instance in /root/persistent-hdfs that will keep data across cluster restarts. Typically each node has relatively little space of persistent data (about 3 GB), but you can use the --ebs-vol-size option to spark-ec2 to attach a persistent EBS volume to each node for storing the persistent HDFS.

永続的なHDFSインスタンスも/root/persistent-hdfsに用意されており、クラスターを再起動してもこれらのデータは存続します。
一般的にそれぞれのノードは関連した少しの永続データスペース(3GB程度)を保持します、しかし--ebs-vol-sizeオプションをspark-ec2スクリプトで利用することで永続的EBSボリュームをそれぞれのノードにHDFSとしてアタッチすることができます。

Finally, if you get errors while running your application, look at the slave’s logs for that application inside of the scheduler work directory (/root/spark/work). You can also view the status of the cluster using the web UI: http://:8080.

最後に、もしアプリケーション実行時にエラー担った場合、スケジューラーのワークディレクトリ(/root/spark/work)のスレーブログを見てください。
Web UI(http://:8080/)で状態を確認することもできます。

Configuration (設定)

You can edit /root/spark/conf/spark-env.sh on each machine to set Spark configuration options, such as JVM options. This file needs to be copied to every machine to reflect the change. The easiest way to do this is to use a script we provide called copy-dir. First edit your spark-env.sh file on the master, then run ~/spark-ec2/copy-dir /root/spark/conf to RSYNC it to all the workers.

それぞれのマシン上の/root/spark/conf/spark-env.shを編集してSparkの設定オプションを設定することができます。例えばJVMオプションなど。このファイルは全てのマシンに変更をコピーする必要があります。この設定ファイルのコピーを簡単におこなうにはcopy-dirを使うと良いでしょう。
最初にマスター上でspark-env.shファイルを編集し、~/spark-ec2/copy-dir /root/spark/confをRSYNCすることで全てのワーカーに同期されます。

The configuration guide describes the available configuration options.

利用可能な設定オプションは設定ガイドに記載しています。

Terminating a Cluster (クラスターを破棄する)

Note that there is no way to recover data on EC2 nodes after shutting them down! Make sure you have copied everything important off the nodes before stopping them.

クラスタをシャットダウンするとEC2ノード上のデータをリカバーする方法はありません。
停止する前に重要なものは全てコピーしてバックアップをとりましょう。

Go into the ec2 directory in the release of Spark you downloaded.
Run ./spark-ec2 destroy .

Sparkのec2ディレクトリに移動します。
./spark-ec2 destory を実行してください。

怖い怖い。

Pausing and Restarting Clusters (一時停止と再稼働)

The spark-ec2 script also supports pausing a cluster. In this case, the VMs are stopped but not terminated, so they lose all data on ephemeral disks but keep the data in their root partitions and their persistent-hdfs. Stopped machines will not cost you any EC2 cycles, but will continue to cost money for EBS storage.

spark-ec2スクリプトはクラスタの一時停止機能をサポートしています。この場合、VMは停止しますがクラスタは破棄されませんので一時ディスク上のデータを失うことはなく、rootパーティションにそれらのデータを保持します。
マシンがストップされている間、EC2のコストはかかりませんが、EBSストレージの料金は継続的に発生します。

To stop one of your clusters, go into the ec2 directory and run ./spark-ec2 stop .

クラスタを一時停止する為にはec2ディレクトリにはいって下記コマンドを実行してください。

./spark-ec2 stop <cluster-name>

To restart it later, run ./spark-ec2 -i start .

停止したクラスタを再起動させるにはec2ディレクトリにはいって下記コマンドを実行してください。

./spark-ec2 -i <key-file> start <cluster-name>

To ultimately destroy the cluster and stop consuming EBS space, run ./spark-ec2 destroy as described in the previous section.

最後にクラスタを破棄、EBSスペースを使い果たしてストップする場合は前述のspark-ec2 destory を利用してください。

Limitations (制限事項)

Support for “cluster compute” nodes is limited – there’s no way to specify a locality group. However, you can launch slave nodes in your -slaves group manually and then use spark-ec2 launch --resume to start a cluster with them.
If you have a patch or suggestion for one of these limitations, feel free to contribute it!

クラスタコンピューティングのノード数は制限があります。ローカリティグループを明示する方法はありません。しかし、-slavesグループにスレーブノードを手動で起動しspark-ec2で復元スタートをすることでノード数を増やすことができます。
もしこの制限事項に対応するパッチや提案があれば寄贈してください!

Accessing Data in S3 (S3上のデータにアクセス)

Spark’s file interface allows it to process data in Amazon S3 using the same URI formats that are supported for Hadoop.

SparkのファイルインターフェイスはHadoopでサポートされているようにAmazon S3に対して同じURIフォーマットでアクセスをサポートしています。

You can specify a path in S3 as input through a URI of the form s3n:///path.

s3n:///pathの書式のURIを通してS3のパスを指定できます。

You will also need to set your Amazon security credentials, either by setting the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY before your program or through SparkContext.hadoopConfiguration.

プログラムを実行する前、SparkContext.hadoopConfigurationを通じてAmazonのセキュリティコンフィデンシャルを環境変数AWS_ACCESS_KEY_IDとAWS_SECRET_ACCESS_KEYに設定する必要があります。

Full instructions on S3 access using the Hadoop input libraries can be found on the Hadoop S3 page.

Hadoopの入力ライブラリを通したS3へのアクセスの導入はHadoop S3のページをご覧ください。

訳者注)
ささっと訳しただけなので言い回しとかおかしければご指摘ください。

33
33
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
33
33