■ 가상 머신의 부하 분산을 통해 고가용성 애플리케이션 만들기

------------------------------------------------------------------------------------------------------------------------

 

##################################################

# 리소스 그룹을 만든다.

##################################################

 

New-AzResourceGroup -ResourceGroupName TestResourceGroup -Location EastUS

 

##################################################

# 공용 IP 주소를 만든다.

##################################################

 

$publicIPAddress = New-AzPublicIpAddress `

  -ResourceGroupName TestResourceGroup `

  -Location EastUS `

  -AllocationMethod Static `

  -Name TestPublicIPAddress

 

##################################################

# 프런트 엔드 IP 구성을 만든다.

##################################################

 

$testFrontendIPConfig = New-AzLoadBalancerFrontendIpConfig -Name TestFrontendIPConfig `

    -PublicIpAddress $publicIPAddress

 

##################################################

# 백 엔드 주소 풀 구성을 만든다.

##################################################

 

$testBackendAddressPoolConfig = New-AzLoadBalancerBackendAddressPoolConfig -Name TestBackendAddressPoolConfig

 

##################################################

# 부하 분산 장치를 만든다.

##################################################

 

$loadBalancer = New-AzLoadBalancer `

  -ResourceGroupName TestResourceGroup `

  -Name TestLoadBalancer `

  -Location EastUS `

  -FrontendIpConfiguration $testFrontendIPConfig `

  -BackendAddressPool $testBackendAddressPoolConfig

 

##################################################

# 상태 프로브를 만든다.

##################################################

 

Add-AzLoadBalancerProbeConfig `

  -Name TestHealthProbe `

  -LoadBalancer $loadBalancer `

  -Protocol tcp `

  -Port 80 `

  -IntervalInSeconds 15 `

  -ProbeCount 2

 

Set-AzLoadBalancer -LoadBalancer $loadBalancer

 

##################################################

# 부하 분산 장치 규칙을 만든다.

##################################################

 

$probeConfig = Get-AzLoadBalancerProbeConfig -LoadBalancer $loadBalancer -Name TestHealthProbe

 

Add-AzLoadBalancerRuleConfig `

  -Name TestLoadBalancerRule `

  -LoadBalancer $loadBalancer `

  -FrontendIpConfiguration $loadBalancer.FrontendIpConfigurations[0] `

  -BackendAddressPool $loadBalancer.BackendAddressPools[0] `

  -Protocol Tcp `

  -FrontendPort 80 `

  -BackendPort 80 `

  -Probe $probeConfig

 

Set-AzLoadBalancer -LoadBalancer $loadBalancer

 

##################################################

# 서브넷 구성을 생성한다.

##################################################

 

$subnetConfig = New-AzVirtualNetworkSubnetConfig -Name TestSubnet -AddressPrefix 192.168.1.0/24

 

##################################################

# 가상 네트워크를 생성한다.

##################################################

 

$vnet = New-AzVirtualNetwork `

  -ResourceGroupName TestResourceGroup `

  -Location EastUS `

  -Name TestVNet `

  -AddressPrefix 192.168.0.0/16 `

  -Subnet $subnetConfig

 

##################################################

# 네트워크 인터페이스를 생성한다.

##################################################

 

for($i = 1; $i -le 3; $i++)

{

    New-AzNetworkInterface `

        -ResourceGroupName TestResourceGroup `

        -Name TestVM$i `

        -Location EastUS `

        -Subnet $vnet.Subnets[0] `

        -LoadBalancerBackendAddressPool $loadBalancer.BackendAddressPools[0]

}

 

##################################################

# 가용성 집합을 만든다.

##################################################

 

$availabilitySet = New-AzAvailabilitySet `

    -ResourceGroupName TestResourceGroup `

    -Name TestAvailabilitySet `

    -Location EastUS `

    -Sku aligned `

    -PlatformFaultDomainCount 2 `

    -PlatformUpdateDomainCount 2

 

##################################################

# 가상 머신의 관리자 계정명과 암호를 설정한다.

##################################################

 

$credential = Get-Credential

 

##################################################

# 가상 머신을 만든다.

##################################################

for($i = 1; $i -le 3; $i++)

{

    New-AzVm `

        -ResourceGroupName TestResourceGroup `

        -Name TestVM$i `

        -Location EastUS `

        -VirtualNetworkName TestVNet `

        -SubnetName TestSubnet `

        -SecurityGroupName TestNetworkSecurityGroup `

        -OpenPorts 80 `

        -AvailabilitySetName TestAvailabilitySet `

        -Credential $credential `

        -AsJob

}

 

##################################################

# 가상 머신에 IIS를 설치한다.

##################################################

 

for($i = 1; $i -le 3; $i++)

{

    Set-AzVMExtension `

        -ResourceGroupName TestResourceGroup `

        -ExtensionName IIS `

        -VMName TestVM$i `

        -Publisher Microsoft.Compute `

        -ExtensionType CustomScriptExtension `

        -TypeHandlerVersion 1.8 `

        -SettingString '{"commandToExecute":"powershell Add-WindowsFeature Web-Server;

             powershell Add-Content -Path \"C:\\inetpub\\wwwroot\\Default.htm\" -Value $($env:computername)"}' `

        -Location EastUS

}

 

##################################################

# 공인 IP 주소를 구한다.

##################################################

 

Get-AzPublicIPAddress -ResourceGroupName TestResourceGroup -Name TestPublicIPAddress | select IpAddress

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker

댓글을 달아 주세요