■ 가상 머신의 가상 네트워크 만들기

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

 

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

# 가상 머신의 관리자 계정에 필요한 사용자명과 패스워드를 설정한다.

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

 

$credential = Get-Credential

 

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

# 리소스 그룹을 생성한다.

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

 

New-AzResourceGroup -ResourceGroupName TestResourceGroup -Location EastUS

 

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

# 프론트엔드 서브넷을 생성한다.

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

 

$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name TestFrontendSubnet -AddressPrefix 10.0.0.0/24

 

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

# 백엔드 서브넷을 생성한다.

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

 

$backendSubnet = New-AzVirtualNetworkSubnetConfig -Name TestBackendSubnet -AddressPrefix 10.0.1.0/24

 

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

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

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

 

$vnet = New-AzVirtualNetwork `

    -ResourceGroupName TestResourceGroup `

    -Location EastUS `

    -Name TestVNet `

    -AddressPrefix 10.0.0.0/16 `

    -Subnet $frontendSubnet, $backendSubnet

 

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

# 공개 IP 주소를 생성한다.

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

 

$publicIPAddress = New-AzPublicIpAddress `

    -ResourceGroupName TestResourceGroup `

    -Location EastUS `

    -AllocationMethod Dynamic `

    -Name TestPublicIPAddress

 

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

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

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

 

New-AzNetworkInterface `

    -ResourceGroupName TestResourceGroup `

    -Location EastUS `

    -Name TestFrontendVM `

    -SubnetId $vnet.Subnets[0].Id `

    -PublicIpAddressId $publicIPAddress.Id

 

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

# 프론트엔드 가상 머신을 생성한다.

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

 

New-AzVM `

    -Credential $credential `

    -Name TestFrontendVM `

    -PublicIpAddressName TestPublicIPAddress `

    -ResourceGroupName TestResourceGroup `

    -Location EastUS `

    -Size Standard_D1 `

    -SubnetName TestFrontendSubnet `

    -VirtualNetworkName TestVNet

 

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

# 프론트엔드 네트워크 보안 그룹 규칙을 생성한다.

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

 

$frontendNSGRule = New-AzNetworkSecurityRuleConfig `

    -Name TestFrontendNSGRule `

    -Protocol Tcp `

    -Direction Inbound `

    -Priority 200 `

    -SourceAddressPrefix * `

    -SourcePortRange * `

    -DestinationAddressPrefix * `

    -DestinationPortRange 80 `

    -Access Allow

 

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

# 백엔드 네트워크 보안 그룹 규칙을 생성한다.

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

 

$backendNSGRule = New-AzNetworkSecurityRuleConfig `

    -Name TestBackendNSGRule `

    -Protocol Tcp `

    -Direction Inbound `

    -Priority 100 `

    -SourceAddressPrefix 10.0.0.0/24 `

    -SourcePortRange * `

    -DestinationAddressPrefix * `

    -DestinationPortRange 1433 `

    -Access Allow

 

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

# 프론트엔드 네트워크 보안 그룹을 생성한다.

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

 

$frontendNSG = New-AzNetworkSecurityGroup `

    -ResourceGroupName TestResourceGroup `

    -Location EastUS `

    -Name TestFrontendNSG `

    -SecurityRules $frontendNSGRule

 

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

# 백엔드 네트워크 보안 그룹을 생성한다.

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

 

$backendNSG = New-AzNetworkSecurityGroup `

    -ResourceGroupName TestResourceGroup `

    -Location EastUS `

    -Name TestBackendNSG `

    -SecurityRules $backendNSGRule

 

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

# 서브넷에 네트워크 보안 그룹을 추가한다.

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

 

$vnet = Get-AzVirtualNetwork -ResourceGroupName TestResourceGroup -Name TestVNet

 

$frontendSubnet = $vnet.Subnets[0]

$backendSubnet  = $vnet.Subnets[1]

 

Set-AzVirtualNetworkSubnetConfig `

    -VirtualNetwork $vnet `

    -Name TestFrontendSubnet `

    -AddressPrefix $frontendSubnet.AddressPrefix `

    -NetworkSecurityGroup $frontendNSG

 

Set-AzVirtualNetworkSubnetConfig `

    -VirtualNetwork $vnet `

    -Name TestBackendSubnet `

    -AddressPrefix $backendSubnet.AddressPrefix `

    -NetworkSecurityGroup $backendNSG

 

Set-AzVirtualNetwork -VirtualNetwork $vnet

 

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

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

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

 

New-AzNetworkInterface `

    -ResourceGroupName TestResourceGroup `

    -Location EastUS `

    -Name TestBackendVM `

    -SubnetId $vnet.Subnets[1].Id

 

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

# 백엔드 가상 머신을 생성한다.

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

 

New-AzVM `

    -Credential $credential `

    -Name TestBackendVM `

    -ImageName "MicrosoftSQLServer:SQL2016SP1-WS2016:Enterprise:latest" `

    -ResourceGroupName TestResourceGroup `

    -Location EastUS `

    -SubnetName TestBackendSubnet `

    -VirtualNetworkName TestVNet

 

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

Posted by 사용자 icodebroker

댓글을 달아 주세요