You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法通过User Data完成AWS EC2服务器初始化更新问题排查

AWS EC2 User Data中yum update未完成,网络连接存疑

环境与User Data脚本

创建了一台AWS EC2 t2.micro实例,使用以下User Data脚本:脚本会等待/tmp/BootstrapCompleted文件出现后,再执行系统更新操作:

#!/bin/bash
while  [  ! -f /tmp/BootstrapCompleted ]
do
  sleep 300
done
echo "file found" >> /tmp/ameya.log
echo -e "Ameya is going mad" >> /tmp/ameya.log
sleep 120
yum update -y >> /tmp/ameya.log
echo -e "\n My Sanity is restored" >> /tmp/ameya.log

问题现象

  • SSH登录实例后手动执行yum update -y可以正常完成更新,说明User Data中的更新操作并未成功执行。
  • 查看/var/log/cloud-init-output.log,发现EPEL源元数据下载失败,日志最后几行如下:
Cloud-init v. 22.1-5.el8 running 'modules:config' at Thu, 23 Feb 2023 01:59:01 +0000. Up 101.14 seconds.
Errors during downloading metadata for repository 'epel':
  - Curl error (6): Couldn't resolve host name for https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/repodata/repomd.xml [Could not resolve host: dl.fedoraproject.org]
Error: Failed to download metadata for repo 'epel': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
Cloud-init v. 22.1-5.el8 running 'modules:final' at Thu, 23 Feb 2023 02:00:10 +0000. Up 170.00 seconds.
Cloud-init v. 22.1-5.el8 finished at Thu, 23 Feb 2023 02:02:12 +0000. Datasource DataSourceEc2Local.  Up 291.76 seconds
  • 查看生成的/tmp/ameya.log,内容显示yum update过程中EPEL源下载速度为0:
[root@ANL62600251 ~]# cat /tmp/ameya.log 
file found
Ameya is going mad
Extra Packages for Enterprise Linux 8 - x86_64  0.0  B/s |   0  B     00:00    

 My Sanity is restored
  • 手动执行yum update时,EPEL源可以正常下载元数据:
yum update
Extra Packages for Enterprise Linux 8 - x86_64                                                          6.5 kB/s | 4.7 kB     00:00    

疑问

这是否说明User Data执行yum update时实例没有网络连接?

内容的提问来源于stack exchange,提问作者learner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 19:45:31