亚马逊EC2的自定义AMI不运行引导(用户数据) [英] Amazon EC2 custom AMI not running bootstrap (user-data)

查看:177
本文介绍了亚马逊EC2的自定义AMI不运行引导(用户数据)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在EC2实例创建自定义的AMI(图像)时,我遇到了一个问题。如果我启动了一个Windows默认2012的服务器实例使用自定义引导/用户数据的脚本,如;

I have encountered an issue when creating custom AMIs (images) on EC2 instances. If I start up a Windows default 2012 server instance with a custom bootstrap/user-data script such as;

<powershell>
PowerShell "(New-Object System.Net.WebClient).DownloadFile('http://download.microsoft.com/download/3/2/2/3224B87F-CFA0-4E70-BDA3-3DE650EFEBA5/vcredist_x64.exe','C:\vcredist_x64.exe')"
</powershell>

它将按照预期并转到网址并下载文件,并将其存储在C:驱动器

It will work as intended and go to the URL and download the file, and store it on the C: Drive.

但是,如果我安装在Windows Server实例,然后从它创建一个图像,并将其存储为一个自定义的AMI,然后用完全相同的自定义用户数据脚本,它不会工作部署。但是,如果我去的实例URL( http://169.254.169.254/latest/user-data )将显示脚本导入成功地但尚未执行。

But if I setup a Windows Server Instance, then create a image from it, and store it as a Custom AMI, then deploy it with the exact same custom user-data script it will not work. But if I go to the instance url (http://169.254.169.254/latest/user-data) it will show the script has imported sucessfully but has not been executed.

检查定期场合,我已经注意到这个错误日志后:

After checking the error logs I have noticed this on a regular occasion:

Failed to fetch instance metadata http://169.254.169.254/latest/user-data with exception The remote server returned an error: (404) Not Found.

有没有人遇到了同样的问题,并找到了解决方法?

Has anyone ran into this same issue and found a solution?

在先进的感谢!

推荐答案

用户数据执行的是初始引导后自动关闭。当你创建你的形象,这是有可能的执行已被禁用。这是可配置的手动在 C:\ Program Files文件\亚马逊\ Ec2ConfigService \设置\ Config.xml中

User data execution is automatically disabled after the initial boot. When you created your image, it is probable that execution had already been disabled. This is configurable manually within C:\Program Files\Amazon\Ec2ConfigService\Settings\Config.xml.

借助文档配置Windows实例使用EC2Config服务推荐了几种选择:

  • 编程创建计划任务在系统启动时运行使用 SchTasks.exe会/创建,并指出该计划的任务到用户数据的脚本(或其他脚本)在 C:\ Program Files文件\亚马逊\ Ec2ConfigServer \脚本\ UserScript.ps1

  • Programmatically create a scheduled task to run at system start using schtasks.exe /Create, and point the scheduled task to the user data script (or another script) at C:\Program Files\Amazon\Ec2ConfigServer\Scripts\UserScript.ps1.

编程使用户数据的插件Config.xml中。

Programmatically enable the user data plug-in in Config.xml.

为例,从文档:

<powershell>
$EC2SettingsFile="C:\Program Files\Amazon\Ec2ConfigService\Settings\Config.xml"
$xml = [xml](get-content $EC2SettingsFile)
$xmlElement = $xml.get_DocumentElement()
$xmlElementToModify = $xmlElement.Plugins

foreach ($element in $xmlElementToModify.Plugin)
{
    if ($element.name -eq "Ec2SetPassword")
    {
        $element.State="Enabled"
    }
    elseif ($element.name -eq "Ec2HandleUserData")
    {
        $element.State="Enabled"
    }
}
$xml.Save($EC2SettingsFile)
</powershell>

  • 与EC2Config版本2.1.10开始,您可以使用&LT;坚持&GT;真&LT; /坚持&GT; 来启用该插件的用户数据执行后

    • Starting with EC2Config version 2.1.10, you can use <persist>true</persist> to enable the plug-in after user data execution.
    • 为例,从文档:

      <powershell>
          insert script here
      </powershell>
      <persist>true</persist>
      

      这篇关于亚马逊EC2的自定义AMI不运行引导(用户数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