來賓 Virtual 網路叢集化Guest Clustering in a Virtual Network

適用於:Windows Server(以每年次管道)、Windows Server 2016Applies To: Windows Server (Semi-Annual Channel), Windows Server 2016

只允許虛擬電腦連接到 virtual 網路使用 Network Controller 已指派為了通訊網路的 IP 位址。Virtual machines that are connected to a virtual network are only permitted to use the IP addresses that Network Controller has assigned in order to communicate on the network. 這表示叢集技術,需要浮動的 IP 位址,例如 Microsoft 容錯、 需要一些額外的步驟,就可以正確運作。This means clustering technologies that require a floating IP address, such as Microsoft Failover Clustering, require some extra steps in order to function correctly.

讓浮動 IP 可供連接的方法是使用軟體負載平衡器 (SLB) virtual IP (VIP)。The method for making the floating IP reachable is to use a Software Load Balancer (SLB) virtual IP (VIP). 軟體負載平衡器必須使 SLB 會直接傳輸到目前擁有該 IP 電腦健康探查的連接埠該 IP 上的設定。The software load balancer must be configured with a health probe on a port on that IP so that SLB will direct traffic to the machine that currently has that IP.

範例: 負載平衡器設定Example: Load balancer configuration

假設,您已經建立 Vm 將會變成叢集節點,其附加到 Virtual 網路。This example assumes that you've already created the VMs which will become cluster nodes, and attached them to a Virtual Network. 如需指引,請參考建立 VM 和連接到承租人 Virtual 網路或 VLANFor guidance, refer to Create a VM and Connect to a Tenant Virtual Network or VLAN.

在此範例中,您將建立代表叢集,浮動 IP 位址 virtual IP 位址 (192.168.2.100),並設定健康探查監視 59999 以判斷哪一個節點為作用中的 TCP 連接埠。In this example you will create a virtual IP address (192.168.2.100) to represent the floating IP address of the cluster, and configure a health probe to monitor TCP port 59999 to determine which node is the active one.

步驟 1: 選取 VIPStep 1: Select the VIP

準備指派 VIP IP 位址。Prepare by assigning a VIP IP address. 此地址可以是任何未使用或保留地址叢集節點相同的子網路中。This address can be any unused or reserved address in the same subnet as the cluster nodes. VIP 必須符合叢集浮動地址。The VIP must match the floating address of the cluster.

$VIP = "192.168.2.100"
$subnet = "Subnet2"
$VirtualNetwork = "MyNetwork"
$ResourceId = "MyNetwork_InternalVIP"

步驟 2: 建立負載平衡器屬性物件Step 2: Create the load balancer properties object

您可以使用下列命令範例建立負載平衡器屬性物件。You can use the following example command to create the load balancer properties object.

$LoadBalancerProperties = new-object Microsoft.Windows.NetworkController.LoadBalancerProperties

步驟 3: 建立 front\ 端的 IP 位址Step 3: Create a front-end IP address

您可以使用下列命令的範例,建立一個 front\ 端的 IP 位址。You can use the following example command to create a front-end IP address.

$LoadBalancerProperties.frontendipconfigurations += $FrontEnd = new-object Microsoft.Windows.NetworkController.LoadBalancerFrontendIpConfiguration
$FrontEnd.properties = new-object Microsoft.Windows.NetworkController.LoadBalancerFrontendIpConfigurationProperties
$FrontEnd.resourceId = "Frontend1"
$FrontEnd.resourceRef = "/loadBalancers/$ResourceId/frontendIPConfigurations/$($FrontEnd.resourceId)"
$FrontEnd.properties.subnet = new-object Microsoft.Windows.NetworkController.Subnet
$FrontEnd.properties.subnet.ResourceRef = "/VirtualNetworks/MyNetwork/Subnets/Subnet2"
$FrontEnd.properties.privateIPAddress = $VIP
$FrontEnd.properties.privateIPAllocationMethod = "Static"

步驟 4: 建立集區 back\ 端包含叢集節點Step 4: Create a back-end pool to contain the cluster nodes

您可以使用下列範例命令來建立集區 back\ 端You can use the following example command to create a back-end pool

$BackEnd = new-object Microsoft.Windows.NetworkController.LoadBalancerBackendAddressPool
$BackEnd.properties = new-object Microsoft.Windows.NetworkController.LoadBalancerBackendAddressPoolProperties
$BackEnd.resourceId = "Backend1"
$BackEnd.resourceRef = "/loadBalancers/$ResourceId/backendAddressPools/$($BackEnd.resourceId)"
$LoadBalancerProperties.backendAddressPools += $BackEnd

步驟 5: 新增探查Step 5: Add a probe

探查才能偵測浮動的地址是在目前的叢集節點。The probe is necessary to detect which cluster node the floating address is currently active on.

注意

在下方的連接埠 VM 的永久位址探查查詢。The probe query against the VM's permanent address at the port defined below. 連接埠必須只回應主動節點上。The port must only respond on the active node.

$LoadBalancerProperties.probes += $lbprobe = new-object Microsoft.Windows.NetworkController.LoadBalancerProbe
$lbprobe.properties = new-object Microsoft.Windows.NetworkController.LoadBalancerProbeProperties

$lbprobe.ResourceId = "Probe1"
$lbprobe.resourceRef = "/loadBalancers/$ResourceId/Probes/$($lbprobe.resourceId)"
$lbprobe.properties.protocol = "TCP"
$lbprobe.properties.port = "59999"
$lbprobe.properties.IntervalInSeconds = 5
$lbprobe.properties.NumberOfProbes = 11

步驟 5: 新增負載平衡規則Step 5: Add the load balancing rules

