【问题标题】:Programmatically detect Windows cluster configuration?以编程方式检测 Windows 集群配置?
【发布时间】:2009-11-13 15:59:15
【问题描述】:

有人知道如何以编程方式检测 Windows 服务器是集群的一部分吗?

进一步,是否可以检测到服务器是主动节点还是被动节点?

[编辑] 并从 Win32 中检测到它?可能是注册表设置?

感谢您的任何见解。

道格

【问题讨论】:

    标签: windows cluster-computing


    【解决方案1】:

    您可以使用 WMI 来查找信息。这应该适用于 XP/Win32 等。

    这里有一些关于使用 VBScript 完成这项工作的重要信息: http://www.activexperts.com/activmonitor/windowsmanagement/scripts/networking/clustering/

    下面是一些也使用 WMI 的 C#/.Net 代码:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System;
    using System.Management;
    
    namespace SandboxConsole
    {
        public class ClusterAdmin
        {
            [MTAThread]
            public static void Main()
            {
                string clusterName = "MyCluster"; // cluster alias
                string custerGroupResource = "FS_Resource1"; // Cluster group name
                ConnectionOptions options = new ConnectionOptions();
                options.Username = "ClusterAdmin"; //could be in domain\user format
                options.Password = "HisPassword";
    
                // Connect with the mscluster WMI namespace on the cluster named "MyCluster"
                ManagementScope s = new ManagementScope("\\\\" + clusterName + "\\root\\mscluster", options);
                ManagementPath p = new ManagementPath("Mscluster_Clustergroup.Name='" + custerGroupResource + "'");
    
                using (ManagementObject clrg = new ManagementObject(s, p, null))
                {
                    // Take clustergroup off line and read its status property when done
                    TakeOffLine(clrg);
                    clrg.Get();
                    Console.WriteLine(clrg["Status"]);
    
                    System.Threading.Thread.Sleep(3000); // Sleep for a while
    
                    // Bring back online and get status.
                    BringOnLine(clrg);
                    clrg.Get();
                    Console.WriteLine(clrg["Status"]);
                }
            }
            static void TakeOffLine(ManagementObject resourceGroup)
            {
                ManagementBaseObject outParams =
                resourceGroup.InvokeMethod("Takeoffline", null, null);
            }
            static void BringOnLine(ManagementObject resourceGroup)
            {
                ManagementBaseObject outParams =
                resourceGroup.InvokeMethod("Takeoffline", null, null);
            }
        }
    }
    

    我找到了这段代码here,并稍微整理了一下。

    【讨论】:

      【解决方案2】:

      我没有确切的答案,但有很多以“Cluster”开头的 API(如 ClusterOpenEnum 和 ClusterNodeEnum)和以“IGetCluster”开头的 COM 接口看起来很有前景。

      【讨论】:

        【解决方案3】:

        您正在寻找任何特定的语言?

        您也许可以使用failover cluster cmdlets for Powershell(适用于 Windows Server 2008 R2)。特别是Get-ClusterGet-ClusterNode

        【讨论】:

        • 谢谢。我需要它用于 Win32,但这是我至少要看的起点。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-10-02
        • 2016-11-18
        • 2018-12-26
        • 2011-01-14
        • 2021-02-25
        • 2016-07-18
        • 2020-02-06
        相关资源
        最近更新 更多