【发布时间】:2018-04-22 13:42:53
【问题描述】:
我正在尝试在 PowerShell 中自动创建服务器场。通过手动创建,我得到了以下 XML:
<webFarms>
<webFarm name="alwaysup" enabled="true">
<server address="alwaysup-blue" enabled="true">
<applicationRequestRouting httpPort="8001" />
</server>
<server address="alwaysup-green" enabled="true">
<applicationRequestRouting httpPort="8002" />
</server>
<applicationRequestRouting>
<healthCheck url="http://alwaysup/up.html" interval="00:00:05" responseMatch="up" />
</applicationRequestRouting>
</webFarm>
<applicationRequestRouting>
<hostAffinityProviderList>
<add name="Microsoft.Web.Arr.HostNameRoundRobin" />
</hostAffinityProviderList>
</applicationRequestRouting>
</webFarms>
然而,尝试通过 PS 执行此操作很麻烦:据我所知,没有专门的 API 可以通过此操作(WebFarmSnapin 用于旧版本)。
我已将注意力转移到IIS Administration Cmdlets,但只完成了一半。
我拥有的代码:
#####
# Overwriting the server farm
#####
Write-Host "Overwriting the server farm $($webFarmName)"
$webFarm = @{};
$webFarm["name"] = 'siteFarm'
Set-WebConfiguration "/webFarms" -Value $webFarm
#####
# Adding the servers
#####
Write-Host "Adding the servers"
$blueServer = @{}
$blueServer["address"] = 'site-blue'
$blueServer["applicationRequestRouting"] = @{}
$greenServer = @{}
$greenServer["address"] = 'site-green'
$greenServer["applicationRequestRouting"] = @{}
$servers = @($blueServer, $greenServer)
Add-WebConfiguration -Filter "/webFarms/webFarm[@name='siteFarm']" -Value $servers
#####
# Adding routing
#####
Write-Host "Adding the routing configurations"
$blueServerRouting = @{}
$blueServerRouting["httpPort"] = "8001"
Add-WebConfiguration -Filter "/webFarms/webFarm[@name='siteFarm']/server[@address='site-blue']" -Value $blueServerRouting
这会生成
<webFarms>
<webFarm name="siteFarm">
<server address="site-blue" />
<server address="site-green" />
</webFarm>
<applicationRequestRouting>
<hostAffinityProviderList>
<add name="Microsoft.Web.Arr.HostNameRoundRobin" />
</hostAffinityProviderList>
</applicationRequestRouting>
</webFarms>
如您所见,它缺少与路由相关的端口。而且我现在还没有开始尝试添加运行状况检查。
我做错了什么?是否有一些我没有找到的 Cmdlet 使这更容易?
Related 但没有太多有用的答案(带有生成代码的 PowerShell 选项卡保持空白)。
【问题讨论】:
-
你可以试试看 IIS 提供程序是否可以做你想做的事情technet.microsoft.com/en-us/library/ee909471(v=ws.10).aspx 可以说它比使用 IIS cmdlet 更具体,但有时这就是它所需要的。
-
您是否查看过此 cmdlet 来配置端口?
Set-WebBinding -Name 'Default Web Site' -BindingInformation "*:80:" -PropertyName "Port" -Value "1234"我对网络农场还不够熟悉,不知道这是否对您有帮助。 -
如果您还没有,我建议您查看xWebAdministration DSC resource 以自动化网络农场的创建/配置/期望状态。 WebAdministration 模块还有很多不足之处(根据今年早些时候自动化一些 IIS 设置后的经验)
-
@TheIncorrigible1 我没有看到任何与网络农场相关的内容。我在看过去吗?
-
我很好奇这是如何工作的!我们对容器做了一些类似但不是农场的事情。
标签: powershell iis load-balancing arr