4

我一直在尝试编写一个 powershell 程序来检查集群是否存在。如果没有,那么它会创建它并将自己添加到其中。如果另一台计算机唤醒,它会检查集群是否存在,如果存在,则将自己添加到集群中。

我在尝试从集群 IP 地址获取对集群对象的引用时遇到问题。每个节点都知道它的地址和集群地址。我想避免每个节点都有其集群中所有其他节点的列表。

我发现我需要查看非集群 IP 地址才能让-nlbcluster 工作。指定集群 ip 地址只是错误。

有什么办法可以做到这一点,而不必在每次从集群中添加或删除节点时更新每个节点上的这个列表。我想我还想避免节点唤醒并且必须轮询“主”列表中的每台机器以查找已启动的机器以将其自身添加到集群的情况。

4

2 回答 2

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
    }
}
于 2012-05-08T13:39:16.043 回答
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
}
于 2012-05-24T09:37:26.400 回答