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

広告AWS
2024年1月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 EFS でのファイルシステムのマウントに関する問題のトラブルシューティングについての情報を見つけることができます。 Microsoft Windows の Amazon EC2 インスタンスで、ファイルシステムのマウントが失敗します。 Amazon EFS を Windows EC2 インスタンスで使用しないでください。これはサポートされていません。 ファイルシステムのマウントが失敗し、次のメッセージが表示されます。 IAM を使用してファイルシステムをマウントする場合は、マウントコマンドで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 コンテキスト - ファイルのラベル付け Red Hat Enterprise Linux 6 | Red Hat Customer Portal

Access Red Hat’s knowledge, guidance, and support through your subscription.redhat.comredhat.com
5.7. SELinux コンテキスト - ファイルのラベル付け Red Hat Enterprise Linux 6 | Red Hat Customer Portal

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?