這個步驟建立負載平衡 1433年的 TCP 連接埠規則。This step creates a load balancing rule for TCP port 1433. 您可以修改通訊協定,並視需要連接埠。You can modify the protocol and port as needed. 您可以也重複此步驟多次額外的連接埠和 protcols 此 VIP 上。You can also repeat this step multiple times for additional ports and protcols on this VIP. 請務必 EnableFloatingIP 設為 $true,因為這會告訴負載平衡器與原始 VIP 就地節點傳送封包。It is important that EnableFloatingIP is set to $true because this tells the load balancer to send the packet to the node with the original VIP in place.

$LoadBalancerProperties.loadbalancingRules += $lbrule = new-object Microsoft.Windows.NetworkController.LoadBalancingRule
$lbrule.properties = new-object Microsoft.Windows.NetworkController.LoadBalancingRuleProperties
$lbrule.ResourceId = "Rules1"

$lbrule.properties.frontendipconfigurations += $FrontEnd
$lbrule.properties.backendaddresspool = $BackEnd 
$lbrule.properties.protocol = "TCP"
$lbrule.properties.frontendPort = $lbrule.properties.backendPort = 1433 
$lbrule.properties.IdleTimeoutInMinutes = 4
$lbrule.properties.EnableFloatingIP = $true
$lbrule.properties.Probe = $lbprobe

步驟 5: 建立網路控制器負載平衡器Step 5: Create the load balancer in Network Controller

若要建立負載平衡器,您可以使用下列命令範例。You can use the following example command to create the load balancer.

$lb = New-NetworkControllerLoadBalancer -ConnectionUri $URI -ResourceId $ResourceId -Properties $LoadBalancerProperties -Force

步驟 6: 端集區中新增叢集節點Step 6: Add the cluster nodes to the backend pool

新增兩個集區的成員,會顯示此範例中,但您也可以新增多個節點集區視需要叢集。This example shows adding two pool members, but you can add as many nodes to the pool as you require for the cluster.

# Cluster Node 1

$nic = get-networkcontrollernetworkinterface  -connectionuri $uri -resourceid "ClusterNode1_Network-Adapter"
$nic.properties.IpConfigurations[0].properties.LoadBalancerBackendAddressPools += $lb.properties.backendaddresspools[0]
$nic = new-networkcontrollernetworkinterface  -connectionuri $uri -resourceid $nic.resourceid -properties $nic.properties -force

# Cluster Node 2

$nic = get-networkcontrollernetworkinterface  -connectionuri $uri -resourceid "ClusterNode2_Network-Adapter"
$nic.properties.IpConfigurations[0].properties.LoadBalancerBackendAddressPools += $lb.properties.backendaddresspools[0]
$nic = new-networkcontrollernetworkinterface  -connectionuri $uri -resourceid $nic.resourceid -properties $nic.properties -force

建立負載平衡器並端集區中新增的網路介面之後,您就可以設定叢集。Once you've created the load balancer and added the network interfaces to the backend pool, you are ready to configure the cluster. 如果您使用 Microsoft 容錯移轉叢集您可以繼續的下一個範例。If you are using a Microsoft Failover Cluster you can continue with the next example.

範例 2: 設定 Microsoft 容錯移轉叢集Example 2: Configuring a Microsoft Failover Cluster

您可以使用下列步驟來設定容錯移轉叢集。You can use the following steps to configure a failover cluster.

步驟 1: 安裝容錯Step 1: Install failover clustering

您可以使用下列命令範例安裝和設定容錯移轉叢集屬性。You can use the following example commands to install and configure properties for a failover cluster.

add-windowsfeature failover-clustering -IncludeManagementTools
Import-module failoverclusters

$ClusterName = "MyCluster"

$ClusterNetworkName = "Cluster Network 1"
$IPResourceName =  
$ILBIP = “192.168.2.100” 

$nodes = @("DB1", "DB2")

步驟 2: 建立一個節點叢集Step 2: Create the cluster on one node

您可以使用下列命令範例節點上建立叢集。You can use the following example command to create the cluster on a node.

New-Cluster -Name $ClusterName -NoStorage -Node $nodes[0]

步驟 3: 停止叢集資源Step 3: Stop the cluster resource

若要停止叢集資源,您可以使用下列命令範例。You can use the following example command to stop the cluster resource.

Stop-ClusterResource "Cluster Name" 

步驟 4: 設定叢集 IP 和探查連接埠Step 4: Set the cluster IP and probe port

IP 位址必須符合先前的範例中, 使用的前端 ip 位址和探查連接埠必須符合的探查連接埠,在上一個範例。The IP address must match the front-end ip address used in the previous example, and the probe port must match the probe port in the previous example.

Get-ClusterResource "Cluster IP Address" | Set-ClusterParameter -Multiple @{"Address"="$ILBIP";"ProbePort"="59999";"SubnetMask"="255.255.255.255";"Network"="$ClusterNetworkName";"EnableDhcp"=0}

步驟 5: 開始叢集資源Step 5: Start the cluster resources

您可以使用下列命令範例開始叢集資源。You can use the following example command to start the cluster resources.

Start-ClusterResource "Cluster IP Address"  -Wait 60 
Start-ClusterResource "Cluster Name"  -Wait 60 

步驟 6: 新增剩餘節點Step 6: Add the remaining nodes

您可以使用下列命令範例新增叢集節點。You can use the following example command to add cluster nodes.

Add-ClusterNode $nodes[1]

完成的最後一個步驟,您叢集為作用中。Upon completion of the last step, your cluster is active. 將在主動節點導向流量 vip 指定連接埠。Traffic going to the VIP on the specified port will be directed at the active node.