![](/img/trans.png)
[英]How to upgrade a generic application running on a windows failover cluster
[英]Windows Failover Cluster API still Valid?
我正在寻找部署的选项。 Net Windows 服务下 2 个 windows 故障转移集群实例。 但我坚持使用 Windows 故障集群 API 用于跨 windows 服务实例进行通信。 我看不到任何参考。 用它。 它仍然有效吗?
首选方法是从您的代码中调用Powershell Cmdlet 。
这是我为集群虚拟机而编写的 class。 它应该为您提供足够的基础以到达您想要 go 的位置。
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Management.Automation;
public static class FailoverClustering
{
public static List<string> GetClusterNode(string cluster)
{
List<string> nodes = new List<string>();
PowerShell powerShell = PowerShell.Create();
powerShell.AddCommand("Get-ClusterNode");
powerShell.AddParameter("Cluster", cluster);
foreach (PSObject result in powerShell.Invoke())
nodes.Add(result.Members["Name"].Value.ToString());
if (powerShell.Streams.Error.Count > 0)
throw new Exception(powerShell.Streams.Error[0].Exception.Message);
powerShell.Dispose();
return nodes;
}
public static ClusteredVirtualMachine AddClusterVirtualMachineRole(string cluster, string virtualMachine)
{
PowerShell powerShell = PowerShell.Create();
powerShell.AddCommand("Add-ClusterVirtualMachineRole");
powerShell.AddParameter("Cluster", cluster);
powerShell.AddParameter("VirtualMachine", virtualMachine);
Collection<PSObject> result = powerShell.Invoke();
if (powerShell.Streams.Error.Count > 0)
throw new Exception(powerShell.Streams.Error[0].Exception.Message);
powerShell.Dispose();
return new ClusteredVirtualMachine(
result[0].Members["Name"].Value.ToString(),
result[0].Members["OwnerNode"].Value.ToString(),
result[0].Members["State"].Value.ToString()
);
}
}
public class ClusteredVirtualMachine
{
public string Name { get; }
public string OwnerNode { get; }
public State State { get; }
public ClusteredVirtualMachine(string name, string ownerNode, string state)
{
Name = name;
OwnerNode = ownerNode;
switch (state)
{
case "Offline": State = State.Offline; break;
case "Online": State = State.Online; break;
}
}
}
public enum State
{
Online,
Offline
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.