SQL Server 2022 がプリインストールされた SQL Server プレミアム イメージを使用します。

多数決でフェイルオーバー シナリオのクォーラムを構成するには、ファイル共有監視として機能する 3 つ目の VM をデプロイします。

  1. 既存の Cloud Shell セッションに戻ります。
  2. クラスタノード用の専用スクリプトを作成します。このスクリプトは、必要な 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
    
  3. VM インスタンスを作成します。クラスタノードとして機能する 2 つの VM で、追加のデータディスクをアタッチして、メタデータキー enable-wsfctrue に設定し、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"
    
  4. 3 つの VM インスタンスを Active Directory に参加させるには、3 つの各 VM インスタンスに対して次の操作を行います。

    1. シリアルポートの出力を表示して、VM の初期化プロセスをモニタリングします。

      gcloud compute instances tail-serial-port-output NAME
      

      NAME は VM インスタンスの名前に置き換えます。

      Instance setup finished という出力が表示されるまで 3 分ほど待ちます。表示されたら Ctrl+C キーを押します。この時点で、VM インスタンスが使用できるようになります。

    2. VM インスタンスにユーザー名とパスワードを作成します。

    3. リモート デスクトップを使用して VM に接続し、前のステップで作成したユーザー名とパスワードを使用してログインします。

    4. [スタート] ボタンを右クリックするか Win + X を押して、[Windows PowerShell(管理者)] をクリックします。

    1. 特権昇格を確認するプロンプトが表示されたら [はい] をクリックします。
    2. コンピュータを Active Directory ドメインに追加して再起動します。

      Add-Computer -Domain DOMAIN -Restart
      

      DOMAIN は、Active Directory ドメインの DNS 名に置き換えます。

    3. VM をドメインに参加させるために必要な権限を持つアカウントの認証情報を入力します。再起動が完了するまで 1 分ほど待ちます。