튜토리얼: Azure PowerShell을 사용해 트래픽 관리자 링크드 레코드 생성하기

이 튜토리얼에서는 Azure PowerShell을 사용해 Azure DNS에서 트래픽 관리자 연결 레코드를 생성합니다. 트래픽 매니저 링크드 레코드는 DNS 레코드 세트를 Azure Traffic Manager 프로필에 직접 연결하여 중간 CNAME 해석이 없는 클라이언트에게 IP 주소를 반환합니다.

포털 기반 워크스루는 Azure 포털을 이용한 트래픽 관리자 링크 레코드 생성(Create a Traffic Manager Linked Record)을 참조하세요. 개념적 개요는 트래픽 관리자 연동 기록 개요를 참조하세요.

이 튜토리얼에서는 다음을 배우게 됩니다:

  • 네트워킹과 가상 머신 인프라를 구축하세요.
  • 엔드포인트가 포함된 트래픽 매니저 프로필을 만드세요.
  • Azure PowerShell을 사용해 트래픽 관리자 링크드 레코드를 생성하세요.
  • 트래픽 매니저 링크드 레코드를 테스트하세요.

Azure 구독이 없는 경우, 시작하기 전에 무료 계정을 만드십시오.

Prerequisites

  • 활성 구독이 있는 Azure 계정.
  • Azure PowerShell 12.0.0 또는 그 이상 버전을 로컬 설치하거나 Azure Cloud Shell를 사용하세요. Get-Module -ListAvailable Az을 실행하여 버전을 확인합니다. 설치 또는 업그레이드하려면 Azure PowerShell 설치를 참조하세요.
  • Azure DNS 호스트되는 도메인 이름입니다. Azure DNS 존이 없다면, 하나를 만들고 도메인을 Azure DNS에 위임하세요.

메모

이 자습서에서는 contoso.com이 도메인 이름 예로 사용됩니다. contoso.com을 사용자 고유의 도메인 이름으로 바꿉니다.

메모

Azure Az PowerShell 모듈을 사용하여 Azure와 상호 작용하는 것이 좋습니다. 시작하려면 Azure PowerShell 설치를 참조하세요. Az PowerShell 모듈로 마이그레이션하는 방법을 알아보려면 Azure PowerShell을 AzureRM에서 Az로 마이그레이션을 참조하세요.

Azure Cloud Shell

Azure는 브라우저를 통해 사용할 수 있는 대화형 셸 환경인 Azure Cloud Shell을 호스트합니다. Cloud Shell에서 Bash 또는 PowerShell을 사용하여 Azure 서비스 작업을 수행할 수 있습니다. Cloud Shell 미리 설치된 명령을 사용하여 로컬 환경에 아무것도 설치하지 않고도 이 문서의 코드를 실행할 수 있습니다.

Azure Cloud Shell 시작하려면:

옵션 예제/링크
코드 또는 명령 블록의 오른쪽 상단에서 시도를 선택합니다. Try It을 선택해도 코드나 명령이 자동으로 Cloud Shell에 복사되지 않습니다. Azure Cloud Shell의
https://shell.azure.com으로 이동하거나 Cloud Shell 시작 단추를 선택하여 브라우저에서 Cloud Shell을 엽니다. Azure Cloud Shell을 실행하는 버튼입니다.
Azure Portal의 오른쪽 위에 있는 메뉴 모음에서 Cloud Shell 단추를 선택합니다. Azure Portal의 Cloud Shell 단추를 보여 주는 스크린샷

Azure Cloud Shell을 사용하려면:

  1. Cloud Shell을 시작합니다.

  2. 코드 블록(또는 명령 블록)에서 복사 단추를 선택하여 코드 또는 명령을 복사합니다.

  3. Windows 및 Linux에서 Ctrl+Shift+V 선택하거나 macOS에서 Cmd+Shift+V 선택하여 코드 또는 명령을 Cloud Shell 세션에 붙여넣습니다.

  4. Enter를 선택하여 코드 또는 명령을 실행합니다.

변수 설정

