0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Mountpoint for Amazon S3を使用して複数EC2でファイル共有してみた

Posted at

Mountpoint for Amazon S3を使用して複数EC2でファイル共有してみた

概要

Amazon S3はオブジェクトストレージとして広く利用されていますが、従来のファイルベースのアプローチとの橋渡しとして、Mountpoint for Amazon S3が提供されています。今回、このMountpointを使用して、複数のEC2インスタンス間でのファイル共有を試してみました。

実施手順

S3バケットの作成

aws s3 mb s3://mount-point-for-s3

次に、2つのEC2インスタンスを作成。これらのインスタンスにはS3へのアクセス権を持たせるため、IAMロールにS3Accessロールを割り当てました。

aws ec2 run-instances --image-id ami-08c84d37db8aafe00 --count 1 --instance-type t2.micro --iam-instance-profile Name=S3Access
aws ec2 run-instances --image-id ami-08c84d37db8aafe00 --count 1 --instance-type t2.micro --iam-instance-profile Name=S3Access

その後、各インスタンスにMountpoint for Amazon S3のクライアントをインストールしました。

wget https://s3.amazonaws.com/mountpoint-s3-release/latest/x86_64/mount-s3.rpm
sudo yum install ./mount-s3.rpm

/mnt/s3ディレクトリを作成。このディレクトリを使用して、先ほど作成したmount-point-for-s3バケットをマウントしました。

mkdir /mnt/s3
mount-s3 mount-point-for-s3 /mnt/s3

最後に、テストファイルtest.txtを作成・削除して、インスタンス間でのファイル共有が正しく動作するか確認しました。
instance1にて

[root@ip-xxx-xxx-xxx-xxx s3]# touch test.txt

instance2にて

[root@ip-xxx-xxx-xxx-xxx s3]# touch test2.txt
[root@ip-xxx-xxx-xxx-xxx s3]# touch test3.txt
[root@ip-xxx-xxx-xxx-xxx s3]# ls
test.txt  test2.txt  test3.txt

ちゃんとファイル共有できていますね。

image.png
S3にもファイルが上がっています。

結論

Mountpoint for Amazon S3を使用すれば、EC2インスタンス間でのファイル共有は問題なく実現できます。
ただし、S3自体は同時アクセスやデータの競合に対して完全に強化されているわけではないため、特に書き込み操作などでの注意が必要です。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?