iis – 在PowerShell中创建Web场

前端之家收集整理的这篇文章主要介绍了iis – 在PowerShell中创建Web场前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在Power Shell自动创建服务器场.通过手动创建,我得到了以下 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选项卡保持为空).

在实现SF存在并且可能更合适之后,从SO开始在此处进行交叉.

解决方法

我见过的最好的方法是将powershell与appcmd.exe命令混合使用. Microsoft已发布一些示例代码,用于在docker容器 here中设置服务器场.

这是一个例子:

ForEach($farm in $farms)
{   
    # Create the farm
    .\appcmd.exe set config  -section:webFarms /+"[name='$($farm.name)']" /commit:apphost

    ForEach($server in $farm.Servers)
    {
        # Add server to farm
        .\appcmd.exe set config  -section:webFarms /+"[name='$($farm.name)'].[address='$($server.address)']" /commit:apphost
    }

    # URL Rewrite
    .\appcmd.exe set config  -section:system.webServer/rewrite/globalRules /+"[name='ARR_$($farm.name)_lb',patternSyntax='Wildcard',stopProcessing='True']" /commit:apphost
    .\appcmd.exe set config  -section:system.webServer/rewrite/globalRules /"[name='ARR_$($farm.name)_lb',stopProcessing='True']".match.url:"*"  /commit:apphost
    .\appcmd.exe set config  -section:system.webServer/rewrite/globalRules /"[name='ARR_$($farm.name)_lb',stopProcessing='True']".action.type:"Rewrite"  /"[name='ARR_$($farm.name)_lb',stopProcessing='True']".action.url:"http://$($farm.name)/{R:0}"  /commit:apphost
}
原文链接:https://www.f2er.com/html/228914.html

猜你在找的HTML相关文章