Userdata:在Windows Server 2016上安装IIS

时间:2018-01-30 03:11:58

标签: amazon-web-services windows-server windows-server-2016 user-data

我试图在AWS中编写一个安装了IIS的新服务器设置脚本。我试图解决这个问题的方法是用户数据:

<powershell> 
Start-Transcript; 

# Set Default Password for Testing
net user "Administrator" "Password.1"; 

# Install IIS
Import-Module ServerManager; 
Install-WindowsFeature web-server, web-webserver -IncludeAllSubFeature; 
Install-WindowsFeature web-mgmt-tools; 

# Configure Bindings to :443
New-WebBinding -Name "Default Web Site" -IP "*" -Port 443 -Protocol https -SslFlags 0;
$newCert = New-SelfSignedCertificate -DnsName localhost -CertStoreLocation cert:\LocalMachine\My; 
$SslBinding = Get-WebBinding -Name "Default Web Site" -Protocol "https";
$SslBinding.AddSslCertificate($newCert.GetCertHashString(), "my"); 
Get-WebBinding -Port 80 -Name "Default Web Site" | Remove-WebBinding;

# Install CodeDeploy Agent 
Import-Module AWSPowerShell; 
New-Item -Path "C:\Temp" -ItemType "directory" -Force; 
Read-S3Object -BucketName aws-codedeploy-us-east-1 -Key latest/codedeploy-agent.msi -File c:\temp\codedeploy-agent.msi; 
c:\temp\codedeploy-agent.msi /quiet /l c:\temp\host-agent-install-log.txt;
</powershell>

我的问题似乎是为了让安装实际完成,我需要让远程桌面进入机器。

鉴于这将出现在一个自动缩放组中,将远程桌面放入服务器是不切实际的,因为它们正在旋转以满足需求。

为什么我需要远程桌面才能完成脚本? 我是否可以通过这样的方式编写脚本,这意味着我们不必将RDP引入服务器,因为它们正在被旋转?

2 个答案:

答案 0 :(得分:0)

感谢上面的Adil B。我通过改变功能的安装方式解决了这个问题。新脚本如下所示:

<powershell> 
Start-Transcript; 

# Install IIS
Import-Module ServerManager; 
Enable-WindowsOptionalFeature -Online -NoRestart -FeatureName 'IIS-WebServerRole', 'IIS-WebServer', 'IIS-ManagementConsole';

# Configure Bindings to :443
New-WebBinding -Name "Default Web Site" -IP "*" -Port 443 -Protocol https -SslFlags 0;
$newCert = New-SelfSignedCertificate -DnsName localhost -CertStoreLocation cert:\LocalMachine\My; 
$SslBinding = Get-WebBinding -Name "Default Web Site" -Protocol "https";
$SslBinding.AddSslCertificate($newCert.GetCertHashString(), "my"); 
Get-WebBinding -Port 80 -Name "Default Web Site" | Remove-WebBinding;

# Install CodeDeploy Agent 
Import-Module AWSPowerShell; 
New-Item -Path "C:\Temp" -ItemType "directory" -Force; 
Read-S3Object -BucketName aws-codedeploy-us-east-1 -Key latest/codedeploy-agent.msi -File c:\temp\codedeploy-agent.msi; 
c:\temp\codedeploy-agent.msi /quiet /l c:\temp\host-agent-install-log.txt;
</powershell>

答案 1 :(得分:0)

通过使用Enable-WindowsOptionalFeature命令设置-NoRestart标志,我已成功通过Userdata脚本安装IIS:Enable-WindowsOptionalFeature -Online -NoRestart -FeatureName 'IIS-WebServerRole', 'IIS-WebServer', 'IIS-ManagementConsole'