我在我的 EC2 实例 (Amazon linux AMI) 上使用 EFS 卷。如果我进入服务器并运行类似的内容,我可以毫无问题地安装卷:
sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 fs-xxxxxxxxx.efs.ap-southeast-2.amazonaws.com:/efs
但是,如果我在我的实例的用户数据部分添加一个 shell 脚本并启动它,我什么也得不到,我该如何调试它?我可以查看文件系统中的一些日志或其他内容吗?我没有收到错误,只是没有安装驱动器。任何帮助表示赞赏。
我正在使用以下 shell 脚本:
#!/bin/bash
# Make sure all packages are up-to-date
yum update -y
# Make sure that NFS utilities and AWS CLI utilities are available
yum install -y jq nfs-utils python27 python27-pip awscli
pip install --upgrade awscli
# Name of the EFS filesystem (match what was created in EFS)
EFS_FILE_SYSTEM_NAME="xxxx.efs.ap-southeast-2.amazonaws.com"
# Gets the EC2 availability zone for the current ECS instance
EC2_AVAIL_ZONE="ap-southeast-2b"
# Gets the EC2 region for the current ECS instance
EC2_REGION="Asia Pacific (Sydney)"
# Creates the mount-point for the EFS filesystem
DIR_TGT="efs"
mkdir "${DIR_TGT}"
# Get the EFS filesystem ID.
EFS_FILE_SYSTEM_ID="$(/usr/local/bin/aws efs describe-file-systems --region "${EC2_REGION}" | jq '.FileSystems[]' | jq "select(.Name==\"${EFS_FILE_SYSTEM_NAME}\")" | jq -r '.FileSystemId')"
if [ -z "${EFS_FILE_SYSTEM_ID}" ]; then
echo "ERROR: variable not set" 1> /etc/efssetup.log
exit
fi
# Create the mount source path
DIR_SRC="${EC2_AVAIL_ZONE}.${EFS_FILE_SYSTEM_ID}.efs.${EC2_REGION}.amazonaws.com"
# Actually mount the EFS filesystem
mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,soft,timeo=600,retrans=2 "${DIR_SRC}:/" "${DIR_TGT}"
# Create a backup of the existing /etc/fstab
cp -p "/etc/fstab" "/etc/fstab.back-$(date +%F)"
# Add the new mount point to /etc/fstab
echo -e "${DIR_SRC}:/ \t\t ${DIR_TGT} \t\t nfs \t\t nfsvers=4.1,rsize=1048576,wsize=1048576,soft,timeo=600,retrans=2 \t\t 0 \t\t 0" | tee -a /etc/fstab