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

AWS自定义AMI实例用户数据功能失效排查求助

问题排查与解决

核心原因:自定义AMI未预装/启用cloud-init

AWS实例的用户数据依赖cloud-init服务执行,你的自定义AMI大概率缺少这个关键组件,或是相关服务未配置开机启动。

具体排查与修复步骤

  1. 检查cloud-init是否安装
    执行对应命令确认:

    rpm -qa | grep cloud-init  # RHEL/CentOS 系列
    dpkg -l | grep cloud-init  # Debian/Ubuntu 系列
    

    若无输出说明未安装,需手动安装:

    • RHEL/CentOS:yum install cloud-init -y
    • Debian/Ubuntu:apt update && apt install cloud-init -y
  2. 确认cloud-init服务状态
    安装后检查服务是否启用并运行:

    systemctl status cloud-init
    systemctl status cloud-init-local
    systemctl status cloud-config
    systemctl status cloud-final
    

    确保所有相关服务设置开机启动:

    systemctl enable cloud-init cloud-init-local cloud-config cloud-final
    
  3. 验证cloud-init基础配置
    检查/etc/cloud/cloud.cfg是否存在,确保包含以下关键配置项:

    datasource_list: [ Ec2 ]
    datasource:
      Ec2:
        metadata_urls: [ 'http://169.254.169.254' ]
    

    该配置确保cloud-init会从AWS元数据服务拉取用户数据。

  4. 重新封装自定义AMI
    完成上述配置后,需重新创建AMI:

    • 可选:执行cloud-init clean清理实例临时数据
    • 停止当前实例,基于该实例创建新的自定义AMI
    • 使用新AMI启动实例,测试用户数据是否生效

额外注意事项

  • 你的用户数据中echo "all" > check.txt会写入cloud-init执行时的默认目录(通常为根目录),建议改为绝对路径如/tmp/check.txt,避免权限或路径问题
  • 修复后重启实例,可通过/var/log/cloud-init.log和/var/log/cloud-init-output.log查看执行日志,确认用户数据执行状态

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 23:46:03