用户数据:在 Windows Server 2016 上安装 IIS

问题描述 投票:0回答:3

我正在尝试在 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 连接到服务器吗?

amazon-web-services windows-server windows-server-2016 user-data
3个回答
1
投票

我已经使用

通过用户数据脚本成功安装了 IIS
Enable-WindowsOptionalFeature -NoRestart
Enable-WindowsOptionalFeature -Online -NoRestart -FeatureName 'IIS-WebServerRole', 'IIS-WebServer', 'IIS-ManagementConsole'

1
投票

感谢上面的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>

0
投票

我尝试使用此命令来安装 IIS。它不起作用。我在哪里检查出了什么问题?有日志吗?

© www.soinside.com 2019 - 2024. All rights reserved.