mochotomochotoロゴ

[AWS]EC2 AlmaLinux9でEFSをマウントする

広告AWS
2024年01月17日

EC2 の AlmaLinux9 で EFS をマウントした際のメモです。

  • EFS は作成済み
  • セキュリティグループは 2049 ポート設定済み

#amazon-efs-utils をインストール

EFS マウント用の amazon-efs-utils を手動でインストールします。 https://docs.aws.amazon.com/ja_jp/efs/latest/ug/installing-amazon-efs-utils.html

sudo dnf install -y git rpm-build
git clone https://github.com/aws/efs-utils
cd efs-utils
sudo make rpm
sudo yum -y install build/amazon-efs-utils*rpm

#EFS をマウントする

EFS コンソールのアタッチからマウントコマンドをコピーする

mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport ${EFSのDNS名}:/ /var/www

マウントされていることを確認する

df -h
Filesystem                                  Size  Used Avail Use% Mounted on
fs-****.efs.ap-northeast-1.amazonaws.com:/  8.0E     0  8.0E   0% /var/www

#mount でハマったところ

マウントの問題のトラブルシューティング - Amazon Elastic File Systemマウントの問題のトラブルシューティング - Amazon Elastic File System

EFS ファイルシステムのマウントに関する問題のトラブルシューティングについて説明します。aws.amazon.comaws.amazon.com

#bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program.

bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program.

amazon-efs-utils をインストールしていなかったためでした。

#an incorrect mount option was specified

an incorrect mount option was specified

OS がNetwork File System バージョン 4.0 および 4.1 (NFSv4) をサポートしていない場合が多いとのことで確認しましたがサポートしていました。

grep CONFIG_NFS_V4_1 /boot/config*

結果、ただの mount コマンドの option 指定のスペルミスでした。。

#apache からドキュメントルートのファイルが参照できない

apache のドキュメントルートに EFS をマウントして index.html を表示しようとしたところ、 permission エラーで参照できませんでした。

ディレクトリのマウント時に  SELinux のコンテキストを定義することで解決できました。

mount -t nfs4 -o context="system_u:object_r:httpd_sys_content_t:s0" ${EFSのDNS名}:/ /var/www

httpd_sys_content_t:タイプは環境に合わせる

5.7. SELinux コンテキスト - ファイルのラベル付け | Security-Enhanced Linux | Red Hat Enterprise Linux | 6 | Red Hat Documentation

5.7. SELinux コンテキスト - ファイルのラベル付け | Security-Enhanced Linux | Red Hat Enterprise Linux | 6 | Red Hat Documentationredhat.comredhat.com

How to set Apache-accessible SELinux policy for EFS mounted user directories?

When I mount my EFS to a user directory, the directory policy becomes `system_u:object_r:nfs_t:s0`, which is too restrictive - I need it to behave more like a typical user directory, which is `unco...repost.awsrepost.aws
How to set Apache-accessible SELinux policy for EFS mounted user directories?