前面有几篇文章介绍了Windows Failver Cluster集群的相关知识和实际案例,请参考如下:
接下来,我们将尝试如何通过Powershell来更高效的部署和管理Windows故障转移群集。实验环境所用的系统版本为Windows Server 2012,但应适用于更高版本。
安装Windows Failover Clustering 角色
安装集群涉及到的账户
- 用于创建集群的账户: 此账户账户用于启动群集创建向导;集群计算机账户的创建也依赖于此账户。
- 集群名称账户: 集群计算机账户,也成为集群名称对象或CNO,此账户由集群创建向导自动创建,名称即为集群名。集群计算机账户十分重要,当在集群上创建服务和应用时,要依赖于此账户。如果此账户被删除或者权限被移除,集群将不能创建集群要求的其它用户除非这个账户被恢复或者被授予足有的权限。
例如,如果你想在集群Cluster1上配置打印服务器PrintServer1,账户Cluster1需要被赋予正确的权限以便它有权限去创建一个名叫PrintServer1的计算机账户。- 集群服务或应用的计算机账户:这些账户在创建高可用集群服务或应用时被自动创建,创建Hyper-V虚拟机例外。集群账户将被赋予管理这些账户的权限。
例如,如果你想在集群Cluster1上创建文件服务器FileServer1,高可用向导将在AD中创建一个名叫FileServer1的计算机账户,高可用向导也会赋予集群账户必要的权限去管理账户FileServer1.
下图摘自https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc731002(v=ws.10)?redirectedfrom=MSDN
image.png
部署集群
本文实验环境为两台Windows Server 2012 R2
node1.buffallos.com : 192.168.100.201
node2.buffallos.com:192.168.100.202
- 安装Windows Failover Clustering 功能组件(所有节点均需安装)
# 定义节点服务器列表
$server=@("node1.buffallos.com","node2.buffallos.com")
PS C:\Windows\system32> $servers
node1.buffallos.com
node2.buffallos.com
# 安装Failover Clustering 功能组件
PS C:\Windows\system32> Invoke-Command ($servers) {Install-WindowsFeature -Name Failover-Clustering -IncludeManagementTools}
Success Restart Needed Exit Code Feature Result PSComputerName
------- -------------- --------- -------------- --------------
True No Success {故障转移群集, 远程服务器管理工具, 故障转移群集工具, Windows Powe... node2.buffallos.com
警告: 未启用 Windows 自动更新。为确保自动更新最新安装的角色或功能,请启用 Windows 更新。
True No Success {故障转移群集, 远程服务器管理工具, 故障转移群集工具, Windows Powe... node1.buffallos.com
警告: 未启用 Windows 自动更新。为确保自动更新最新安装的角色或功能,请启用 Windows 更新。
- 测试节点是否满足配置Failover Clustering要求,如下图,由于我们是测试环境,存储将使用我的另外一篇博文 使用powershell配置和管理基于Windows的iSCSI - 简书 (jianshu.com) 中创建的iSCSI磁盘作为集群存储,因此会有些存储警告,但是测试通过。测试会生成报告,存储在
C:\Windows\Cluster\Reports
或者%USERPROFILE%\AppData\Local
以供在测试不通过时用来Troubleshooting.
PS C:\Users\huzx> Test-Cluster -Node node1,node2
警告: 存储 - 列出要进行验证的磁盘: 测试报告了一些警告。。
警告: 存储 - 验证 SCSI 设备重要产品数据 (VPD): 测试报告了一些警告。。
警告: 存储 - 验证 SCSI-3 永久保留: 测试报告了一些警告。。
警告: 存储 - 验证磁盘访问延迟: 测试报告了一些警告。。
警告: 存储 - 验证磁盘仲裁: 测试报告了一些警告。。
警告: 存储 - 验证存储空间永久保留: 测试报告了一些警告。。
警告: 存储 - 验证多重仲裁: 测试报告了一些警告。。
警告: 存储 - 验证基于 Microsoft MPIO 的磁盘: 测试报告了一些警告。。
警告: 存储 - 验证磁盘故障转移: 测试报告了一些警告。。
警告: 存储 - 验证文件系统: 测试报告了一些警告。。
警告: 存储 - 验证并发故障转移: 测试报告了一些警告。。
警告:
测试结果:
ClusterConditionallyApproved
测试已成功完成。该配置似乎适合进行群集,但你仍应当查看报告,因为该报告可能包含某些警告,你需要解决这些警告才能获得最高可用性。
测试报告文件路径: C:\Users\huzx\AppData\Local\Temp\2\验证报告 在 18.13.19 上的 2021.01.14 .xml.mht
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2021/1/14 18:14 395854 验证报告 在 18.13.19 上的 2021.01.14 .xml.mht
- 创建一个名为TestClusterA的Cluster,cluster需要指定一个虚拟IP(本例使用192.168.100.220作为其地址,创建完成后,AD中会新创建一个名为TestClusterA的计算机被加入,TestClusterA.buffallos.com (192.168.100.220)的DNS记录也会被创建
PS C:\Users\huzx> New-Cluster -Name TestClusterA -Node node1,node2 -StaticAddress 192.168.100.220
New-Cluster : 未配置静态网络 192.168.199.0/24。请使用 -StaticAddress 来使用此网络,或者使用 -IgnoreNetwork 来忽略此网络。
所在位置 行:1 字符: 1
+ New-Cluster -Name TestClusterA -Node node1,node2 -StaticAddress 192.168.100.220
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Cluster],ClusterCmdletException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.FailoverClusters.PowerShell.NewClusterCommand
如上图,出现报错,这是因为我们的每个节点有两块网卡,分别连接不同的网络(192.168.100.0/24 和192.168.199.0/24),如果集群需要向两个网段同时提供服务或者两个节点来自不同的网段,则可以提供多个虚拟IP如下例;如不需要则可以添加-ignorenetwork参数忽略掉
New-Cluster -Name TestClusterA -Node node1,node2 -StaticAddress 192.168.100.220,192.168.199.220
如果我们集群的地址涉及地址都开启DHCP自动获取IP,我们也可以用下面命令创建
New-Cluster -Name TestClusterA -Node node1,node2
创建集群时,我们还可以指定它创建后所在的AD的OU,比如下面的命令
New-Cluster -Name "CN=TestClusterA,OU=Cluster,DC=buffallos,DC=com" -Node node1,node2 -StaticAddress 192.168.100.220
本例将使用比较常用的方式,只指定静态地址和(192.168.100.0/24)的虚拟IP
PS C:\Users\huzx> New-Cluster -Name TestClusterA -Node node1,node2 -StaticAddress 192.168.100.220 -IgnoreNetwork 192.168.199.0/24
报告文件位置: C:\Windows\cluster\Reports\创建群集向导 TestClusterA on 2021.01.14 At 20.50.12.mht
Name
----
TestClusterA
集群创建成功
PS C:\Windows\system32> Get-ADComputer -Filter {name -like 'testclustera'}
DistinguishedName : CN=TESTCLUSTERA,CN=Computers,DC=buffallos,DC=com
DNSHostName : TestClusterA.buffallos.com
Enabled : True
Name : TESTCLUSTERA
ObjectClass : computer
ObjectGUID : aa6c6941-1423-4f18-be8d-833fc07227ba
SamAccountName : TestClusterA$
SID : S-1-5-21-3035757615-648915789-1977492108-1107
UserPrincipalName :
PS C:\Windows\system32> Resolve-DnsName testclustera
Name Type TTL Section IPAddress
---- ---- --- ------- ---------
testclustera.buffallos.com A 1200 Answer 192.168.100.220
对应的计算机和DNS记录已经创建.
小知识:
- 安装AD远程管理工具
Install-WindowsFeature -Name rsat-ad-powershell
- Windows server 2008 R2 或更新
Add-WindowsCapability -Online -Name Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0
- Windows 10- 安装集群远程管理工具 (powershell module)
install-WindowsFeature -Name RSAT-Clustering
- Windows Server 2008 R2 或更新
Add-WindowsCapability -Online -Name Rsat.FailoverCluster.Management.Tools~~~~0.0.1.0
- Windows 10
- 查看集群的信息和配置
PS C:\Windows\system32> Get-Cluster -Name testclustera | fl *
AddEvictDelay : 60
AdministrativeAccessPoint : ActiveDirectoryAndDns
AutoAssignNodeSite : 0
AutoBalancerMode : 2
AutoBalancerLevel : 1
BackupInProgress : 0
BlockCacheSize : 0
DetectedCloudPlatform : None
DetectManagedEvents : 0
DetectManagedEventsThreshold : 0
ClusSvcHangTimeout : 60
ClusSvcRegroupStageTimeout : 5
ClusSvcRegroupTickInMilliseconds : 300
ClusterEnforcedAntiAffinity : 0
ClusterFunctionalLevel :
ClusterUpgradeVersion :
ClusterGroupWaitDelay : 120
ClusterLogLevel : 3
ClusterLogSize : 300
CrossSiteDelay :
CrossSiteThreshold :
CrossSubnetDelay : 1000
CrossSubnetThreshold : 5
CsvBalancer : 1
DatabaseReadWriteMode : 0
DefaultNetworkRole : 2
Description :
Domain : buffallos.com
DrainOnShutdown : 1
DumpPolicy : 0
DynamicQuorum : 1
EnableSharedVolumes : Enabled
FixQuorum : 0
GroupDependencyTimeout : 600
HangRecoveryAction : 3
Id : 8f53bc7f-90f1-42be-825a-5539eb34aa87
IgnorePersistentStateOnStartup : 0
LogResourceControls : 0
LowerQuorumPriorityNodeId : 0
MessageBufferLength : 50
MinimumNeverPreemptPriority : 3000
MinimumPreemptorPriority : 1
Name : TestClusterA
NetftIPSecEnabled : 1
PlacementOptions : 0
PlumbAllCrossSubnetRoutes : 0
PreferredSite :
PreventQuorum : 0
QuarantineDuration : 0
QuarantineThreshold : 0
QuorumArbitrationTimeMax : 20
RecentEventsResetTime : 2021/1/14 12:50:23
RequestReplyTimeout : 60
ResiliencyDefaultPeriod : 0
ResiliencyLevel :
RouteHistoryLength : 10
S2DBusTypes : 0
S2DCacheBehavior : 0
S2DCacheDesiredState : Disabled
S2DCacheMetadataReserveBytes : 0
S2DCachePageSizeKBytes : 0
S2DEnabled : 0
S2DIOLatencyThreshold : 0
S2DOptimizations : 0
SameSubnetDelay : 1000
SameSubnetThreshold : 5
SecurityLevel : 1
SecurityLevelForStorage :
SharedVolumeCompatibleFilters : {}
SharedVolumeIncompatibleFilters : {}
SharedVolumeSecurityDescriptor : {1, 0, 4, 128...}
SharedVolumesRoot : C:\ClusterStorage
SharedVolumeVssWriterOperationTimeout : 1800
ShutdownTimeoutInMinutes : 20
UseClientAccessNetworksForSharedVolumes : 0
WitnessDatabaseWriteTimeout : 300
WitnessDynamicWeight : 0
WitnessRestartInterval : 15
EnabledEventLogs :
- 查看当前已有的集群资源
PS C:\Windows\system32> Invoke-Command -ComputerName node1 -ScriptBlock {Get-Cluster -Name TestClusterA | Get-ClusterResource}
Name State OwnerGroup ResourceType PSComputerName
---- ----- ---------- ------------ --------------
群集 IP 地址 群集组 IP Address node1
群集名称 群集组 Network Name node1
6.将创建好的iSCSI磁盘添加进群集TestClusterA
[node1]: PS C:\Users\huzx\Documents> Get-ClusterAvailableDisk | Add-ClusterDisk
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
群集磁盘1 OnlinePending 可用存储 Physical Disk
群集磁盘2 OnlinePending 可用存储 Physical Disk
群集磁盘3 OnlinePending 可用存储 Physical Disk
[node1]: PS C:\Users\huzx\Documents> Get-ClusterResource |ft -AutoSize -wrap
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
群集 IP 地址 Online 群集组 IP Address
群集磁盘1 Online 可用存储 Physical Disk
群集磁盘2 Online 可用存储 Physical Disk
群集磁盘3 Online 可用存储 Physical Disk
群集名称 Online 群集组 Network Name
使用Powershell管理集群
- 查看节点和节点的详细信息
PS C:\Windows\system32> Get-ClusterNode -Cluster TestClusterA | fl *
BuildNumber : 9600
Cluster : TestClusterA
CSDVersion :
Description :
DrainStatus : NotInitiated
DrainTarget : 4294967295
DynamicWeight : 0
Id : 1
MajorVersion : 6
MinorVersion : 3
Name : node1
NeedsPreventQuorum : 0
NodeHighestVersion : 533888
NodeInstanceID : 00000000-0000-0000-0000-000000000001
NodeLowestVersion : 533888
NodeName : node1
NodeWeight : 1
FaultDomain :
Model :
Manufacturer :
SerialNumber :
State : Up
StatusInformation : Normal
Type : Node
DetectedCloudPlatform : None
BuildNumber : 9600
Cluster : TestClusterA
CSDVersion :
Description :
DrainStatus : NotInitiated
DrainTarget : 4294967295
DynamicWeight : 1
Id : 2
MajorVersion : 6
MinorVersion : 3
Name : node2
NeedsPreventQuorum : 0
NodeHighestVersion : 533888
NodeInstanceID : 00000000-0000-0000-0000-000000000002
NodeLowestVersion : 533888
NodeName : node2
NodeWeight : 1
FaultDomain :
Model :
Manufacturer :
SerialNumber :
State : Up
StatusInformation : Normal
Type : Node
DetectedCloudPlatform : None
2.将创建好的iSCSI磁盘添加进群集TestClusterA
[node1]: PS C:\Users\huzx\Documents> Get-ClusterAvailableDisk | Add-ClusterDisk
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
群集磁盘1 OnlinePending 可用存储 Physical Disk
群集磁盘2 OnlinePending 可用存储 Physical Disk
群集磁盘3 OnlinePending 可用存储 Physical Disk
[node1]: PS C:\Users\huzx\Documents> Get-ClusterResource |ft -AutoSize -wrap
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
群集 IP 地址 Online 群集组 IP Address
群集磁盘1 Online 可用存储 Physical Disk
群集磁盘2 Online 可用存储 Physical Disk
群集磁盘3 Online 可用存储 Physical Disk
群集名称 Online 群集组 Network Name
- 设置群集仲裁为节点磁盘多数仲裁,然后查看仲裁信息
[node1]: PS C:\Users\huzx\Documents> Set-ClusterQuorum -DiskWitness "群集磁盘1"
Cluster QuorumResource
------- --------------
TestClusterA 群集磁盘1
[node1]: PS C:\Users\huzx\Documents> Get-ClusterQuorum -Cluster TestClusterA | fl *
Cluster : TestClusterA
QuorumResource : 群集磁盘1
QuorumType : NodeAndDiskMajority
如果像设置为节点共享文件夹多数仲裁,可以使用如下命令
PS C:\> Set-ClusterQuorum -NodeAndFileShareMajority \\DC\ClusterFSW
4.为了方便日后运维,资源可以更改名字,下面我们将加"群集磁盘1"更改为Witness
[node1]: PS C:\Users\huzx\Documents> (Get-ClusterResource -name "群集磁盘1").name = "Witness"
[node1]: PS C:\Users\huzx\Documents> Get-ClusterResource -name witness
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
witness Online 群集组 Physical Disk
[node1]: PS C:\Users\huzx\Documents> Get-ClusterResource | ft -AutoSize -wrap
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
Witness Online 群集组 Physical Disk
群集 IP 地址 Online 群集组 IP Address
群集磁盘2 Online 可用存储 Physical Disk
群集磁盘3 Online 可用存储 Physical Disk
群集名称 Online 群集组 Network Name
- 重名集群网络
[node1]: PS C:\Users\huzx\Documents> Get-ClusterNetworkInterface | ft -AutoSize -wrap
Name Node Network State
---- ---- ------- -----
node1 - Ethernet0 node1 群集网络 1 Up
node2 - Ethernet0 node2 群集网络 1 Up
node1 - Ethernet1 node1 群集网络 2 Up
node2 - Ethernet1 node2 群集网络 2 Up
[node1]: PS C:\Users\huzx\Documents> Get-ClusterNetwork | fl *
Cluster : TestClusterA
State : Up
Name : 群集网络 1
Ipv6Addresses : {}
Ipv6PrefixLengths : {}
Ipv4Addresses : {192.168.199.0}
Ipv4PrefixLengths : {24}
Address : 192.168.199.0
AddressMask : 255.255.255.0
Description :
Role : 3
AutoMetric : True
Metric : 70384
Id : 0c0d6d0f-6bd6-46ae-a096-bd8a79b10990
Cluster : TestClusterA
State : Up
Name : 群集网络 2
Ipv6Addresses : {}
Ipv6PrefixLengths : {}
Ipv4Addresses : {192.168.100.0}
Ipv4PrefixLengths : {24}
Address : 192.168.100.0
AddressMask : 255.255.255.0
Description :
Role : 3
AutoMetric : True
Metric : 70385
Id : 2f1dc2bc-8024-490c-a847-5fec12ff9aeb
[node1]: PS C:\Users\huzx\Documents> (Get-ClusterNetwork -Name "群集网络 1").name = "Internet"
[node1]: PS C:\Users\huzx\Documents> (Get-ClusterNetwork -Name "群集网络 2").name = "HeartBeat&Domain"
[node1]: PS C:\Users\huzx\Documents> Get-ClusterNetworkInterface | ft -AutoSize -wrap
Name Node Network State
---- ---- ------- -----
node1 - Ethernet1 node1 HeartBeat&Domain Up
node2 - Ethernet1 node2 HeartBeat&Domain Up
node1 - Ethernet0 node1 Internet Up
node2 - Ethernet0 node2 Internet Up
- 为集群配置访问和管理权限
- 查看当前权限信息
[node1]: PS C:\Users\huzx\Documents> Get-ClusterAccess | ft -AutoSize -wrap
IdentityReference AccessControlType ClusterRights
----------------- ----------------- -------------
NT AUTHORITY\SYSTEM Allow Full
NT AUTHORITY\NETWORK SERVICE Allow Full
BUILTIN\Administrators Allow Full
NT SERVICE\MSDTC Allow Full
- 我们有可能会给不同的账户分配不同的权限,可以使用grant-clusteraccess来实现,默认权限为read-only可以添加参数-Full来给目标用户分配完全管理权限
PS C:\Windows\system32> Grant-ClusterAccess -Cluster TestClusterA -User buffallos\ClusterAdmin -Full
PS C:\Windows\system32> Get-ClusterAccess -cluster TestClusterA
IdentityReference AccessControlType ClusterRights
----------------- ----------------- -------------
NT AUTHORITY\SYSTEM Allow Full
NT AUTHORITY\NETWORK SERVICE Allow Full
BUILTIN\Administrators Allow Full
buffallos\ClusterAdmin Allow Full
NT SERVICE\MSDTC Allow Full
用户被分配管理权限后,可以在用户所用的计算机上安装RSAT进行远程管理群集,但是为了安全,不建议将此用户添加到Domain Admins组。
移除某个用户的群集管理权限可以使用Remove-ClusterAccess
PS C:\> Remove-ClusterAccess -Cluster TestClusterA Buffallos\ClusterAdmin
但是这种方式移除用户后,并不能保证该用户已经没有群集权限,因为有可能该用户所隶属的组可能有管理权限,因此如果想明确某个用户不能拥有群集权限可以使用Block-ClusterAccess,如下,明确ClusterAdmin不能有集群权限
Block-ClusterAccess -Cluster TestClusterA -user buffallos\ClusterAdmin
7.下面我们将使用powershell快速创建一个群集文件服务角色(Windows 故障转移群集 Part 3 中详述了图形化创建过程),然后再了解下群集组。
分享个小函数,命令行模式运行powershell,粘贴到脚本然后执行,Get-ClusterDisk函数就可以调用,这个函数可以将集群磁盘和物理磁盘关联起来
Function Get-ClusterDisk { [CmdletBinding()] Param( [string]$cluster ) $ClusterDisks=@() Get-ClusterResource -Cluster $cluster | ? {$_.ResourceType -eq "Physical Disk"} | % { $resourcename = $_.Name $resource = Get-WmiObject -Namespace root\mscluster -class mscluster_resource | ? {$_.Name -eq $resourcename} $disk = Get-WmiObject -Namespace root\mscluster -Query "ASSOCIATORS OF {$resource} WHERE ResultClass=mscluster_disk" $physicaldisk=get-disk | ? {$_.UniqueId -eq $disk.UniqueId} $ClusterDisk = New-Object -TypeName psobject -Property @{ ClusterDiskName=$resource.Name ClusterDiskNumber=$disk.Number ClusterDiskFriendlyName=$physicaldisk.FriendlyName ClusterDiskStatus=$physicaldisk.OperationalStatus ClusterDiskSize=$physicaldisk.Size ClusterDiskType=$physicaldisk.PartitionStyle } $ClusterDisks += $ClusterDisk } $ClusterDisks | select ClusterDiskName,ClusterDiskFriendlyName,ClusterDiskType,ClusterDiskNumber,ClusterDiskStatus,@{l="ClusterDiksSize(GB)";e={$_.ClusterDiskSize / 1GB}} }
执行上面的函数后,结果如下,我们可以看到,群集磁盘 3
容量最大,我们将它作为文件服务器存储
[node1]: PS C:\Users\huzx\Documents> Get-ClusterDisk -cluster TestClusterA
ClusterDiskName : Witness
ClusterDiskFriendlyName : MSFT Virtual HD SCSI Disk Device
ClusterDiskType : GPT
ClusterDiskNumber : 3
ClusterDiskStatus : Online
ClusterDiksSize(GB) : 1
ClusterDiskName : 群集磁盘2
ClusterDiskFriendlyName : MSFT Virtual HD SCSI Disk Device
ClusterDiskType : GPT
ClusterDiskNumber : 2
ClusterDiskStatus : Online
ClusterDiksSize(GB) : 30
ClusterDiskName : 群集磁盘3
ClusterDiskFriendlyName : MSFT Virtual HD SCSI Disk Device
ClusterDiskType : GPT
ClusterDiskNumber : 1
ClusterDiskStatus : Online
ClusterDiksSize(GB) : 50
我们把磁盘3名称改为F_Disk,方便区分
[node1]: PS C:\Users\huzx\Documents> (Get-ClusterResource -Name "群集磁盘3").name = "F_Disk"
[node1]: PS C:\Users\huzx\Documents> Get-ClusterResource | ? {$_.resourcetype -eq 'physical disk'} | ft -AutoSize -wrap
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
F_Disk Online 可用存储 Physical Disk
Witness Online 群集组 Physical Disk
群集磁盘2 Online 可用存储 Physical Disk
创建文件服务器FileA并创建共享文件夹E:\Data
PS C:\Users\huzx> Add-ClusterFileServerRole -Storage "F_Disk" -Name "FileA" -StaticAddress 192.168.100.221 -IgnoreNetwork 192.168.199.0/24
Name OwnerNode State
---- --------- -----
FileA node1 Online
PS C:\Users\huzx> mkdir e:\Data
目录: E:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2021/1/18 23:51 Data
PS C:\Users\huzx> New-SmbShare -Name Data -Path "E:\Data" -EncryptData $true
Name ScopeName Path Description
---- --------- ---- -----------
Data FILEA E:\Data
默认情况下,群集组类型只有群集组和可用存储组,但是在我们创建了文件服务器后,与文件服务器相关的资源都被放在了FileA这个群集组中,如下
[node1]: PS C:\Users\huzx\Documents> Get-ClusterResource | ft -AutoSize -wrap
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
F_Disk Online FileA Physical Disk
FileA Online FileA Network Name
IP 地址 192.168.100.221 Online FileA IP Address
Witness Online 群集组 Physical Disk
群集 IP 地址 Online 群集组 IP Address
群集磁盘2 Online 可用存储 Physical Disk
群集名称 Online 群集组 Network Name
文件服务器 (\\FileA) Online FileA File Server
[node1]: PS C:\Users\huzx\Documents> (Get-ClusterResource -Name 'IP 地址 192.168.100.221').name ="FileA_IPAddress"
[node1]: PS C:\Users\huzx\Documents> Get-ClusterResource | ? {$_.ownergroup -eq 'FileA'} | ft -AutoSize -wrap
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
F_Disk Online FileA Physical Disk
FileA Online FileA Network Name
FileA_IPAddress Online FileA IP Address
文件服务器 (\\FileA) Online FileA File Server
我们定义集群组,其目的就是为了方便管理,一般会把所提供服务或应用所用到的资源归为一组,每当需要管理其相关资源时,可以通过组方式筛选
- 添加群集资源到组
Move-ClusterResource
本例中,我们将为闲置一块磁盘移动到到群集组FileA
[node1]: PS C:\Users\huzx\Documents> Get-ClusterResource | ? {$_.name -eq '群集磁盘2'} | ft -AutoSize -wrap
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
群集磁盘2 Online 可用存储 Physical Disk
[node1]: PS C:\Users\huzx\Documents> Move-ClusterResource -Name '群集磁盘2' -Group FileA
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
群集磁盘2 Online FileA Physical Disk
[node1]: PS C:\Users\huzx\Documents> Get-ClusterResource | ? {$_.name -eq '群集磁盘2'} | ft -AutoSize -wrap
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
群集磁盘2 Online FileA Physical Disk
- 集群资源的依赖 集群资源间存在依赖关系,集群服务会根据依赖关系来决定集群资源上线和下线的顺序,本文首部集群部署相关文章有介绍
通过以下命令,获取前面创建的群集文件服务器的依赖,文件服务器角色依赖网络和存储
[node1]: PS C:\Users\huzx\Documents> Get-ClusterGroup filea | Get-ClusterResource | ft -AutoSize -wra
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
F_Disk Online FileA Physical Disk
FileA Online FileA Network Name
FileA_IPAddress Online FileA IP Address
群集磁盘2 Online FileA Physical Disk
文件服务器 (\\FileA) Online FileA File Server
[node1]: PS C:\Users\huzx\Documents> Get-ClusterResourceDependency -Resource '文件服务器 (\\FileA)' | ft -AutoSize -wrap
Resource DependencyExpression
-------- --------------------
文件服务器 (\\FileA) ([FileA]) and ([F_Disk])
群集管理器中资源属性可以查看依赖关系
依赖关系还可以添加,下面我们将FileA组中的闲置磁盘添加文件服务器FileA依存关系,使其被后者依赖
[node1]: PS C:\Users\huzx\Documents> Add-ClusterResourceDependency -Resource '文件服务器 (\\FileA)' -Provider '群集磁盘2'
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
文件服务器 (\\FileA) Online FileA File Server
[node1]: PS C:\Users\huzx\Documents> Get-ClusterResourceDependency -Resource '文件服务器 (\\FileA)' | ft -AutoSize -wrap
Resource DependencyExpression
-------- --------------------
文件服务器 (\\FileA) ([群集磁盘2]) and ([FileA]) and ([F_Disk])
注意:添加的依赖逻辑操作符均为逻辑与(AND),即所有被依赖的资源上线后,依赖者才能上线,下线顺序相反
- 其它有用命令
- 查看服务器角色群集组中资源之间依赖关系
[node1]: PS C:\Users\huzx\Documents> Get-ClusterGroup -Name FileA | Get-ClusterResource | Get-ClusterResourceDependency | ft -AutoSize -wrap
Resource DependencyExpression
-------- --------------------
F_Disk
FileA ([FileA_IPAddress])
FileA_IPAddress
群集磁盘2
文件服务器 (\\FileA) ([群集磁盘2]) and ([FileA]) and ([F_Disk])
- 停止和启动资源
[node1]: PS C:\Users\huzx\Documents> Stop-ClusterResource -Name '文件服务器 (\\FileA)'
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
文件服务器 (\\FileA) Offline FileA File Server
[node1]: PS C:\Users\huzx\Documents> Get-ClusterGroup -Name FileA
Name OwnerNode State
---- --------- -----
FileA node1 Offline
[node1]: PS C:\Users\huzx\Documents> Get-ClusterGroup -Name FileA | Get-ClusterResource
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
F_Disk Online FileA Physical Disk
FileA Online FileA Network Name
FileA_IPAddress Online FileA IP Address
群集磁盘2 Online FileA Physical Disk
文件服务器 (\\FileA) Offline FileA File Server
[node1]: PS C:\Users\huzx\Documents> Start-ClusterResource -Name '文件服务器 (\\FileA)'
Name State OwnerGroup ResourceType
---- ----- ---------- ------------
文件服务器 (\\FileA) Online FileA File Server
[node1]: PS C:\Users\huzx\Documents> Get-ClusterGroup -Name FileA
Name OwnerNode State
---- --------- -----
FileA node1 Online
- 移动群集资源组到其他节点
[node1]: PS C:\Users\huzx\Documents> Get-ClusterGroup FileA | ft -AutoSize -Wrap
Name OwnerNode State
---- --------- -----
FileA node1 Online
[node1]: PS C:\Users\huzx\Documents> Move-ClusterGroup -Name FileA -Node node2
Name OwnerNode State
---- --------- -----
FileA node2 Online