Pour obtenir un nombre de votes majoritaire et atteindre un quorum pour le scénario de basculement, vous déployez une troisième VM faisant office de témoin de partage de fichiers.
Revenez à la session Cloud Shell que vous avez précédemment ouverte.
Créez un script de spécialisation pour les nœuds du cluster. Le script installe la fonctionnalité Windows nécessaire et crée des règles de pare-feu pour le cluster de basculement et 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
Créez les instances de VM. Sur les deux VM qui servent de nœuds de cluster, associez un disque de données supplémentaire et activez le clustering de basculement Windows Server en définissant la clé de métadonnées enable-wsfc sur true.
Pour rattacher les trois instances de VM à Active Directory, procédez comme suit pour chacune d'entre elles.
Surveillez le processus d'initialisation de la VM en consultant la sortie de son port série.
gcloud compute instances tail-serial-port-output NAME
Remplacez NAME par le nom de l'instance de VM.
Attendez environ trois minutes avant que la sortie Instance setup finished s'affiche, puis appuyez sur Ctrl+C. À ce stade, l'instance de VM est prête à être utilisée.
Effectuez un clic droit sur le bouton Start (Démarrer) (ou appuyez sur Win+X) et cliquez sur Windows PowerShell (Admin).
Confirmez l'invite d'élévation en cliquant sur Yes (Oui).
Rattachez l'ordinateur au domaine Active Directory, puis redémarrez-le.
Add-Computer -Domain DOMAIN -Restart
Remplacez DOMAIN par le nom DNS du domaine Active Directory.
Saisissez les identifiants d'un compte autorisé à associer une VM au domaine. Attendez environ une minute la fin du redémarrage.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/03 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/03 (UTC)."],[[["\u003cp\u003eA SQL Server premium image with SQL Server 2022 preinstalled can be used, or users can opt for Windows Server base images and install SQL Server with their own licenses via the license mobility program.\u003c/p\u003e\n"],["\u003cp\u003eA third VM is deployed as a file share witness to provide a tie-breaking vote and ensure quorum for failover.\u003c/p\u003e\n"],["\u003cp\u003eA specialize script is utilized to install necessary Windows features and establish firewall rules for the failover cluster and SQL Server, as well as format the data disk and create folders.\u003c/p\u003e\n"],["\u003cp\u003eVM instances are created, and the two cluster node VMs have an additional data disk attached and Windows Server Failover Clustering enabled using metadata.\u003c/p\u003e\n"],["\u003cp\u003eEach of the three VM instances must be added to an active directory domain, and credentials must be provided to facilitate joining the VM to the active directory domain.\u003c/p\u003e\n"]]],[],null,["You use a [SQL Server premium image](/compute/docs/images/os-details#sql_server)\nwhich has SQL Server 2022 preinstalled.\n| **Note:** If you plan to bring your own licenses for SQL Server by using the [license Mobility](/compute/docs/instances/windows/ms-licensing) program, select Windows Server base images for these nodes and install SQL Server using your own product keys.\n\nTo provide a tie-breaking vote and achieve a quorum for the failover scenario,\nyou deploy a third VM that serves as a\n[file share witness](https://docs.microsoft.com/en-us/windows-server/failover-clustering/manage-cluster-quorum#quorum-configuration-options).\n\n1. Return to your existing Cloud Shell session.\n2. Create a [specialize script](/compute/docs/startupscript#providing_a_startup_script_for_windows_instances)\n for the cluster nodes. The script installs the necessary Windows feature and creates\n firewall rules for the failover cluster and SQL Server.\n\n ```\n cat \u003c\u003c \"EOF\" \u003e specialize-node.ps1\n\n $ErrorActionPreference = \"stop\"\n\n # Install required Windows features\n Install-WindowsFeature Failover-Clustering -IncludeManagementTools\n Install-WindowsFeature RSAT-AD-PowerShell\n\n # Open firewall for availability group listener\n netsh advfirewall firewall add rule name=\"Allow SQL Server Listener health check\" dir=in action=allow protocol=TCP localport=59997\n\n # Open firewall for the Failover Cluster\n netsh advfirewall firewall add rule name=\"Allow SQL Server health check\" dir=in action=allow protocol=TCP localport=59998\n\n # Open firewall for SQL Server\n netsh advfirewall firewall add rule name=\"Allow SQL Server\" dir=in action=allow protocol=TCP localport=1433\n\n # Open firewall for SQL Server replication\n netsh advfirewall firewall add rule name=\"Allow SQL Server replication\" dir=in action=allow protocol=TCP localport=5022\n\n # Format data disk\n Get-Disk |\n Where partitionstyle -eq 'RAW' |\n Initialize-Disk -PartitionStyle MBR -PassThru |\n New-Partition -AssignDriveLetter -UseMaximumSize |\n Format-Volume -FileSystem NTFS -NewFileSystemLabel 'Data' -Confirm:$false\n\n # Create data and log folders for SQL Server\n md d:\\Data\n md d:\\Logs\n EOF\n ```\n3. Create the VM instances. On the two VMs that serve as cluster nodes,\n attach an additional data disk and enable the Windows Server Failover Clustering\n by setting the metadata key `enable-wsfc` to `true`.\n\n ```\n REGION=$(gcloud config get-value compute/region)\n ZONE1=$(gcloud config get-value compute/zone)\n ZONE2=$(gcloud config get-value compute/zone)\n ZONE3=$(gcloud config get-value compute/zone)\n PD_SIZE=200\n MACHINE_TYPE=n2-standard-8\n\n gcloud compute instances create node-1 \\\n --zone $ZONE1 \\\n --machine-type $MACHINE_TYPE \\\n --subnet $SUBNET_NAME \\\n --image-family sql-ent-2022-win-2022 \\\n --image-project windows-sql-cloud \\\n --tags wsfc,wsfc-node \\\n --boot-disk-size 50 \\\n --boot-disk-type pd-ssd \\\n --boot-disk-device-name \"node-1\" \\\n --create-disk=name=node-1-datadisk,size=$PD_SIZE,type=pd-ssd,auto-delete=no \\\n --metadata enable-wsfc=true \\\n --metadata-from-file=sysprep-specialize-script-ps1=specialize-node.ps1\n\n gcloud compute instances create node-2 \\\n --zone $ZONE2 \\\n --machine-type $MACHINE_TYPE \\\n --subnet $SUBNET_NAME \\\n --image-family sql-ent-2022-win-2022 \\\n --image-project windows-sql-cloud \\\n --tags wsfc,wsfc-node \\\n --boot-disk-size 50 \\\n --boot-disk-type pd-ssd \\\n --boot-disk-device-name \"node-2\" \\\n --create-disk=name=node-2-datadisk,size=$PD_SIZE,type=pd-ssd,auto-delete=no \\\n --metadata enable-wsfc=true \\\n --metadata-from-file=sysprep-specialize-script-ps1=specialize-node.ps1\n\n gcloud compute instances create \"witness\" \\\n --zone $ZONE3 \\\n --machine-type n2-standard-2 \\\n --subnet $SUBNET_NAME \\\n --image-family=windows-2022 \\\n --image-project=windows-cloud \\\n --tags wsfc \\\n --boot-disk-size 50 \\\n --boot-disk-type pd-ssd \\\n --metadata sysprep-specialize-script-ps1=\"add-windowsfeature FS-FileServer\"\n ```\n | **Note:** Depending on your [performance requirements](/compute/docs/disks/performance#optimize_disk_performance), consider using a machine type larger than `n2-standard-8` for the cluster nodes.\n | **Note:** For the purpose of this tutorial, and to fit within the default regional SSD Persistent Disk quota, the size of the disks attached to each VM is smaller than it would be in a production environment. For better performance and to accommodate a larger database, you would increase the size of each disk.\n4. To join the 3 VM instances to Active Directory, do the following for each of\n the 3 VM instances.\n\n 1. Monitor the initialization process of the VM by viewing its serial port output.\n\n gcloud compute instances tail-serial-port-output \u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e with the name of the VM instance.\n\n Wait about 3 minutes until you see the output `Instance setup finished`,\n then press Ctrl+C. At this point, the VM instance is ready to be used.\n 2. [Create a username and password](/compute/docs/instances/windows/creating-passwords-for-windows-instances)\n for the VM instance.\n\n 3. [Connect to the VM by using Remote Desktop](/compute/docs/instances/connecting-to-windows)\n and sign in using the username and password created in the previous step.\n\n 4. Right-click the **Start** button (or press **Win+X** ) and click **Windows PowerShell (Admin)**.\n\n | **Note:** In this guide, we used Powershell 5.1.\n 1. Confirm the elevation prompt by clicking **Yes**.\n 2. Join the computer to your Active Directory domain and restart.\n\n Add-Computer -Domain \u003cvar translate=\"no\"\u003eDOMAIN\u003c/var\u003e -Restart\n\n Replace \u003cvar translate=\"no\"\u003eDOMAIN\u003c/var\u003e with the DNS name of your Active Directory domain.\n 3. Enter the credentials of an account that has permissions to join a VM to\n the domain. Wait for approximately 1 minute for the restart to complete."]]