Mountpoint for Amazon S3 で S3 Bucket を自動マウントする
AWS の S3 Bucket を Linux のファイルシステムとしてマウントするには下記の選択肢があります。 下記のうち、s3fs は最も古いようですが、パフォーマンス比較すると「goofys の方が処理速度が早い」と結論づけている方が多いようです (※ 私は s3fs を試したことがありません)。 Mountpoint for Amazon S3 は最も後発です。 AWS 自体が開発に参加しているようですが、現時点でも「/etc/fstab をサポートしない為、起動時に自動マウントする」ということが出来ないようです。 この「自動マウント」については後述します。
これらに関して、過去に幾つかのメモを書きました。 その一部が下記です。
- EC2 上の CentOS7 から goofys で S3 をマウントする(IAM ロール利用編)
- ARM 版 Amazon Linux 2023 に Mountpoint for Amazon S3 をインストールする
上記のメモを書いた時点では、Mountpoint for Amazon S3 のインストールは「ソースコードからビルドする」手順が公式にガイドされていました。 ですが、現時点では RPM / DEB 形式のパッケージが提供されている為、インストールが簡単になりました。 今回は改めて、Mountpoint for Amazon S3 のインストール手順をメモしておきます。
インストール¶
パッケージが用意されている為、インストールは簡単です。 ご自分の環境に合わせたパッケージをダウンロードし、インストールするだけです。 パッケージの URL は GitHub に記載されています。
curl -LO https://s3.amazonaws.com/mountpoint-s3-release/latest/x86_64/mount-s3.rpm
sudo dnf -y install mount-s3.rpm
尚、現時点で DEB 形式パッケージのインストール手順は下記のように記載されていました。
wget https://s3.amazonaws.com/mountpoint-s3-release/latest/x86_64/mount-s3.deb
sudo apt-get install -y ./mount-s3.deb
今回は Amazon Linux 2023 へインストールしました。 パスは /usr/bin/mount-s3 に、バージョンは 1.0.2 がインストールされました。
S3 Bucket をマウントする¶
基本的な使い方は簡単です。 S3 Bucket 名とマウントしたいパスを指定するだけです。
OS 起動時に S3 Bucket を自動マウントする¶
Mountopint for Amazon S3 は /etc/fstab には現時点でも対応していないらしく、OS 起動時に S3 Bucket を自動マウントさせることが出来ません。 この問題については GitHub Issue である Auto mount bucket to local directory e.g. on instance reboot #441 で言及されています。 この問題の回避策として「(fstab を使うのでは無く) デーモンとして Mountpoint for Amazon S3 を実行する」というアプローチが紹介されています。
この手順で問題を回避するには、まず systemd 用の Unit ファイルを用意します。 例えば以下のような内容で作成します。
cat << EOF > /lib/systemd/system/mount-s3.service
[Unit]
Description=Mountpoint for Amazon S3 mount
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/mount-s3 DOC-EXAMPLE-BUCKET /path/to/mount --allow-delete
ExecStop=/usr/bin/fusermount -u /mnt
[Install]
WantedBy=default.target
EOF
Unit ファイルを追加したので、一度だけ systemctl daemon-reload を実行してファイルを認識させます。
これで準備完了です。 定義したデーモンを起動・自動起動設定して完了です。
念のため、systemctl status mount-s3.service を実行してデーモンの状態を確認しておきます。 デーモンが正常に起動していれば下記のように「Loaded: loaded」「Active: active」と表示されます。
# systemctl status mount-s3.service
● mount-s3.service - Mountpoint for Amazon S3 mount
Loaded: loaded (/usr/lib/systemd/system/mount-s3.service; enabled; preset: disabled)
Active: active (exited) since Sun 2023-10-22 01:51:16 UTC; 28min ago
・
・
・
参考¶
mount-s3 のヘルプ¶
# mount-s3 --help
Mountpoint for Amazon S3
Usage: mount-s3 [OPTIONS] <BUCKET_NAME> <DIRECTORY>
Arguments:
<BUCKET_NAME> Name of bucket to mount
<DIRECTORY> Directory to mount the bucket at
Options:
-f, --foreground Run as foreground process
-h, --help Print help
-V, --version Print version
Bucket options:
--prefix <PREFIX>
Prefix inside the bucket to mount, ending in '/' [default: mount the entire bucket]
--region <REGION>
AWS region of the bucket [default: auto-detect region]
--endpoint-url <ENDPOINT_URL>
S3 endpoint URL [default: auto-detect endpoint]
--force-path-style
Force path-style addressing
--transfer-acceleration
Use S3 Transfer Acceleration when accessing S3. This must be enabled on the bucket.
--dual-stack
Use dual-stack endpoints when accessing S3
--requester-pays
Set the 'x-amz-request-payer' to 'requester' on S3 requests
--storage-class <STORAGE_CLASS>
Set the storage class for new objects
--expected-bucket-owner <AWS_ACCOUNT_ID>
Account ID of the expected bucket owner. If the bucket is owned by a different account, S3 requests fail with an access denied error.
AWS credentials options:
--no-sign-request Do not sign requests. Credentials will not be loaded if this argument is provided.
--profile <PROFILE> Use a specific profile from your credential file.
Mount options:
--read-only Mount file system in read-only mode
--allow-delete Allow delete operations on file system
--auto-unmount Automatically unmount on exit
--allow-root Allow root user to access file system
--allow-other Allow other users, including root, to access file system
--uid <UID> Owner UID [default: current user's UID]
--gid <GID> Owner GID [default: current user's GID]
--dir-mode <DIR_MODE> Directory permissions [default: 0755]
--file-mode <FILE_MODE> File permissions [default: 0644]
Client options:
--maximum-throughput-gbps <N> Maximum throughput in Gbps [default: auto-detected on EC2 instances, 10 Gbps elsewhere]
--max-threads <N> Maximum number of FUSE daemon threads [default: 16]
--part-size <PART_SIZE> Part size for multi-part GET and PUT [default: 8388608]
Logging options:
-l, --log-directory <DIRECTORY> Write log files to a directory [default: logs written to syslog]
--log-metrics Enable logging of summarized performance metrics
-d, --debug Enable debug logging for Mountpoint
--debug-crt Enable debug logging for AWS Common Runtime
--no-log Disable all logging