이 튜토리얼 전반에 걸쳐 사용되는 자원 이름과 위치에 대한 변수를 정의하세요.

$ResourceGroup = "test-rg"
$Location = "eastus"
$VNetName = "vnet-1"
$TmProfileName = "tm-profile"
$DnsZone = "contoso.com"
$DnsZoneResourceGroup = "<dns-zone-resource-group>"

메모

기존 Azure DNS 존이 포함된 리소스 그룹으로 교체하세요<dns-zone-resource-group>.

리소스 그룹 만들기

New-AzResourceGroup -Name $ResourceGroup -Location $Location

가상 네트워크 만들기

$subnet = @{
    Name          = "subnet-1"
    AddressPrefix = "10.10.0.0/24"
}
$SubnetConfig = New-AzVirtualNetworkSubnetConfig @subnet

$vnet = @{
    ResourceGroupName = $ResourceGroup
    Name              = $VNetName
    Location          = $Location
    AddressPrefix     = "10.10.0.0/16"
    Subnet            = $SubnetConfig
}
New-AzVirtualNetwork @vnet

웹 서버 가상 머신 만들기

공인 IP 주소 생성

$pip1 = @{
    ResourceGroupName = $ResourceGroup
    Name              = "public-ip-1"
    Location          = $Location
    Sku               = "Standard"
    AllocationMethod  = "Static"
    DomainNameLabel   = "vm-1-tmlink"
}
$Vm1Pip = New-AzPublicIpAddress @pip1

$pip2 = @{
    ResourceGroupName = $ResourceGroup
    Name              = "public-ip-2"
    Location          = $Location
    Sku               = "Standard"
    AllocationMethod  = "Static"
    DomainNameLabel   = "vm-2-tmlink"
}
$Vm2Pip = New-AzPublicIpAddress @pip2

네트워크 보안 그룹 만들기

$httpRule = @{
    Name                     = "AllowHTTP"
    Protocol                 = "Tcp"
    Direction                = "Inbound"
    Priority                 = 100
    SourceAddressPrefix      = "*"
    SourcePortRange          = "*"
    DestinationAddressPrefix = "*"
    DestinationPortRange     = 80
    Access                   = "Allow"
}
$HttpRule = New-AzNetworkSecurityRuleConfig @httpRule

$httpsRule = @{
    Name                     = "AllowHTTPS"
    Protocol                 = "Tcp"
    Direction                = "Inbound"
    Priority                 = 110
    SourceAddressPrefix      = "*"
    SourcePortRange          = "*"
    DestinationAddressPrefix = "*"
    DestinationPortRange     = 443
    Access                   = "Allow"
}
$HttpsRule = New-AzNetworkSecurityRuleConfig @httpsRule

$nsg = @{
    ResourceGroupName = $ResourceGroup
    Location          = $Location
    Name              = "nsg-1"
    SecurityRules     = $HttpRule, $HttpsRule
}
$Nsg = New-AzNetworkSecurityGroup @nsg

네트워크 인터페이스와 가상 머신을 생성하세요

$VNet = Get-AzVirtualNetwork -ResourceGroupName $ResourceGroup -Name $VNetName
$Subnet = Get-AzVirtualNetworkSubnetConfig -VirtualNetwork $VNet -Name "subnet-1"

$nic1 = @{
    ResourceGroupName      = $ResourceGroup
    Name                   = "nic-1"
    Location               = $Location
    SubnetId               = $Subnet.Id
    PublicIpAddressId      = $Vm1Pip.Id
    NetworkSecurityGroupId = $Nsg.Id
}
$Vm1Nic = New-AzNetworkInterface @nic1

$nic2 = @{
    ResourceGroupName      = $ResourceGroup
    Name                   = "nic-2"
    Location               = $Location
    SubnetId               = $Subnet.Id
    PublicIpAddressId      = $Vm2Pip.Id
    NetworkSecurityGroupId = $Nsg.Id
}
$Vm2Nic = New-AzNetworkInterface @nic2

