Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)

Azure 가상 머신에 Web Application을 배포하는 방법

Azure에서 Web Application을 운영하는 방법으로는 PaaS 유형으로 Cloud Services (classic), Web App (App Service)과 같은 서비스를 이용할 수 있습니다. 또는 IaaS 유형으로 가상 머신(VM)을 하나 생성해 운영하는 것도 가능합니다.

PaaS 유형의 경우 Azure Portal에서 배포를 위한 "profile" 파일을 구해 Visual Studio에서 프로젝트의 "배포" 메뉴로 바로 연결해 쉽게 응용 프로그램을 올릴 수 있습니다. 반면, IaaS 형식의 VM인 경우에는 응용 프로그램에 대한 전용 환경은 아니기 때문에 별도의 배포 프로파일이 제공되지 않으므로 약간 불편한 점이 있습니다.

물론, VM은 단일 PC와 동일하기 때문에 단순히 RDP 화면을 이용해 폴더를 복사하거나 FTP를 열어 배포하는 것도 가능합니다. 그 외에 좀 더 편리한 방식이 있다면 바로 "WebDeploy" 도구를 이용하는 것으로 이에 대해서는 다음의 문서에서 자세하게 설명하고 있습니다.

Publish an ASP.NET Web App to an Azure VM from Visual Studio
; https://learn.microsoft.com/en-us/azure/virtual-machines/windows/publish-web-app-from-visual-studio

간단하게 정리해 볼까요? ^^

우선, VM 쪽에 2가지 준비를 해줘야 합니다. 그 첫 번째로 "Web Deploy" 도구를 설치해야 합니다. 이상한 점이 있다면, 현재 3.6 버전으로 배포되는 "Web Deploy"가 아닌 아래의 글에서 설명하고 있는,

Installing and Configuring Web Deploy on IIS 8.0 or Later
; https://learn.microsoft.com/en-us/iis/install/installing-publishing-technologies/installing-and-configuring-web-deploy-on-iis-80-or-later

(IIS 관리자에도 제공되는) "Web Platform Installer"를 들어가 다음과 같이 "Recommended"로 검색해 "Recommended Server Configuration for Web Hosting Providers" 항목을 선택해 설치해야 합니다.

pub_webapp_to_azure_vm_0.png

설치가 정상적으로 되었으면 VM 측에 8172 번 포트가 열립니다.

C:\>netstat -ano | findstr 8172
  TCP    0.0.0.0:8172           0.0.0.0:0              LISTENING       4
  TCP    [::]:8172              [::]:0                 LISTENING       4

두 번째로 Azure Portal을 통해 해당 VM에 대한 DNS를 갖도록 설정해야 합니다. (별도 DNS를 구매할 필요는 없고 azure에서 기본 제공되는 DNS 설정을 하시면 됩니다.)

Create a fully qualified domain name in the Azure portal for a Windows VM
; https://learn.microsoft.com/en-us/azure/virtual-machines/windows/portal-create-fqdn

pub_webapp_to_azure_vm_1.png

그 외에, 만약 해당 VM에 Network Security Group이 설정되어 있다면 "Inbound security rules"에서 8172 포트를 열어야 합니다.

위와 같이 VM 측의 준비가 끝나면 이제 Visual Studio에서 배포할 수 있습니다. Visual Studio에서 웹 프로젝트를 우 클릭해 "Publish..." 메뉴를 선택해 다음과 같이 "Microsoft Azure Virtual Machines" 항목을 선택해 줍니다.

pub_webapp_to_azure_vm_2.png

그다음, "Settings..." 링크를 눌러 "웹 사이트" 정보와 계정 정보를 입력 후 "Validate Connection"을 눌러 검증합니다.

pub_webapp_to_azure_vm_3.png

이후 배포를 하면 최초 한 번은 다음과 같이 인증서 설치를 묻습니다.

pub_webapp_to_azure_vm_4.png

"Save this certificate for future sessions of Visual Studio" 옵션을 체크해 주고 "Accept" 버튼을 누른 후, "Publish" 버튼으로 배포를 하면 됩니다.

