AWS RHEL8 s3fsを使ってS3バケットをマEC2にウントする方法

環境
AWS EC2
RHEL8.6
AWS S3

前提条件
AmazonS3FullAccessポリシーをアタッチしたロールを作成し、作成したロールをサーバロールとしてアタッチしています。

操作方法
1.s3バケットを作成する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ aws s3 mb s3://ark-s3fs-20231119
$ aws s3 ls s3://ark-s3fs-20231119
$ aws s3 mb s3://ark-s3fs-20231119 $ aws s3 ls s3://ark-s3fs-20231119
$ aws s3 mb s3://ark-s3fs-20231119
$ aws s3 ls s3://ark-s3fs-20231119

2.バケットにテストファイルを配置する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
date > test.txt
aws s3 cp test.txt s3://ark-s3fs-20231119
date > test.txt aws s3 cp test.txt s3://ark-s3fs-20231119
date > test.txt
aws s3 cp test.txt s3://ark-s3fs-20231119

3.EPELリポジトリを有効にする

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf config-manager --set-enabled codeready-builder-for-rhel-8-rhui-rpms
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm sudo dnf config-manager --set-enabled codeready-builder-for-rhel-8-rhui-rpms
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf config-manager --set-enabled codeready-builder-for-rhel-8-rhui-rpms

4.f3fs-fuseをインストールする

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ sudo dnf install -y s3fs-fuse
$ sudo dnf install -y s3fs-fuse
$ sudo dnf install -y s3fs-fuse

 

5./etc/fstab設定を行う

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo vi /etc/fstab
下記内容を追記する
ark-s3fs-20231119 /data fuse.s3fs _netdev,rw,allow_other,uid=1000,gid=1000,iam_role=auto,endpoint=ap-northeast-1 0 0
# sudo vi /etc/fstab 下記内容を追記する ark-s3fs-20231119 /data fuse.s3fs _netdev,rw,allow_other,uid=1000,gid=1000,iam_role=auto,endpoint=ap-northeast-1 0 0
# sudo vi /etc/fstab
下記内容を追記する
ark-s3fs-20231119 /data fuse.s3fs _netdev,rw,allow_other,uid=1000,gid=1000,iam_role=auto,endpoint=ap-northeast-1 0 0

確認
# cat /etc/fstab

7.マウントの確認を行う

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# df -h
# sudo mount -a
# df -h
# df -h # sudo mount -a # df -h
# df -h
# sudo mount -a
# df -h

8.3へのファイルの読み込み・書き込み・削除確認を行う

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# cd /data
# cat test.txt
# date >test.txt
# ls -la
# cd /data # cat test.txt # date >test.txt # ls -la
# cd /data
# cat test.txt
# date >test.txt
# ls -la

9.OSを再起動する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#sudo shutdown -r now
#sudo shutdown -r now
#sudo shutdown -r now

再起動後確認

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#df -h
# ls -la /data
#df -h # ls -la /data
#df -h
# ls -la /data

 

AWS

Posted by arkgame