가상 머신 구성을 만들고 VM을 배포하세요. 안내 문구가 나오면 관리자 계정의 비밀번호를 입력하세요.

$Credential = Get-Credential -Message "Enter a username and password for the VMs"

$image = @{
    PublisherName = "Canonical"
    Offer         = "ubuntu-24_04-lts"
    Skus          = "server"
    Version       = "latest"
}

$Vm1Config = New-AzVMConfig -VMName "vm-1" -VMSize "Standard_B1s" |
    Set-AzVMOperatingSystem -Linux -ComputerName "vm-1" -Credential $Credential |
    Set-AzVMSourceImage @image |
    Add-AzVMNetworkInterface -Id $Vm1Nic.Id

New-AzVM -ResourceGroupName $ResourceGroup -Location $Location -VM $Vm1Config -AsJob

$Vm2Config = New-AzVMConfig -VMName "vm-2" -VMSize "Standard_B1s" |
    Set-AzVMOperatingSystem -Linux -ComputerName "vm-2" -Credential $Credential |
    Set-AzVMSourceImage @image |
    Add-AzVMNetworkInterface -Id $Vm2Nic.Id

New-AzVM -ResourceGroupName $ResourceGroup -Location $Location -VM $Vm2Config

가상 머신에 NGINX를 설치하세요

$run1 = @{
    ResourceGroupName = $ResourceGroup
    VMName            = "vm-1"
    CommandId         = "RunShellScript"
    ScriptString      = "sudo apt-get update && sudo apt-get install -y nginx && echo 'Hello World from vm-1' | sudo tee /var/www/html/index.html"
}
Invoke-AzVMRunCommand @run1

$run2 = @{
    ResourceGroupName = $ResourceGroup
    VMName            = "vm-2"
    CommandId         = "RunShellScript"
    ScriptString      = "sudo apt-get update && sudo apt-get install -y nginx && echo 'Hello World from vm-2' | sudo tee /var/www/html/index.html"
}
Invoke-AzVMRunCommand @run2

공인 IP 주소를 조회하세요

$Vm1IPAddress = (Get-AzPublicIpAddress -ResourceGroupName $ResourceGroup -Name "public-ip-1").IpAddress
$Vm2IPAddress = (Get-AzPublicIpAddress -ResourceGroupName $ResourceGroup -Name "public-ip-2").IpAddress

Write-Output "vm-1 IP: $Vm1IPAddress"
Write-Output "vm-2 IP: $Vm2IPAddress"

트래픽 매니저 프로필 생성

$tm = @{
    Name                 = $TmProfileName
    ResourceGroupName    = $ResourceGroup
    TrafficRoutingMethod = "Priority"
    RelativeDnsName      = "tm-profile-$(Get-Random)"
    Ttl                  = 30
    MonitorProtocol      = "HTTP"
    MonitorPort          = 80
    MonitorPath          = "/"
    RecordType           = "A"
}
$TmProfile = New-AzTrafficManagerProfile @tm

트래픽 관리자 프로필에 엔드포인트 추가

$ep1 = @{
    EndpointName          = "tmendpoint-1"
    TrafficManagerProfile = $TmProfile
    Type                  = "ExternalEndpoints"
    Target                = $Vm1IPAddress
    EndpointStatus        = "Enabled"
    Priority              = 1
}
Add-AzTrafficManagerEndpointConfig @ep1

$ep2 = @{
    EndpointName          = "tmendpoint-2"
    TrafficManagerProfile = $TmProfile
    Type                  = "ExternalEndpoints"
    Target                = $Vm2IPAddress
    EndpointStatus        = "Enabled"
    Priority              = 2
}
Add-AzTrafficManagerEndpointConfig @ep2

Set-AzTrafficManagerProfile -TrafficManagerProfile $TmProfile

트래픽 관리자 연결 레코드 생성

-TrafficManagementProfile 매개변수와 함께 New-AzDnsRecordSet를 사용하여 트래픽 관리자 연결 레코드를 생성하세요. 다음 명령어는 존 꼭짓점(@)에 A 레코드를 생성합니다.

