2
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 3 years have passed since last update.

【AWS S3】S3バケットをEC2にマウントしてみる

2
Posted at

goofysを使ってS3バケットをEC2にマウントしてみます。

インストール

依存パッケージのインストール

sudo yum install -y golang fuse

READMEに書いてある通りにやるとビルドでエラーが出るので、バイナリをインストールします。

sudo curl -sS -L -o /usr/local/bin/goofys https://github.com/kahing/goofys/releases/download/v0.24.0/goofys
sudo chmod 755 /usr/local/bin/goofys

バケット作成

 aws s3 mb s3://バケット名

マウント

# マウントポイント作成
sudo mkdir /mnt/s3
sudo chown ec2-user:ec2-user /mnt/s3 

# マウント
# 何かエラーがったら/var/log/messagesに書き込まれます。
goofys バケット名 /mnt/s3

# マウントされたか確認
df -h
# Filesystem                   Size  Used Avail Use% Mounted on
# ... 中略 ...
# バケット名  1.0P     0  1.0P   0% /mnt/s3

# マウント解除
sudo umount /mnt/s3

fstabの設定

起動と同時にマウントする場合は /etc/fstab に追記します。
fstabの書式 -> fstabについて | Qiita

# rootユーザーでawsの認証情報を参照できる必要があるので、とりあえずシンボリックリンクを設定しておきます。
sudo ln -s /home/ec2-user/.aws /root/.aws

# アカウントのuidとgidを調べます
id

# fstabに設定(後述)を追記します
sudo vim /etc/fstab

# fstabの設定が正しいか確認
sudo mount -a
df -h

fstabに追記する設定。バケット名とマウントポイント、--uid、--gidを設定してください。

/usr/local/bin/goofys#バケット名  /mnt/s3        fuse     _netdev,allow_other,--file-mode=0666,--dir-mode=0777,--uid=1000,--gid=1000    0       0

リブートして、 /mnt/s3 にバケットがマウントされていればOKです。

■ 参考

2
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
2
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?