使用预安装了 SQL Server 2022 的 SQL Server 高级映像。
为了在故障切换情景中提供决定性投票权,实现仲裁,您需要部署第三个虚拟机作为文件共享见证者。
- 返回到现有的 Cloud Shell 会话。
为集群节点创建专用脚本。该脚本会安装必要的 Windows 功能,并为故障切换集群和 SQL Server 创建防火墙规则。
cat << "EOF" > specialize-node.ps1 $ErrorActionPreference = "stop" # Install required Windows features Install-WindowsFeature Failover-Clustering -IncludeManagementTools Install-WindowsFeature RSAT-AD-PowerShell # Open firewall for availability group listener netsh advfirewall firewall add rule name="Allow SQL Server Listener health check" dir=in action=allow protocol=TCP localport=59997 # Open firewall for the Failover Cluster netsh advfirewall firewall add rule name="Allow SQL Server health check" dir=in action=allow protocol=TCP localport=59998 # Open firewall for SQL Server netsh advfirewall firewall add rule name="Allow SQL Server" dir=in action=allow protocol=TCP localport=1433 # Open firewall for SQL Server replication netsh advfirewall firewall add rule name="Allow SQL Server replication" dir=in action=allow protocol=TCP localport=5022 # Format data disk Get-Disk | Where partitionstyle -eq 'RAW' | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel 'Data' -Confirm:$false # Create data and log folders for SQL Server md d:\Data md d:\Logs EOF
创建虚拟机实例。在充当集群节点的两个虚拟机上,通过将元数据键
enable-wsfc
设置为true
,再挂接一个数据磁盘并启用 Windows Server 故障切换集群。REGION=$(gcloud config get-value compute/region) ZONE1=$(gcloud config get-value compute/zone) ZONE2=$(gcloud config get-value compute/zone) ZONE3=$(gcloud config get-value compute/zone) PD_SIZE=200 MACHINE_TYPE=n2-standard-8 gcloud compute instances create node-1 \ --zone $ZONE1 \ --machine-type $MACHINE_TYPE \ --subnet $SUBNET_NAME \ --image-family sql-ent-2022-win-2022 \ --image-project windows-sql-cloud \ --tags wsfc,wsfc-node \ --boot-disk-size 50 \ --boot-disk-type pd-ssd \ --boot-disk-device-name "node-1" \ --create-disk=name=node-1-datadisk,size=$PD_SIZE,type=pd-ssd,auto-delete=no \ --metadata enable-wsfc=true \ --metadata-from-file=sysprep-specialize-script-ps1=specialize-node.ps1 gcloud compute instances create node-2 \ --zone $ZONE2 \ --machine-type $MACHINE_TYPE \ --subnet $SUBNET_NAME \ --image-family sql-ent-2022-win-2022 \ --image-project windows-sql-cloud \ --tags wsfc,wsfc-node \ --boot-disk-size 50 \ --boot-disk-type pd-ssd \ --boot-disk-device-name "node-2" \ --create-disk=name=node-2-datadisk,size=$PD_SIZE,type=pd-ssd,auto-delete=no \ --metadata enable-wsfc=true \ --metadata-from-file=sysprep-specialize-script-ps1=specialize-node.ps1 gcloud compute instances create "witness" \ --zone $ZONE3 \ --machine-type n2-standard-2 \ --subnet $SUBNET_NAME \ --image-family=windows-2022 \ --image-project=windows-cloud \ --tags wsfc \ --boot-disk-size 50 \ --boot-disk-type pd-ssd \ --metadata sysprep-specialize-script-ps1="add-windowsfeature FS-FileServer"
如需将 3 个虚拟机实例加入 Active Directory,请对 3 个虚拟机实例中的每个实例执行以下操作。
通过查看虚拟机的串行端口输出来监控其初始化过程。
gcloud compute instances tail-serial-port-output
NAME
将
NAME
替换为虚拟机实例的名称。等待大约 3 分钟,直到您看到输出
Instance setup finished
,然后按 Ctrl+C。此时,该虚拟机实例已准备就绪,可以使用了。为虚拟机实例创建用户名和密码。
使用远程桌面连接到虚拟机,然后使用上一步中创建的用户名和密码登录。
右键点击开始按钮(或者按 Win+X),然后点击 Windows PowerShell(管理员)。
- 点击是以确认提升权限提示。
将该计算机加入您的 Active Directory 网域,然后重启。
Add-Computer -Domain
DOMAIN -Restart
将
DOMAIN
替换为您的 Active Directory 域的 DNS 名称。输入具有将虚拟机加入网域所需权限的账号凭证。等待重启过程完成,大约需要 1 分钟。