通过自定义AMI自动登录启动多个ec2 Windows服务器

Jon*_*ett 1 windows amazon-ec2 ec2-ami

救命!!!

我正在尝试创建一个Windows ami,当启动时(需要多个[20]实时服务器在短时间内启动短时间)自动登录并运行.exe应用程序(不幸的是我无法让应用程序作为服务运行).机器名称也必须是唯一的.

问题在预先sysprep之前工作得很好,但是当我从ami启动实例时它无法登录,因为机器名称显然已从原始机器映像更改.

我管理它的唯一方法是不使用sysprep,使用ami,然后在启动时登录到新计算机并手动更改计算机名称,并设置autologon sysinternal工具.这并不理想,因为最终用户不是技术人员,时间限制不允许有效执行此操作.

我没办法!非常感激您的帮忙.

Ami*_*rge 10

我知道这是一个非常古老的问题.尽管如此,当我遇到类似的问题时,谷歌也引发了我这个问题.我做了以下事情来解决我的问题.

  • 根据自己的喜好自定义实例.将使用此实例创建AMI.

    • 使用管理员权限创建新用户帐户.这是必需的,因为Sysprep\Ec2ConfigService将重置管理员密码.将此用户添加到组中Remote Desktop Users,因此您可以使用此用户帐户进行RDP.
  • 编辑EC2的Sysprep应答文件以启用自动登录.

    • 将以下内容附加到文件中component指定Microsoft-Windows-Shell-Setup的节点C:\Program Files\Amazon\Ec2ConfigService\sysprep2008.xml

.

<AutoLogon>
  <Password>
    <Value>NewUser'sPassword</Value>
    <PlainText>true</PlainText>
  </Password>
  <Username>NewUser'sName</Username>
  <Enabled>true</Enabled>
  <LogonCount>999</LogonCount>
</AutoLogon>
Run Code Online (Sandbox Code Playgroud)

生成的文件应该类似于下面的代码段.我删除了这个答案不需要的部分.

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
  <settings pass="oobeSystem">
    <!-- snip -->
    <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <!-- snip -->    
        <AutoLogon>
          <Password>
            <Value>NewUser'sPassword</Value>
            <PlainText>true</PlainText>
          </Password>
          <Username>NewUser'sName</Username>
          <Enabled>true</Enabled>
          <LogonCount>999</LogonCount>
        </AutoLogon>
    </component>
  </settings>
  <!-- snip -->
</unattend>
Run Code Online (Sandbox Code Playgroud)
  • 接下来,我们编辑EC2ConfigService设置.

    • 在文件中"C:\Program Files\Amazon\Ec2ConfigService\Settings\BundleConfig.xml",确保SetPasswordAfterSysprepis 的值Yes.
    • 在文件中"C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml",确保state节点具有Enabled插件的值Ec2SetPassword.
    • 在文件中"C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml",确保RemoveCredentialsfromSysprepOnStartupis 的值false.
  • 您已经在登录时启动了exe.使用相同的机制,还启动一个脚本,AutoLogonCount从注册表中删除该设置.此步骤很重要,否则在999(根据上述示例)登录后,自动登录将停止.

.

powershell.exe  -command { Remove-ItemProperty -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\winlogon"  -Name AutoLogonCount -Force -ErrorAction 0 }
Run Code Online (Sandbox Code Playgroud)
  • 现在我们可以启动Sysprep了.使用UI或以下命令.

.

%ProgramFiles%\Amazon\Ec2ConfigService\ec2config.exe -sysprep
Run Code Online (Sandbox Code Playgroud)

使用从上述实例创建的AMI启动的任何实例都会无限期地保留自动登录行为.