참고로, Cloud Services(classic) 유형의 배포는 패키징을 하고 그것을 통째로 업로드하기 때문에 많이 느린데 반해 이 글에서 설명한 Web Deploy 방식은 패키징이 아닌 변경된 파일만 업로드하기 때문에 처음 한 번을 제외하고는 배포가 확실히 빠릅니다.




참고로, "Recommended Server Configuration for Web Hosting Providers"가 아닌 Web Deploy만 설치했다면,

Web Deploy 3.6
; https://www.iis.net/downloads/microsoft/web-deploy

배포 시에 다음과 같은 오류가 발생합니다.

1>------ Build started: Project: Test.Framework, Configuration: Release Any CPU ------
...[생략]...
7>Auto ConnectionString Transformed web.config into obj\Release\CSAutoParameterize\transformed\web.config.
7>Copying all files to temporary location below for package/publish:
7>obj\Release\Package\PackageTmp.
7>Start Web Deploy Publish the Application/package to https://testsite.koreacentral.cloudapp.azure.com:8172/msdeploy.axd?site=Default%20Web%20Site ...
7>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets(4292,5): Error ERROR_DESTINATION_NOT_REACHABLE: Web deployment task failed. (Could not connect to the remote computer ("testsite.koreacentral.cloudapp.azure.com"). On the remote computer, make sure that Web Deploy is installed and that the required process ("Web Management Service") is started.  Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_DESTINATION_NOT_REACHABLE.)
7>Publish failed to deploy.
7>
========== Build: 6 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========

확인해 보면 실제로 8172 번 포트가 LISTENING 상태가 아님을 알 수 있습니다.




다음과 같은 오류가 발생하는 경우도 있습니다.

