LoginSignup
6
4

More than 5 years have passed since last update.

Amazon Linux で goofys を使う

Posted at

EC2 のディスク容量はいつも心配事。AWS EFS も出てきましたけれど、月額100ドル以上ぐらい払わないとアクセス速後が遅いまま。なので S3 のバケットを EC2 にマウントするという方法があります。

お断り

データ転送量

安価にスタートできますが、 データ転送量が2重 にかかります。

データの流れは、S3 -(1)-> EC2 -(2)-> ユーザーになります。

(1) では S3 のデータ転送料金、

(2) は EC2 のデータ転送料金がかかります。

ディスク読み込み速度

S3<->EC2 では、VPC の外と通信するのでネットワーク速度は必然的に落ちます。
ディスクアクセススピードが求められるファイルは置かないようにしましょう (SWAP とか)。

AWS アカウント側の設定 (マネージメントコンソール)

S3 バケットを作成

書き込み許可をさせたい S3 バケットを作成。

S3 用の Policy と IAM ユーザー作成

Policy を作成。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::[S3バケット名]",
                "arn:aws:s3:::[S3バケット名]/*"
            ]
        }
    ]
}

IAM ユーザーを作成し、さきほどのポリシーを付与。
Access ID & Secret Key をゲットする。

EC2 側の goofys のインストールと設定

goofys のインストール

$ # root ユーザー
$ yum -y install golang fuse
$ aws configure
# AWS S3 の IAM Access ID/Secret Key を設定
$ vi .bash_profile
export GOPATH=$HOME/go
PATH=${PATH}:${GOPATH}/bin
$ echo $GOPATH
#パスが正常に設定されているか確認
$ go get github.com/kahing/goofys
$ go install github.com/kahing/goofys

S3 ストレージをマウント

$ # root ユーザー
$ mkdir -p [マウントポイント]
$ id [許可したいuser] # [uid] [gid] を書き留める
$ goofys -o nonempty -o allow_other --uid=[uid] --gid=[gid] --dir-mode=0777 --file-mode=0666 [S3バケット名] [マウントポイント]

再起動しても自動マウントされるよう設定

$ # root ユーザー
$ vi /etc/fstab
$ /root/go/bin/goofys#[S3バケット名] [マウントポイント] fuse _netdev,allow_other,--dir-mode=0777,--file-mode=0666,--uid=[uid],--gid=[gid] 0 0
$ mount -a

--dir-mode & --file-mode は適宜変更。
EC2 内から chmod & chown できなく、すべてこの設定が有効化される。

参考情報

参考
https://qiita.com/kooohei/items/a14f22cb0381342d1861

6
4
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
6
4