我一直在尝试编写一个 powershell 程序来检查集群是否存在。如果没有,那么它会创建它并将自己添加到其中。
如果另一台计算机醒来,它会检查集群是否存在,如果存在,则将自己添加到集群中。
我在尝试从集群 IP 地址获取对集群对象的引用时遇到问题。每个节点都知道它的地址和集群地址。我想避免每个节点都有其集群中所有其他节点的列表。
我发现我需要查看非集群 IP 地址才能使 get-nlbcluster 正常工作。指定集群 IP 地址只是错误。
有什么方法可以做到这一点,而不必每次在集群中添加或删除节点时更新每个节点上的此列表。我想我还想避免节点醒来并必须轮询“主”列表中的每台机器以查找已启动的机器以将其自身添加到集群的情况。
这有帮助吗?我不久前就做到了,但从未有机会完全测试它:
#Add a new node to NLB cluster
#Tested with Windows Server 2008 R2 only
#Requires WSManCredSSP Server Role Enabled on cluster Host
Function join-NlbCluster {
Param(
[Parameter(Mandatory=$true)]
$clusterHostname,
[Parameter(Mandatory=$true)]
$newNodename,
[Parameter(Mandatory=$true)]
$newNodeinterfaceName,
[Parameter(Mandatory=$true)]
$userName,
[Parameter(Mandatory=$true)]
$password
)
Write-Verbose "Verifiying if the remote node has NLB installed"
If (!((Get-OSFeature -computerName $newNodename -featureName NLB).Installed)) {
Write-Error "NLB feature is not installed on $newNodename. Cannot continue."
return $false
}
$cmdBlock = "Import-Module networkLoadBalancingClusters
`$nlbCluster = Get-nlbCluster -HostName $clusterHostName
if (`$nlbCluster) {
`$newNode = Add-NlbClusterNode -InputObject `$nlbCluster -NewNodeName $newNodename -NewNodeInterface `"$newNodeinterfaceName`"
if (`$newNode) {
Write-Host `"New node is added to cluster`"
return `$newNode
} else {
Write-Host `"Error Creating the NLB Cluster`"
return `$false
}
} else {
Write-Host `"No NLB cluster found on $clusterHostname`"
return `$false
}"
Write-Verbose $cmdBlock
$scriptBlock = $ExecutionContext.InvokeCommand.NewScriptBlock($cmdBlock)
try {
Write-Verbose "Creating new NLB Cluster"
Invoke-Command -ComputerName $clusterHostName -ScriptBlock $scriptBlock -HideComputerName -Authentication Credssp -Credential (Get-PSCredential -userName $userName -Password $password)
}
catch {
Write-Verbose $_
return $false
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)