我通过 cloudformation 向 Linux 机器提供用户数据,当我使用 c4 类类型(例如:c4.large、c4.xlarge)时,它工作正常,而当我在 cloudformation 中更改实例类型并通过运行 jenkin 作业在服务器上部署时,它停止工作。
我正在使用 c4.large,当我将实例类型更改为 c5.xlarge 时,它无法工作,因此,为了进行测试,当我更改为 c4.xlarge 时,它可以工作,因此问题仅出在 c5 实例类型上。我还使用优化的 EBS 卷检查了这两种实例类型,因此在磁盘级别上没有太大差异。
日志:
Mar 28 05:50:30 ip-10-116-54-180 cloud-init[1876]: Setting up python3-botocore (1.4.70-1~16.04.0) ...
Mar 28 05:50:30 ip-10-116-54-180 cloud-init[1876]: Setting up python3-s3transfer (0.1.9-1~16.04.0) ...
Mar 28 05:50:31 ip-10-116-54-180 cloud-init[1876]: Setting up awscli (1.11.13-1ubuntu1~16.04.0) ...
Mar 28 05:50:31 ip-10-116-54-180 cloud-init[1876]: Processing triggers for libc-bin (2.23-0ubuntu11) ...
**Mar 28 05:50:32 ip-10-116-54-180 cloud-init[1876]: Error: Could not stat device /dev/xvdb - No such file or directory.
Mar 28 05:50:32 ip-10-116-54-180 cloud-init[1876]: #015 #015Error: Could not stat device /dev/xvdb - No such file or directory.**
Mar 28 05:50:39 ip-10-116-54-180 systemd[1]: Created slice User Slice of ubuntu.
Mar 28 05:50:39 ip-10-116-54-180 systemd[1]: Starting User Manager for UID 1000...
Mar 28 05:50:39 ip-10-116-54-180 systemd[1]: Started Session 1 of user ubuntu.
Mar 28 05:50:39 ip-10-116-54-180 systemd[8734]: Reached target Sockets.
Mar 28 05:50:39 ip-10-116-54-180 systemd[8734]: Reached target Timers.
Mar 28 05:50:39 ip-10-116-54-180 systemd[8734]: Reached target Paths.
Mar 28 05:50:39 ip-10-116-54-180 systemd[8734]: Reached target Basic System.
Mar 28 05:50:39 ip-10-116-54-180 systemd[8734]: Reached target Default.
Mar 28 05:50:39 ip-10-116-54-180 systemd[8734]: Startup finished in 8ms.
Mar 28 05:50:39 ip-10-116-54-180 systemd[1]: Started User Manager for UID 1000.
Mar 28 05:50:55 ip-10-116-54-180 amazon-ssm-agent.amazon-ssm-agent[1800]: 2019-03-28 05:50:55 INFO [HealthCheck] HealthCheck reporting agent health.
Mar 28 05:53:32 ip-10-116-54-180 systemd[1]: Started Session 2 of user ubuntu.
用户数据例如:
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y awscli python-pip python-dev python-virtualenv
mkdir /var/log/nginx
parted /dev/xvdb mklabel gpt
parted -a opt /dev/xvdb mkpart primary ext4 0% 100%
echo '/dev/xvdb1 /var/log/nginx ext4 defaults 0 0' >> /etc/fstab
sleep 10
while [ ! -e /dev/xvdb1 ]; do sleep 1; done
mkfs.ext4 /dev/xvdb1
mount /var/log/nginx
chown root:adm /var/log/nginx
tar zxvf aws-ss-routing.tar.gz
chmod +x nginx/install.sh
cd nginx && ./install.sh
由于 c5 类是 c4 类类型的高级水平类,所以我需要使用它来解决这个问题。
答案1
错误消息指出无法找到设备名称Error: Could not stat device /dev/xvdb - No such file or directory.
。您可能需要检查设备名称是否仍然是/dev/xvdX
,大多数较新版本的 EC2 都使用 NVMe EBS,因此命名约定已更改为/dev/nvme[0-26]n1
,请参阅此处https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html
您需要更新User Data
以映射 EBS 的正确命名约定。