■ 가상 머신의 가상 네트워크를 만드는 방법을 보여준다.
▶ 실행 명령
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
################################################## # 가상 머신의 관리자 계정에 필요한 사용자명과 패스워드를 설정한다. ################################################## $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 |