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-buildgit clone https://github.com/aws/efs-utilscd efs-utilssudo make rpmsudo yum -y install build/amazon-efs-utils*rpmEFSをマウントする
EFSコンソールのアタッチからマウントコマンドをコピーする
mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport ${EFSのDNS名}:/ /var/wwwマウントされていることを確認する
df -hFilesystem                                  Size  Used Avail Use% Mounted on
fs-****.efs.ap-northeast-1.amazonaws.com:/  8.0E     0  8.0E   0% /var/wwwmountでハマったところ
マウントの問題のトラブルシューティング - Amazon Elastic File System
EFS ファイルシステムのマウントに関する問題のトラブルシューティングについて説明します。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 specifiedOSが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/wwwhttpd_sys_content_t:タイプは環境に合わせる
5.7. SELinux コンテキスト - ファイルのラベル付け | Red Hat Product Documentation
5.7. SELinux コンテキスト - ファイルのラベル付け | Red Hat DocumentationHow 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...

