我一直在尝试编写一个powershell程序来检查群集是否存在。如果没有,那么它会创建它并将其自身添加到它。 如果另一台计算机醒来,它会检查群集是否存在,如果存在,则将其自身添加到群集中。
我在尝试从群集IP地址获取对群集对象的引用时遇到问题。每个节点都知道其地址和集群地址。我想避免每个节点都有一个其集群中所有其他节点的列表。
我发现我需要查看非群集IP地址才能使用-nlbcluster工作。指定群集IP地址只是错误。
我有什么方法可以做到这一点,每次我从群集中添加或删除节点时都不必在每个节点上更新此列表。我想我也想避免一个节点醒来的情况,并且必须轮询“主”列表中的每台机器,寻找一个机器,以便将自己添加到集群中。
答案 0 :(得分:2)
这有帮助吗?我刚刚做过,但从来没有机会完全测试它:
#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
}
}
答案 1 :(得分:1)
可以在群集中的所有节点上运行以下脚本,如果群集不存在则创建它,否则只需将当前计算机添加到现有群集。您需要做的就是确保群集中的所有计算机都具有相同名称的专用卡。在下面的示例中,网卡名为“NLB”。
Import-Module ServerManager
# Interface cards should be named the same and have a fixed IP
$interfaceName = "NLB"
$clusterName = "NLB-Cluster"
$clusterIpAddress = "1.2.3.0"
$clusterSubnet = "255.0.0.0"
# Install Network Load Balancing and Tools
Write-Host "Install Network Load Balancing and Tools"
Add-WindowsFeature NLB, RSAT-NLB
Import-Module NetworkLoadBalancingClusters
# If the cluster hasn't been created yet then create it
if (!(Get-NlbCluster -HostName $clusterIpAddress -ErrorAction SilentlyContinue))
{
Write-Host "Creating NLB Cluster: $clusterName" -ForegroundColor yellow
# Create Cluster (default unicast)
New-NlbCluster -InterfaceName $interfaceName -ClusterName $clusterName -ClusterPrimaryIP $clusterIpAddress -SubnetMask $clusterSubnet
# Remove defaults
Write-Host "Removing default port rules" -ForegroundColor yellow
Get-NlbClusterPortRule | Remove-NlbClusterPortRule -Force
# Create port rules
Get-NlbCluster | Add-NlbClusterPortRule -StartPort 80 -EndPort 80 -Protocol TCP -Affinity None | Out-Null
Get-NlbCluster | Add-NlbClusterPortRule -StartPort 443 -EndPort 443 -Protocol TCP -Affinity None | Out-Null
}
else
{
Get-NlbCluster
}
# if this node isn't already a member of a cluster then add it
if(!(Get-NlbClusterNode -HostName $env:COMPUTERNAME))
{
# Add node to cluster
Write-Host "Adding node to cluster: $clusterName" -ForegroundColor yellow
Get-NlbCluster -HostName $clusterIpAddress | Add-NlbClusterNode -NewNodeName $env:COMPUTERNAME -NewNodeInterface $interfaceName
}
else
{
Get-NlbClusterNode
}