본문 바로가기
Azure :: 애저 지식/02 Azure :: 애저 기초 지식

02 윈도우서버를 에저에 마이그레이션 (VHD 업로드) :: Migrate On-Premises VHD files to Azure

by Jasie 2020. 7. 29.

 

원초적인 방법으로 마이그레이션을 해보려 한다

제시하는 방법은 다음과 같다 HyperV의 Window Server를 VHD로 변환시켜 에저로 마이그레이션 하는 것이다

 

 

VHD파일 마이그레이션 흐름도

 

현재 제시하는 마이그레이션 방법은 애저 또는 AWS에 윈도우 서버를 업로드하기 전 일반화되어있는 VHD파일이 있어야 한다

 

 

1. window-PowerShell을 이용해 WindowServer VHDX파일을 VHD 파일로 변환하고 동시에 동적 디스크를 정적 디스크로 변환한다

  - Convert-VHD -Path <VHDX위치> -DestinationPath <VHD저장할위치> -VHDType Fixed

 

더보기

   ex) Convert-VHD -Path 'C:\Users\Public\Documents\Hyper-V\Virtual hard disks\server.vhdx' -DestinationPath 'C:\Users\Public\Documents\Hyper-V\Virtual hard disks\server.vhd' -VHDType Fixed

 

2. 고정크기 디스크 VHD가 생성된 것을 확인할 수 있다

 

 

3. Azure에 대해 Window 네트워크 구성을 설정한다

 

 

3-1. 라우팅 테이블에서 정적 영구 경로를 제거한다

 

route.exe delete

 

3-2. WinHTTP 프록시를 제거한다

 

netsh.exe winhttp reset proxy

 

3-3. VM이 특정 프록시를 사용 해야 하는 경우 VM이 Azure에 연결할 수 있도록 Azure IP 주소 (168.63.129.16)에 대 한 프록시 예외를 추가 한다

 

$proxyAddress='<your proxy server>'
$proxyBypassList='<your list of bypasses>;168.63.129.16'
netsh.exe winhttp set proxy $proxyAddress $proxyBypassList

 

3-4. 디스크 정책을 설정한다

 

diskpart.exe
san policy=onlineall
exit

 

3-5. window 시간을 w32time자동으로 설정한다

 

Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\TimeZoneInformation -Name RealTimeIsUniversal -Value 1 -Type DWord -Force
Set-Service -Name w32time -StartupType Automatic

 

3-6. 전원 프로필을 고성능으로 설정한다

 

powercfg.exe /setactive SCHEME_MIN

 

3-7. 환경 변수 TEMP와 TMP가 기본값인지 확인한다

 

Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -Name TEMP -Value "%SystemRoot%\TEMP" -Type ExpandString -Force 
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -Name TMP -Value "%SystemRoot%\TEMP" -Type ExpandString -Force

 

4. Window 서비스 확인을 한다

  - Window 서비스가 기본값으로 설정 되어 있는지 확인 한다, 이 작업은 VM연결을 보장하기 위해 구성해야하는 작업이다

 

Get-Service -Name BFE, Dhcp, Dnscache, IKEEXT, iphlpsvc, nsi, mpssvc, RemoteRegistry |
  Where-Object StartType -ne Automatic |
    Set-Service -StartupType Automatic

Get-Service -Name Netlogon, Netman, TermService |
  Where-Object StartType -ne Manual |
    Set-Service -StartupType Manual

 

5. 원격 데스크톱을 엑세스하기 위해 레지스트리 설정을 업데이트 한다

 

 

 

5-1. RDP(원격 데스크톱 프로토콜) 활성화

 

Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server' -Name fDenyTSConnections -Value 0 -Type DWord -Force
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services' -Name fDenyTSConnections -Value 0 -Type DWord -Force

 

5-2. 기본 포트 3389를 이용, RDP 포트 설정

 

Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\Winstations\RDP-Tcp' -Name PortNumber -Value 3389 -Type DWord -Force

 

5-3. 수신기가 모든 네트워크 인터페이스에서 수신 대기

 

Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\Winstations\RDP-Tcp' -Name LanAdapter -Value 0 -Type DWord -Force

 

5-4. RDP 연결에 대해 NLA (네트워크 수준 인증) 모드 구성

 

Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name UserAuthentication -Value 1 -Type DWord -Force
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name SecurityLayer -Value 1 -Type DWord -Force
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name fAllowSecProtocolNegotiation -Value 1 -Type DWord -Force

 

5-5. 연결 유지 값을 설정

 

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services' -Name KeepAliveEnable -Value 1  -Type DWord -Force
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services' -Name KeepAliveInterval -Value 1  -Type DWord -Force
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\Winstations\RDP-Tcp' -Name KeepAliveTimeout -Value 1 -Type DWord -Force

 

5-6. 연결 옵션 재설정

 

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services' -Name fDisableAutoReconnect -Value 0 -Type DWord -Force
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\Winstations\RDP-Tcp' -Name fInheritReconnectSame -Value 1 -Type DWord -Force
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\Winstations\RDP-Tcp' -Name fReconnectSame -Value 0 -Type DWord -Force

 

