首页 > 代码库 > SqlCmd -Windows Cluster Model
SqlCmd -Windows Cluster Model
前提条件
1存储lun 划分完毕并且挂载到其中一台机器上
2 需要加入群集的节点机器加入域完毕,并设置好心跳线 .加域部分可以参考 之前 Sqler Cmd 加域部分.
1检查Feature 更新
SqlerCmdWinClusterInstallFeature
再需要按装cluster的 节点机器上面运行 SqlerCmdWinClusterInstallFeature
cat C:\CheckInstallClusterLog.Log
如果节点机器已安装
PS C:\Users\xwj> cat C:\CheckInstallClusterLog.Log
Application-Server,AS-Outgoing-Trans,AS-Incoming-Trans,Failover-clustering Is Exists
如果节点机器没安装
PS C:\Users\xwj> cat C:\CheckInstallClusterLog.Log
3428: 2013-04-09 14:14:25.685 [ServerManagerPS] Complete initializing log file. 3428: 2013-04-09 14:14:25.866 [CBS] IsCacheStillGood: True. 3428: 2013-04-09 14:14:26.540 [ServerManagerPS] 开始安装... 3428: 2013-04-09 14:14:26.541 [ServerManagerPS] 已为安装指定: [应用程序服务器] .NET Framework 3.5.1 3428: 2013-04-09 14:14:26.633 [Sync] Sync Graph of changed nodes ========== --------------------------------------------------------------------------- name : 应用程序服务器 state : Changed rank : 1 sync tech: Unknown guest[1] : .NET Framework 3.5.1 guest[2] : .NET 4.0 的应用程序服务器扩展 guest[3] : Web 服务器(IIS)支持 guest[4] : COM+ 网络访问 guest[5] : TCP 端口共享 guest[6] : Windows 进程激活服务支持 guest[7] : 分布式事务 ant. : empty pred. : empty provider : ApplicationServerRoleProvider --------------------------------------------------------------------------- name : .NET Framework 3.5.1 state : Changed rank : 10 sync tech: Unknown ant. : .NET Framework 3.5.1, 进程模型, .NET 环境, 配置 API pred. : 应用程序服务器, .NET Framework 3.5.1, 进程模型, .NET 环境, 配置 API provider : ApplicationServerRoleProvider 3428: 2013-04-09 14:14:26.634 [Sync] Calling sync provider of .NET Framework 3.5.1 ... 3428: 2013-04-09 14:14:26.635 [ApplicationServer] Sync:: guest: ‘.NET Framework 3.5.1‘, guest deleted?: False 3428: 2013-04-09 14:14:26.635 [ApplicationServer] Begin installation of ‘.NET Framework 3.5.1‘... 3428: 2013-04-09 14:14:26.638 [ApplicationServer] Installing: ‘.NET Framework 3.5.1‘ 3428: 2013-04-09 14:14:26.649 [ApplicationServer] Writing app server view: C:\ProgramData\Microsoft\Event Viewer\Views\ServerRoles\ApplicationServer.Events.xml 3428: 2013-04-09 14:14:26.651 [ApplicationServer] Skipped configuration of ‘.NET Framework 3.5.1‘ because running in command line mode. 3428: 2013-04-09 14:14:26.651 [ApplicationServer] [STAT] For ‘.NET Framework 3.5.1‘: [STAT] Installation took ‘0.0152068‘ second(s) total. [STAT] Configuration took ‘0‘ second(s) total. [STAT] Total time: ‘0.0152068‘ second(s). 3428: 2013-04-09 14:14:26.652 [Provider] Sync Result - Success: True, RebootRequired: False, Id: 230 3428: 2013-04-09 14:14:26.656 [Provider] Sync Message - OperationKind: Install, MessageType: Information, MessageCode: 0, Message: <null>, AdditionalMessage: <null> 3428: 2013-04-09 14:14:26.670 [ServerManagerPS] [STAT] Overall Sync Time: ‘0.0421967‘ second(s) 3428: 2013-04-09 14:14:26.732 [ServerManagerPS] [安装] 成功: [应用程序服务器] .NET Framework 3.5.1。 3428: 2013-04-09 14:14:27.641 [ServerManagerPS] Complete initializing log file. 3428: 2013-04-09 14:14:27.812 [CBS] IsCacheStillGood: True. 3428: 2013-04-09 14:14:27.890 [ServerManagerPS] 开始安装... 3428: 2013-04-09 14:14:27.891 [ServerManagerPS] 已为安装指定: [故障转移群集] 故障转移群集 3428: 2013-04-09 14:14:28.046 [Sync] Sync Graph of changed nodes ========== --------------------------------------------------------------------------- name : 故障转移群集 state : Changed rank : 1 sync tech: CBS ant. : empty pred. : empty provider : Provider 3428: 2013-04-09 14:14:28.046 [Sync] Calling sync provider of 故障转移群集 ... 3428: 2013-04-09 14:14:28.047 [Provider] Sync:: guest: ‘故障转移群集‘, guest deleted?: False 3428: 2013-04-09 14:14:28.047 [Provider] Begin installation of ‘故障转移群集‘... 3428: 2013-04-09 14:14:28.047 [Provider] Install: Guest: ‘故障转移群集‘, updateElement: ‘FailoverCluster-FullServer‘ 3428: 2013-04-09 14:14:28.048 [Provider] Installation queued for ‘故障转移群集‘. 3428: 2013-04-09 14:14:28.049 [CBS] installing ‘FailoverCluster-FullServer ‘ ... 3428: 2013-04-09 14:14:30.351 [CBS] ...parents that will be auto-installed: ‘<none>‘ 3428: 2013-04-09 14:14:30.351 [CBS] ...default children to turn-off: ‘<none>‘ 3428: 2013-04-09 14:14:30.493 [CBS] ...current state of ‘FailoverCluster-FullServer‘: p: Staged, a: Staged, s: UninstallRequested 3428: 2013-04-09 14:14:30.493 [CBS] ...setting state of ‘FailoverCluster-FullServer‘ to ‘InstallRequested‘ 3428: 2013-04-09 14:14:30.531 [CBS] ...‘FailoverCluster-FullServer‘ : applicability: Applicable 3428: 2013-04-09 14:14:32.291 [CbsUIHandler] Initiate: 3428: 2013-04-09 14:15:35.350 [CbsUIHandler] Terminate: 3428: 2013-04-09 14:15:35.854 [CBS] ...done installing ‘FailoverCluster-FullServer ‘. Status: 0 (0) 3428: 2013-04-09 14:15:35.922 [Provider] Skipped configuration of ‘故障转移群集‘ because running in command line mode. 3428: 2013-04-09 14:15:35.923 [Provider] [STAT] ---- CBS Session Consolidation ----- [STAT] For ‘故障转移群集‘[STAT] installation(s) took ‘67.8737122‘ second(s) total. [STAT] Configuration(s) took ‘0.0006572‘ second(s) total. [STAT] Total time: ‘67.8743694‘ second(s). 3428: 2013-04-09 14:15:35.924 [Provider] Sync Result - Success: True, RebootRequired: False, Id: 33 3428: 2013-04-09 14:15:35.924 [Provider] Sync Message - OperationKind: Install, MessageType: Information, MessageCode: 0, Message: <null>, AdditionalMessage: <null> 3428: 2013-04-09 14:15:35.993 [ServerManagerPS] [STAT] Overall Sync Time: ‘67.9480339‘ second(s) 3428: 2013-04-09 14:15:36.067 [ServerManagerPS] [安装] 成功: [故障转移群集] 故障转移群集。
2 Test-Cluster
Import-Module FailoverClusters; [array] $ClusterNodes=‘db001‘,‘db002‘ SqlerCmdWinClusterTest $ClusterNodes
cmd C:\ClusterReport.Log.mht
你可以在 查看 报告C:\ClusterReport.Log.mht
报告通过,下面正式开始安装
新建群集 配置群集ip 和节点
$DomainName=‘xwjtest‘ $ClusterName=‘ClusterTest‘; $ClusterIP=‘192.168.1.43‘; [array] $ClusterNodes=‘db001‘,‘db002‘ [array] $ClusterGroup =‘Test01‘,‘Test02‘; SqlerCmdCreateWinCluster $DomainName $ClusterName $ClusterIP $ClusterNodes
创建群集资源组
SqlerCmdWinClusterCreateGroup $ClusterName $ClusterNodes $ClusterGroup
创建 资源磁盘并获取磁盘信息
SqlerCmdWinClusterGetDiskResource $ClusterName ‘c:\CreateClusterDisk.log‘
cat c:\CreateClusterDisk.log
Name : 群集磁盘 1
Path : T:
FileSystem : NTFS
TotalSize : 2044
FreeSpace : 2006
Name : 群集磁盘 3
Path : Q:
FileSystem : NTFS
TotalSize : 1020
FreeSpace : 987
Name : 群集磁盘 5
Path : H:
FileSystem : NTFS
TotalSize : 1020
FreeSpace : 988
Name : 群集磁盘 2
Path : K:
FileSystem : NTFS
TotalSize : 252
FreeSpace : 230
Name : 群集磁盘 4
Path : M:
FileSystem : NTFS
TotalSize : 1020
FreeSpace : 988
根据需求合理分配磁盘
$ResourceName="群集磁盘 5" ,"群集磁盘 1" SqlerCmdWinClusterMoveDiskToGroup $ClusterName $ResourceName ‘Test01‘ $ResourceName="群集磁盘 4" SqlerCmdWinClusterMoveDiskToGroup $ClusterName $ResourceName ‘Test02‘
创建仲裁盘
SqlerCmdWinClusterCreateQuorum $ClusterName "群集磁盘 3" $ClusterNodes
创建 dtc
$DtcDiskName="群集磁盘 2" $DtcIpAddress=‘192.168.1.44‘ $DtcIpNetSub=‘255.255.255.0‘ SqlerCmdWinClusterCreateDtc $ClusterName $ClusterNodes $DtcDiskName $DtcIpAddress $DtcIpNetSub
流程化的安装大大降低了人为的错误,同时提高了个人效率. 适合大规模 流程化 db运维.
附上sqlerCmd Create CLuster 模块代码
1 Function SqlerCmdWinClusterInstallFeature 2 {param([string] $LogPath=‘C:\CheckInstallClusterLog.Log‘) 3 try 4 { 5 Import-Module ServerManager; 6 $Array= ‘Application-Server‘,‘AS-Outgoing-Trans‘,‘AS-Incoming-Trans‘,‘Failover-clustering‘ 7 $Feature=$Array| %{$f=$_; Get-WindowsFeature |where {$f -eq $_.Name -and $_.Installed -eq $False }|select-object Name,FeatureType,Installed}; 8 if((Test-Path -Path $LogPath )){Remove-Item -Path $LogPath}; 9 if($Feature -ne $Nul) 10 { 11 $Feature|foreach-object{ Add-WindowsFeature -Name $_.Name -logPath $LogPath } 12 Restart-computer -force 13 14 } 15 Else 16 { 17 "Application-Server,AS-Outgoing-Trans,AS-Incoming-Trans,Failover-clustering Is Exists "|out-file -FilePath $LogPath -Append 18 } 19 } 20 catch 21 { 22 $_.Exception.Message|out-file -FilePath $LogPath -Append 23 } 24 } 25 26 27 28 Function SqlerCmdWinClusterTest 29 {param([array] $Nodes,[string] $LogPath=‘C:\ClusterReport.Log‘) 30 try 31 { 32 if((Test-Path -Path $LogPath )){Remove-Item -Path $LogPath}; 33 Test-Cluster -Node $Nodes -reportname $LogPath 34 } 35 catch [Exception] 36 { 37 $_.Exception.Message|out-file -FilePath $LogPath -Append 38 } 39 } 40 41 42 43 Function SqlerCmdWinClusterCreate 44 {param 45 ([string] $DomainName 46 ,[string] $ClusterName 47 ,[string] $ClusterIP 48 ,[array] $ClusterNodes 49 ) 50 try 51 { 52 if( (Get-Cluster -domain $DomainName |where {$_.Name -eq $ClusterName }) -eq $Null) 53 { 54 New-Cluster -Name $ClusterName -StaticAddress $ClusterIP -Node $ClusterNodes -NoStorage -ErrorAction Stop; 55 $Return=‘OK‘ 56 } 57 else 58 { 59 $Return= ‘Exists Cluster : ‘+$ClusterName 60 } 61 } 62 catch 63 { 64 $Return=$_.Exception.Message 65 } 66 Return $Return 67 } 68 69 70 71 72 Function SqlerCmdWinClusterCreateGroup 73 {param 74 ( 75 [string] $ClusterName 76 ,[array] $ClusterNodes 77 ,[array] $ClusterGroup 78 ) 79 try 80 { 81 Foreach($GroupName in $ClusterGroup) 82 { 83 Add-ClusterGroup -Name $GroupName -Cluster $ClusterName -ErrorAction Stop ; 84 Set-ClusterOwnerNode -Group $GroupName -Owners $ClusterNodes -Cluster $ClusterName -ErrorAction Stop; 85 } 86 $Return=‘OK‘ 87 } 88 catch 89 { 90 $Return=$_.Exception.Message 91 } 92 Return $Return 93 } 94 95 96 97 98 Function SqlerCmdWinClusterGetDiskResource 99 {param 100 ([string] $ClusterName 101 ,[string] $LogPath=‘c:\CreateClusterDisk.log‘ 102 ) 103 try 104 { 105 Get-ClusterAvailableDisk -cluster $ClusterName | Add-ClusterDisk -ErrorAction Stop; 106 $MSCluster_DiskPartition=gwmi -Namespace root/MSCluster -class MSCluster_DiskPartition| select-object @{n=‘PartComponent‘;e={$_.__RELPATH}},FileSystem,TotalSize,FreeSpace,Path -ErrorAction Stop ; 107 $MSCluster_DiskToDiskPartition=gwmi -Namespace root/MSCluster -class MSCluster_DiskToDiskPartition |select-object PartComponent,GroupComponent -ErrorAction Stop ; 108 $MSCluster_ResourceToDisk=gwmi -Namespace root/MSCluster -class MSCluster_ResourceToDisk |select-object PartComponent,GroupComponent -ErrorAction Stop ; 109 $MSCluster_Resource=gwmi -Namespace root/MSCluster -class MSCluster_Resource | where {$_.type -replace ‘ ‘,‘‘ -eq ‘PhysicalDisk‘} |Select-object Name,@{n=‘GroupComponent‘;e={$_.__RELPATH}} -ErrorAction Stop ; 110 $ClusterDisk=$MSCluster_DiskPartition | % { $f = $_; $MSCluster_DiskToDiskPartition ` 111 | where { $_.PartComponent -eq $f.PartComponent } ` 112 | Select GroupComponent,PartComponent,@{n=‘Path‘;e={$f.path}},@{n=‘FileSystem‘;e={$f.FileSystem}},@{n=‘TotalSize‘;e={$f.TotalSize}},@{n=‘FreeSpace‘;e={$f.FreeSpace}}} ` 113 | % { $e=$_; $MSCluster_ResourceToDisk |where { $_.PartComponent -eq $e.GroupComponent } ` 114 | Select GroupComponent,PartComponent, @{n=‘Path‘;e={$e.path}},@{n=‘FileSystem‘;e={$e.FileSystem}},@{n=‘TotalSize‘;e={$e.TotalSize}},@{n=‘FreeSpace‘;e={$e.FreeSpace}}} ` 115 | % { $d = $_; $MSCluster_Resource| where { $d.GroupComponent -eq $_.GroupComponent } ` 116 | Select Name, @{n=‘Path‘;e={$d.path}},@{n=‘FileSystem‘;e={$d.FileSystem}},@{n=‘TotalSize‘;e={$d.TotalSize}},@{n=‘FreeSpace‘;e={$d.FreeSpace}}}; 117 if((Test-Path -Path $LogPath )){Remove-Item -Path $LogPath}; 118 $ClusterDisk|out-file -FilePath $LogPath -Append 119 $Return=‘OK‘ 120 } 121 catch 122 { 123 $Return=$_.Exception.Message 124 } 125 Return $Return 126 } 127 128 129 130