2018-04-12 오후 10:19:16
System.AggregateException: One or more errors occurred. ---> System.Exception: Publish failed due to build errors. Check the error list for more details.
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.Web.Publish.PublishService.VsWebProjectPublish.<>c__DisplayClass40_0.<PublishAsync>b__2()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.ApplicationCapabilities.Publish.ViewModel.ProfileSelectorViewModel.<RunPublishTaskAsync>d__108.MoveNext()
---> (Inner Exception #0) System.Exception: Publish failed due to build errors. Check the error list for more details.<---

제 경우에는, 이 글에서 설명한 "Settings..." 링크에 대한 정보를 설정하고 나서는 발생하지 않았습니다.




배포 시 web.config에 connectionStrings 노드에 있던 연결 문자열들에 대해 다음과 같은 오류가 발생할 수 있습니다.

2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets(4292,5): Error : The 'mydb-Web.config Connection String' argument cannot be null or empty.

아래의 글에 보면,

The 'DefaultConnection-Web.config Connection String' argument cannot be null or empty. VS2013
; https://stackoverflow.com/questions/28996604/the-defaultconnection-web-config-connection-string-argument-cannot-be-null-or

DB 연결 문자열 설정마다 "Use this connection string at runtime"과 'Update database" 설정이 있는데 제 경우에는 다음 화면과 같이 이런 체크 박스가 없습니다.

pub_webapp_to_azure_vm_5.png

이 옵션이 뜨게 하려면 web.config의 연결 문자열에 providerName을 추가하면 됩니다.

<connectionStrings>
    <add name="db1" providerName="System.Data.SqlClient" connectionString="...[생략]..." />
    <add name="db2" providerName="System.Data.SqlClient"  connectionString="...[생략]..." />
    <add name="db3"  providerName="System.Data.SqlClient" connectionString="...[생략]..." />
    <add name="db4"  providerName="System.Data.SqlClient" connectionString="...[생략]..." />
</connectionStrings>

이렇게 변경하고 다시 배포 화면의 "Settings..." 링크로 들어가면 체크 박스가 나타납니다.

pub_webapp_to_azure_vm_6.png

적절하게 "Use this connection string at runtime" 옵션을 설정해 주고 다시 Publish를 하면 이번에는 오류 없이 잘 배포가 됩니다. 이후에는 다시 web.config 연결 문자열 설정에서 providerName을 삭제해도 됩니다. 왜냐하면 배포 프로파일이 ".\Properties\PublishProfiles" 폴더에 .pubxml 확장자의 파일로 만들어지고 설정들이 보존되기 때문입니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 3/15/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... [91]  92  93  94  95  96  97  98  99  100  101  102  103  104  105  ...
NoWriterDateCnt.TitleFile(s)
11657정성태8/18/201819909사물인터넷: 30. 릴레이(Relay) 제어파일 다운로드3
11656정성태8/16/201815686사물인터넷: 29. 트랜지스터와 병렬로 연결한 LED파일 다운로드1
11655정성태8/16/201817949사물인터넷: 28. 저항과 병렬로 연결한 LED파일 다운로드1
11654정성태8/15/201819207사물인터넷: 27. 병렬 회로의 저항, 전압 및 전류파일 다운로드1
11653정성태8/14/201820047사물인터넷: 26. 입력 전압에 따른 LED의 전압/저항 변화 [1]파일 다운로드1
11652정성태8/14/201817470사물인터넷: 25. 컬렉터 9V, 베이스에 5V와 3.3V 전압으로 테스트하는 C1815 트랜지스터파일 다운로드1
11651정성태8/14/201822606사물인터넷: 24. 9V 전압에서 테스트하는 C1815 트랜지스터 [1]파일 다운로드3
11650정성태8/14/201817007사물인터넷: 23. 가변저항으로 분압파일 다운로드1
11649정성태8/12/201819331사물인터넷: 22. 저항에 따른 전류 테스트파일 다운로드1
11648정성태8/12/201820756사물인터넷: 21. 퓨즈를 이용한 회로 보호파일 다운로드3
11647정성태8/8/201820888오류 유형: 476. 음수의 음수는 여전히 음수가 되는 수(절대값이 음수인 수)
11646정성태8/8/201816919오류 유형: 475. gacutil.exe 실행 시 "Failure initializing gacutil" 오류 발생
11645정성태8/8/201819125오류 유형: 474. 닷넷 COM+ - Failed to load the runtime. [1]
11644정성태8/6/201822030디버깅 기술: 118. windbg - 닷넷 개발자를 위한 MEX Debugging Extension 소개
11643정성태8/6/201821638사물인터넷: 20. 아두이노 레오나르도 R3 호환 보드의 3.3v 핀의 LED 전압/전류 테스트 [1]파일 다운로드1
11642정성태8/3/201820463Graphics: 20. Unity - LightMode의 ForwardBase에 따른 _WorldSpaceLightPos0 값 변화
11641정성태8/3/201825985Graphics: 19. Unity로 실습하는 Shader (10) - 빌보드 구현 [1]파일 다운로드1
11640정성태8/3/201822142Graphics: 18. Unity - World matrix(unity_ObjectToWorld)로부터 Position, Rotation, Scale 값을 복원하는 방법파일 다운로드1
11639정성태8/2/201819732디버깅 기술: 117. windbg - 덤프 파일로부터 추출한 DLL을 참조하는 방법
11638정성태8/2/201818123오류 유형: 473. windbg - 덤프 파일로부터 추출한 DLL 참조 시 "Resolved file has a bad image, no metadata, or is otherwise inaccessible." 빌드 오류
11637정성태8/1/201822524Graphics: 17. Unity - World matrix(unity_ObjectToWorld)로부터 TRS(이동/회전/크기) 행렬로 복원하는 방법파일 다운로드1
11636정성태8/1/201829922Graphics: 16. 3D 공간에서 두 점이 이루는 각도 구하기파일 다운로드1
11635정성태8/1/201818641오류 유형: 472. C# 컴파일 오류 - Your project is not referencing the ".NETFramework,Version=v3.5" framework.
11634정성태8/1/201821592.NET Framework: 790. .NET Thread 상태가 Cooperative일 때 GC hang 현상 재현 방법파일 다운로드1
11633정성태7/29/201825519Graphics: 15. Unity - shader의 World matrix(unity_ObjectToWorld)를 수작업으로 구성 [2]파일 다운로드1
11632정성태7/28/201827838Graphics: 14. C# - Unity에서 캐릭터가 바라보는 방향을 기준으로 카메라의 위치 이동 및 회전하는 방법
... [91]  92  93  94  95  96  97  98  99  100  101  102  103  104  105  ...