메모

-TrafficManagementProfile 매개 변수는 Az.Dns 5.0.0 이후 버전에서 제공되며, Traffic Manager 연결 레코드를 지원하는 API 버전(2024-06-01-preview 이상)이 필요합니다.

$TmProfileId = $TmProfile.Id

$apex = @{
    ResourceGroupName        = $DnsZoneResourceGroup
    ZoneName                 = $DnsZone
    Name                     = "@"
    RecordType               = "A"
    Ttl                      = 30
    TrafficManagementProfile = $TmProfileId
}
New-AzDnsRecordSet @apex

영역 정점 대신 서브도메인 레코드를 생성하려면 서브도메인 이름으로 대체 "@" 하세요. 다음은 그 예입니다.

$www = @{
    ResourceGroupName        = $DnsZoneResourceGroup
    ZoneName                 = $DnsZone
    Name                     = "www"
    RecordType               = "A"
    Ttl                      = 30
    TrafficManagementProfile = $TmProfileId
}
New-AzDnsRecordSet @www

링크된 기록을 확인하세요

$record = @{
    ResourceGroupName = $DnsZoneResourceGroup
    ZoneName          = $DnsZone
    Name              = "@"
    RecordType        = "A"
}
Get-AzDnsRecordSet @record

출력 TrafficManagementProfile 에는 Traffic Manager 프로필 리소스 ID를 보여주는 속성이 포함되어 있어 링크가 확립되었음을 확인합니다.

메모

레코드의 TTL 값은 트래픽 관리자 프로필 TTL을 반영합니다. 레코드 생성 시 지정된 TTL은 트래픽 매니저 프로필의 DNS TTL 값으로 대체됩니다.

트래픽 매니저 연결 레코드 테스트

DNS 존의 네임 서버를 불러와서 직접 쿼리하세요.

$ns = @{
    ResourceGroupName = $DnsZoneResourceGroup
    ZoneName          = $DnsZone
    Name              = "@"
    RecordType        = "NS"
}
$NameServer = (Get-AzDnsRecordSet @ns).Records[0].Nsdname

Resolve-DnsName -Name $DnsZone -Server $NameServer -Type A

응답에는 IP 주소가 포함된 A 레코드가 포함되어 있어, 트래픽 매니저 링크드 레코드가 CNAME 홉 없이 직접 IP 주소를 반환한다는 것을 확인시켜 줍니다.

테스트 장애 조치

  1. 도메인을 탐색하세요. vm-1에 대한 NGINX 페이지를 보실 거예요.

  2. vm-1 VM 중지:

    Stop-AzVM -ResourceGroupName $ResourceGroup -Name "vm-1" -Force
    
  3. 트래픽 매니저가 엔드포인트를 건강하지 않다고 감지할 때까지 몇 분간 기다리세요.

  4. 필요하면 로컬 DNS 캐시를 플러시한 뒤 다시 도메인으로 탐색하세요. 이제 vm-2 페이지를 보실 수 있을 겁니다.

  5. vm-1을 재시작하여 원래 구성을 복원하세요:

    Start-AzVM -ResourceGroupName $ResourceGroup -Name "vm-1"
    

자원을 정리하세요

더 이상 리소스가 필요 없을 때는 리소스 그룹과 DNS 레코드를 제거하세요:

# Delete the resource group and all resources within it
Remove-AzResourceGroup -Name $ResourceGroup -Force -AsJob

# Delete the Traffic Manager Linked Record from the DNS zone
$cleanup = @{
    ResourceGroupName = $DnsZoneResourceGroup
    ZoneName          = $DnsZone
    Name              = "@"
    RecordType        = "A"
}
Remove-AzDnsRecordSet @cleanup

다음 단계

이 튜토리얼에서는 Azure PowerShell을 사용해 트래픽 관리자 링크드 레코드를 만들었습니다. 이 기록은 DNS 존을 트래픽 매니저 프로필에 연결하여 IP 주소를 직접 클라이언트에게 반환합니다.