LoginSignup
36
34

More than 5 years have passed since last update.

[S3] OS X に goofys 入れて S3 をマウントする

Last updated at Posted at 2016-06-17

goofys 使うと、S3バケットを直接マウントしてファイルシステムのように使用することが可能ですが、Homebrew 使えばわりかし簡単に OS X でも使用できたので、やり方をさらっと

環境整備

Homebrew インストール

まずは、Homebrew が入ってないと話になりません。
入ってない場合はいれましょう。

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

参考: Homebrew

golang インストール

Homebrew 入れたら、次は golang のインストール

$ brew install golang
$ [ ! -e ~/go/ ] && mkdir ~/go
$ export GOROOT=/usr/local/opt/go/libexec
$ export GOPATH=$HOME/go
$ export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

export で始まる3行は ~/.bash_profile にも書いておいた方がいいでしょう。

FUSE for OS X インストール

次に FUSE for OS X をインストール

Homebrew Cask が入ってない場合はインストール

$ brew install caskroom/cask/brew-cask

FUSE for OS Xをインストール

$ brew cask install osxfuse

参考: OS X YosemiteでNTFSフォーマットのディスクに書き込めるようにする

awscli インストール

awscli 入れて configure

$ brew install awscli
$ aws configure

goofys インストール

goofys をインストール

$ go get github.com/kahing/goofys
$ go install github.com/kahing/goofys
$ goofys -h
Error: goofys takes exactly two arguments.

NAME:
   goofys - Mount an S3 bucket locally

USAGE:
   goofys [global options] bucket[:prefix] mountpoint

VERSION:
   0.0.6

GLOBAL OPTIONS:
   --help, -h           Print this help text and exit successfuly.
   -o value         Additional system-specific mount options. Be careful!
   --dir-mode value     Permissions bits for directories. (default: 0755) (default: 493)
   --file-mode value        Permission bits for files (default: 0644) (default: 420)
   --uid value          UID owner of all inodes. (default: 500)
   --gid value          GID owner of all inodes. (default: 500)
   --endpoint value     The non-AWS endpoint to connect to. Possible values: http://127.0.0.1:8081/
   --region value       The non-AWS endpoint to connect to. Possible values: us-east-1, us-west-1, us-west-2, eu-west-1, eu-central-1, ap-southeast-1, ap-southeast-2, ap-northeast-1, sa-east-1, cn-north-1 (default: "us-west-2")
   --storage-class value    The type of storage to use when writing objects. Possible values: REDUCED_REDUNDANCY, STANDARD, STANDARD_IA. (default: "STANDARD")
   --use-path-request       Use a path-style request instead of virtual host-style. (deprecated, always on)
   --profile value      Use a named profile from $HOME/.aws/credentials instead of "default"
   --use-content-type       Set Content-Type according to file extension and /etc/mime.types (default: off)
   --stat-cache-ttl value   How long to cache StatObject results and inode attributes. (default: 1m0s)
   --type-cache-ttl value   How long to cache name -> file/dir mappings in directory inodes. (default: 1m0s)
   --debug_fuse         Enable fuse-related debugging output.
   --debug_s3           Enable S3-related debugging output.
   -f               Run goofys in foreground.
   --version, -v        print the version

goofys の使用方法

マウント

goofys でマウントするには、以下の感じでやります

$ goofys -o allow_other --uid {uid} --gid {gid} --region {リージョン} {s3バケット名} {マウントポイント}

uid と gid は id コマンドで調べましょう。

$ id
uid=501(wokamoto) gid=20(staff) groups=20(staff),...

wokamoto ユーザの uid は 501 で、gid 20 の staff グループに所属してるみたいですね。

例えば ap-northeast-1 にある s3-example って S3 バケットを ~/s3 にマウントしたい場合は、以下のとおり。

$ goofys -o allow_other --uid 501 --gid 20 --region ap-northeast-1 s3-example ~/s3

やったー 1PB のボリュームとして認識されたよ

$ df -h
Filesystem                                  Size   Used  Avail Capacity  iused      ifree %iused  Mounted on
/dev/disk1                                 233Gi  205Gi   27Gi    89% 53803254    7182088   88%   /
devfs                                      199Ki  199Ki    0Bi   100%      688          0  100%   /dev
map -hosts                                   0Bi    0Bi    0Bi   100%        0          0  100%   /net
map auto_home                                0Bi    0Bi    0Bi   100%        0          0  100%   /home
s3-example                                 1.0Pi    0Bi  1.0Pi     0%        0 1000000000    0%   /Users/wokamoto/s3

うまくいかない時は...

goofys コマンドがうまくいかない場合は -f とか --debug_s3 とか --debug_fuse パラメータつけて起動すればなんかメッセージでます。

$ goofys -o allow_other --uid 501 --gid 20 --region ap-northeast-1 --debug_s3 --debug_fuse -f s3-example ~/s3
2016/06/17 16:42:31.029518 s3.DEBUG DEBUG: Request s3/HeadBucket Details:
---[ REQUEST POST-SIGN ]-----------------------------
HEAD http://s3-ap-northeast-1.amazonaws.com/s3-example HTTP/1.1
Host: s3-ap-northeast-1.amazonaws.com
User-Agent: aws-sdk-go/1.0.0 (go1.6; darwin; amd64)
Authorization: AWS4-HMAC-SHA256 ...

アンマウント

アンマウントしたい時は sudo umount {マウントポイント}
例えば ~/s3 にマウントしていたのであれば...

$ sudo umount ~/s3

良い S3 ライフを!

36
34
1

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
36
34