5-7. 동시 연결 수 제한

 

Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\Winstations\RDP-Tcp' -Name MaxInstanceCount -Value 4294967295 -Type DWord -Force

 

5-8. RDP 수신기에 연결 된 자체 서명 된 인증서를 모두 제거

 

if ((Get-Item -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp').Property -contains 'SSLCertificateSHA1Hash')
{
    Remove-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name SSLCertificateSHA1Hash -Force
}

 

6. Windows 방화벽 규칙 구성

 

!!중요 6-1 ~ 6.5까지는 영어버전의 window를 기준으로 작성되었으므로, firewall.cpl 를 이용해 'window defender 방화벽'을 켠후 한글로 명령어를 바꿔준다

예시) 6-2에 'Windows Remote Management (HTTP-In)''Windows 원격 관리(HTTP-In)'로 바꿔주면 된다

 

6-1. 세 가지 프로필 (도메인, 표준 및 공용)에서 Windows 방화벽을 설정

 

Set-NetFirewallProfile -Profile Domain, Public, Private -Enabled True

 

6-2. 다음 예제를 실행 하 여 세 개의 방화벽 프로필 (도메인, 개인 및 공용)을 통한 WinRM을 허용 하 고 PowerShell 원격 서비스를 사용 하도록 설정

 

Enable-PSRemoting -Force
Set-NetFirewallRule -DisplayName 'Windows Remote Management (HTTP-In)' -Enabled True

#or

Set-NetFirewallRule -DisplayName 'Windows 원격 관리(HTTP-In)' -Enabled True

 

6-3. 다음 방화벽 규칙을 사용하도록 설정하여 RDP 트래픽을 허용

 

Set-NetFirewallRule -DisplayGroup 'Remote Desktop' -Enabled True

#or

Set-NetFirewallRule -DisplayName '원격 데스크톱 - 사용자 모드(TCP-In)' -Enabled True

 

6-4. VM이 가상 네트워크 내의 ping 요청에 응답할 수 있도록 파일 및 프린터 공유에 대 한 규칙을 사용 하도록 설정

 

Set-NetFirewallRule -DisplayName 'File and Printer Sharing (Echo Request - ICMPv4-In)' -Enabled True

#or

Set-NetFirewallRule -DisplayName '파일 및 프린터 공유(에코 요청 - ICMPv4-In)' -Enabled True

 

6-5. Azure platform network에 대 한 규칙을 만든다

 

New-NetFirewallRule -DisplayName AzurePlatform -Direction Inbound -RemoteAddress 168.63.129.16 -Profile Any -Action Allow -EdgeTraversalPolicy Allow
New-NetFirewallRule -DisplayName AzurePlatform -Direction Outbound -RemoteAddress 168.63.129.16 -Profile Any -Action Allow

 

 

7. VM을 확인한다

  - VM이 정상인지, 보안과 RDP를 액세스할 수 있는지 확인 한다

 

7-1. 재부팅될때 디스크가 정상 상태고 일관되는지 확인한다

 

chkdsk.exe /f

 

7-2. BCD(부팅 구성 데이터) 설정을 지정한다

 

bcdedit.exe /set "{bootmgr}" integrityservices enable
bcdedit.exe /set "{default}" device partition=C:
bcdedit.exe /set "{default}" integrityservices enable
bcdedit.exe /set "{default}" recoveryenabled Off
bcdedit.exe /set "{default}" osdevice partition=C:
bcdedit.exe /set "{default}" bootstatuspolicy IgnoreAllFailures

#Enable Serial Console Feature
bcdedit.exe /set "{bootmgr}" displaybootmenu yes
bcdedit.exe /set "{bootmgr}" timeout 5
bcdedit.exe /set "{bootmgr}" bootems yes
bcdedit.exe /ems "{current}" ON
bcdedit.exe /emssettings EMSPORT:1 EMSBAUDRATE:115200

 

7-3. 덤프 로그는 Windows 크래시 문제를 해결 하는 데 도움이 되므로 덤프 로그 수집을 사용 하도록 설정 한다

 

# Set up the guest OS to collect a kernel dump on an OS crash event
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl' -Name CrashDumpEnabled -Type DWord -Force -Value 2
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl' -Name DumpFile -Type ExpandString -Force -Value "%SystemRoot%\MEMORY.DMP"
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl' -Name NMICrashDump -Type DWord -Force -Value 1

# Set up the guest OS to collect user mode dumps on a service crash event
$key = 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps'
if ((Test-Path -Path $key) -eq $false) {(New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting' -Name LocalDumps)}
New-ItemProperty -Path $key -Name DumpFolder -Type ExpandString -Force -Value 'C:\CrashDumps'
New-ItemProperty -Path $key -Name CrashCount -Type DWord -Force -Value 10
New-ItemProperty -Path $key -Name DumpType -Type DWord -Force -Value 2
Set-Service -Name WerSvc -StartupType Manual

 

7-4. WMI(Windows Management Instrumentation) (WMI) 리포지토리가 일치 하는지 확인 한다.

 

winmgmt.exe /verifyrepository

 

7-5. 3389 포트는 Azure의 RDP 서비스를 위해 다른 응용 프로그램에서 포트 3389을 사용하는지를 확인 한다.

 

netstat.exe -anob

 

8. WindowServer VHDX파일을 일반화한다

  - 일반화 이유 : 각 벤더사(Intel,AMD)의 CPU나 드라이브 정보가 다르기때문에 이를 모두 없애 클라우드상에 마이그레이션 되었을 때 충돌이 없도록하기 위해서 이다

  - CMD를 켜고 %windir%\system32\sysprep로 디렉터리를 변경
  - sysprep.exe를 실행
  - 일반화 클릭 후 시스템 종료 (클라우드상에 마이그레이션 할 때 혹여나하는 충돌되는 오류를 위해 일반화 한다)

 

 

 

 

9. window에서 할 수 있는 모든 조치를 취했으니, 로컬 컴퓨터에 에저를 연결하여 VHD파일을 업로드해준다

  -Power Shell에서 애저로 로그인하는 방법은 아래 명령어는 다음과 같다

 

 

9-1. Azure에 빈 관리형 디스크를 만든다 링크

  - Local 컴퓨터에 Azure를 연결 해준다

  - VHD를 업로드할려면 최소 VHD 크기의 빈 HDD를 만들어야한다

  - 리전위치, 리소스그룹, 관리디스크이름을 지정해준다

 

 

#Azure를 Local에 연결하기위해 모듈을 설치해준다
Install-Module -Name Az -AllowClobber -Scope CurrentUser
Connect-AzAccount
Install-Module -Name Az -AllowClobber -Force
set-executionpolicy unrestricted 

#Azure에 연결한다
Connect-AzAccount

# vhd파일위치를 입력해준다
$vhdSizeBytes = (Get-Item "<fullFilePathHere>").length 

#리전위치를 지정해준다
$diskconfig = New-AzDiskConfig -SkuName 'Standard_LRS' -OsType 'Windows' -UploadSizeInBytes $vhdSizeBytes -Location '<yourregion>' -CreateOption 'Upload'

#리소스 그룹이름, 관리디스크이름 입력
New-AzDisk -ResourceGroupName '<yourresourcegroupname>' -DiskName '<yourdiskname>' -Disk $diskconfig

 

9-2. 빈 관리 디스크를 만들었으므로 이제 VHD를 업로드할 수 있다. 디스크에 VHD를 업로드 하려면 업로드할 대상으로 참조할 수 있도록 쓰기 가능한 SAS가 필요 하다

 

$diskSas = Grant-AzDiskAccess -ResourceGroupName '<yourresourcegroupname>' -DiskName '<yourdiskname>' -DurationInSecond 86400 -Access 'Write'

$disk = Get-AzDisk -ResourceGroupName '<yourresourcegroupname>' -DiskName '<yourdiskname>'

 

10. 생성된 관리디스크에 VHD파일 업로드

  - 빈 관리 디스크(SAS)가 준비 되었으므로 VHD를 AzCopy v10를 사용 하 여 생성 한 SAS URI를 지정 하 여 로컬 VHD 파일을 관리 되는 디스크에 업로드한다

 

AzCopy.exe 다운로드

 

AzCopy.exe copy "<vhd 파일위치>" $diskSas.AccessSAS --blob-type PageBlob

 

10-1. 업로드가 완료되면 SAS 디스크가 필요 없어서 SAS를 해지해준다

 

Revoke-AzDiskAccess -ResourceGroupName '<yourresourcegroupname>' -DiskName '<yourdiskname>'

 

11. 디스크에 업로드된 VHD를 가져온다

 

$disk = Get-AzDisk -ResourceGroupName 'myResourceGroup' -DiskName 'myDiskName'

 

12. 관리형 디스크를 가지고 VM 이미지 생성

 

#일반화된 OS 관리형 디스크에서 관리형 이미지를 만든다. 다음 값을 사용자 고유의 정보로 바꾼다.

$location = 'East US'
$imageName = 'myImage'
$rgName = 'myResourceGroup'

#관리형 디스크를 사용하여 이미지를 만든다.

$imageConfig = New-AzImageConfig `
   -Location $location
$imageConfig = Set-AzImageOsDisk `
   -Image $imageConfig `
   -OsState Generalized `
   -OsType Windows `
   -ManagedDiskId $disk.Id
   
   # 이미지를 만든다
   
   $image = New-AzImage `
   -ImageName $imageName `
   -ResourceGroupName $rgName `
   -Image $imageConfig

 

13. VM 생성

  - 이미지가 생겼으니 이미지를 이용해 새 VM을 만든다

 

New-AzVm `
    -ResourceGroupName $rgName `
    -Name "myVM" `
    -Image $image.Id `
    -Location $location `
    -VirtualNetworkName "myVnet" `
    -SubnetName "mySubnet" `
    -SecurityGroupName "myNSG" `
    -PublicIpAddressName "myPIP" `
    -OpenPorts 3389

 

 

 

 

 

 

 

댓글