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)
11456정성태2/17/201829680.NET Framework: 731. C# - await을 Task 타입이 아닌 사용자 정의 타입에 적용하는 방법 [7]파일 다운로드1
11455정성태2/17/201818599오류 유형: 451. ASP.NET Core - An error occurred during the compilation of a resource required to process this request.
11454정성태2/12/201827478기타: 71. 만료된 Office 제품 키를 변경하는 방법
11453정성태1/31/201819436오류 유형: 450. Azure Cloud Services(classic) 배포 시 "Certificate with thumbprint ... doesn't exist." 오류 발생
11452정성태1/31/201824977기타: 70. 재현 가능한 최소한의 예제 프로젝트란? [3]파일 다운로드1
11451정성태1/24/201819217디버깅 기술: 111. windbg - x86 메모리 덤프 분석 시 닷넷 메서드의 호출 인자 값 확인
11450정성태1/24/201834462Windows: 146. PowerShell로 원격 프로세스(EXE, BAT) 실행하는 방법 [1]
11449정성태1/23/201821826오류 유형: 449. 단위 테스트 - Could not load file or assembly 'Microsoft.VisualStudio.QualityTools.VideoRecorderEngine' or one of its dependencies. [1]
11448정성태1/20/201819281오류 유형: 448. Fakes를 포함한 단위 테스트 프로젝트를 빌드 시 CS0619 관련 오류 발생
11447정성태1/20/201820650.NET Framework: 730. dotnet user-secrets 명령어 [2]파일 다운로드1
11446정성태1/20/201821703.NET Framework: 729. windbg로 살펴보는 GC heap의 Segment 구조 [2]파일 다운로드1
11445정성태1/20/201819576.NET Framework: 728. windbg - 눈으로 확인하는 Workstation GC / Server GC
11444정성태1/19/201819677VS.NET IDE: 125. Visual Studio에서 Selenium WebDriver를 이용한 웹 브라우저 단위 테스트 구성파일 다운로드1
11443정성태1/18/201820172VC++: 124. libuv 모듈 살펴 보기
11442정성태1/18/201818064개발 환경 구성: 353. ASP.NET Core 프로젝트의 "Enable unmanaged code debugging" 옵션 켜는 방법
11441정성태1/18/201816610오류 유형: 447. ASP.NET Core 배포 오류 - Ensure that restore has run and that you have included '...' in the TargetFrameworks for your project.
11440정성태1/17/201819889.NET Framework: 727. ASP.NET의 HttpContext.Current 구현에 대응하는 ASP.NET Core의 IHttpContextAccessor/HttpContextAccessor 사용법파일 다운로드1
11439정성태1/17/201824668기타: 69. C# - CPU 100% 부하 주는 프로그램파일 다운로드1
11438정성태1/17/201819447오류 유형: 446. Error CS0234 The type or namespace name 'ITuple' does not exist in the namespace
11437정성태1/17/201818725VS.NET IDE: 124. Platform Toolset 설정에 따른 Visual C++의 헤더 파일 기본 디렉터리
11436정성태1/16/201820993개발 환경 구성: 352. ASP.NET Core (EXE) 프로세스가 IIS에서 호스팅되는 방법 - ASP.NET Core Module(AspNetCoreModule) [4]
11435정성태1/16/201822127개발 환경 구성: 351. OWIN 웹 서버(EXE)를 IIS에서 호스팅하는 방법 - HttpPlatformHandler (Reverse Proxy)파일 다운로드2
11434정성태1/15/201822440개발 환경 구성: 350. 사용자 정의 웹 서버(EXE)를 IIS에서 호스팅하는 방법 - HttpPlatformHandler (Reverse Proxy)파일 다운로드2
11433정성태1/15/201820510개발 환경 구성: 349. dotnet ef 명령어 사용을 위한 준비
11432정성태1/11/201826277.NET Framework: 726. WPF + Direct2D + SharpDX 출력 C# 예제파일 다운로드2
11431정성태1/11/201824256.NET Framework: 725. C# - 동기 방식이면서 비동기 메서드(awaitable)처럼 구현한 사례 [9]
... 91  92  93  94  95  96  97  98  [99]  100  101  102  103  104  105  ...