

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 執行基本 IIS 遷移
<a name="dotnet-migrating-applications-basic-migration"></a>

本節將引導您使用 **eb migrate**命令將 IIS 應用程式遷移至 Elastic Beanstalk。

## 探索您的 IIS 環境
<a name="dotnet-migrating-applications-basic-migration-exploring"></a>

在進行任何變更之前，您會想要了解伺服器上存在的資源。首先執行 探索您的 IIS 網站**eb migrate explore**，如下列範例所示：

```
PS C:\migrations_workspace> eb migrate explore
```

此命令會顯示您的 IIS 網站。請參閱下列清單：

```
Default Web Site
Intranet
API.Internal
Reports
```

如需每個網站組態的詳細檢視，包括繫結、應用程式和虛擬目錄，請新增 `--verbose`選項，如本範例所示：

```
PS C:\migrations_workspace> eb migrate explore --verbose
```

以下清單顯示 命令提供的 環境的完整資訊：

```
1: Default Web Site:
  - Bindings:
    - *:80:www.example.com
    - *:443:www.example.com
  - Application '/':
    - Application Pool: DefaultAppPool
    - Enabled Protocols: http
    - Virtual Directories:
      - /:
        - Physical Path: C:\inetpub\wwwroot
        - Logon Method: ClearText
  - Application '/api':
    - Application Pool: ApiPool
    - Enabled Protocols: http
    - Virtual Directories:
      - /:
        - Physical Path: C:\websites\api
        - Logon Method: ClearText
2: Intranet:
...
3. API.Internal:
...
4. Reports:
...
```

### 了解探索輸出
<a name="dotnet-migrating-applications-basic-migration-exploring-output"></a>

詳細輸出提供下列遷移規劃的關鍵資訊：

網站  
探索輸出會列出伺服器上的所有 IIS 網站。每個網站會以其名稱 （例如「預設網站」、「內部網路」、「API.內部」) 識別，並依序編號。當伺服器上存在多個網站時， `eb migrate`命令可以根據您的遷移策略單獨或一起封裝和部署每個網站。

繫結  
通訊協定繫結會顯示您的網站使用哪些通訊協定 (HTTP/HTTPS) 及其操作的連接埠。繫結資訊包含定義網域型路由組態的主機標頭需求。

應用程式  
應用程式路徑會顯示 IIS 組態中的根應用程式結構和巢狀應用程式結構。應用程式集區指派會指出應用程式如何彼此隔離以進行安全性和資源管理。

虛擬目錄  
實體路徑映射指出您的內容位於檔案系統上的位置。身分驗證設定顯示遷移後需要維護的特殊存取要求。

## 準備遷移
<a name="dotnet-migrating-applications-basic-migration-preparing"></a>

了解您的環境後，請確定您的伺服器符合先決條件。首先，使用以下 PowerShell 命令驗證您的 IIS 版本：

```
PS C:\migrations_workspace> Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\InetStp\" -Name MajorVersion
```

您需要 IIS 7.0 或更新版本。遷移工具使用 Web Deploy 3.6 封裝您的應用程式。使用以下命令驗證其安裝：



```
PS C:\migrations_workspace> Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\3" -Name InstallPath
```

如果您的伺服器上未安裝 Web Deploy，您可以從 [Microsoft Web Platform Installer](https://www.iis.net/downloads/microsoft/web-deploy) 下載頁面下載。

## 您的第一次遷移
<a name="dotnet-migrating-applications-basic-migration-first"></a>

讓我們從預設網站的基本遷移開始。下列範例顯示最簡單的命令 **eb migrate**。

```
PS C:\migrations_workspace> eb migrate
```

此命令會啟動一系列自動化步驟，如下列範例輸出所示：

```
Identifying VPC configuration of this EC2 instance (i-0123456789abcdef0)
  id: vpc-1234567890abcdef0
  publicip: true
  elbscheme: public
  ec2subnets: subnet-123,subnet-456,subnet-789
  securitygroups: sg-123,sg-456
  elbsubnets: subnet-123,subnet-456,subnet-789

Using .\migrations\latest to contain artifacts for this migration run.
Generating source bundle for sites, applications, and virtual directories...
  Default Web Site/ -> .\migrations\latest\upload_target\DefaultWebSite.zip
```

遷移工具會建立包含部署成品的結構化目錄。下列清單顯示目錄結構：

```
C:\migration_workspace\
└── .\migrations\latest\
    └── upload_target\
        ├── DefaultWebSite.zip
        ├── aws-windows-deployment-manifest.json
        └── ebmigrateScripts\
            ├── site_installer.ps1
            ├── permission_handler.ps1
            └── >other helper scripts<
```

## 控制遷移
<a name="dotnet-migrating-applications-basic-migration-controlling"></a>

如需對遷移程序的更多控制，您可以使用下列命令指定要遷移的站點：

```
PS C:\migrations_workspace> eb migrate --sites "Default Web Site,Intranet"
```

您也可以自訂環境名稱和應用程式名稱，如下列範例命令所示：

```
PS C:\migrations_workspace> eb migrate `
    --sites "Default Web Site" `
    --application-name "CorporateApp" `
    --environment-name "Production"
```

如需選項的完整清單，請參閱 [**eb migrate**](eb3-migrate.md)。

## 監控進度
<a name="dotnet-migrating-applications-basic-migration-monitoring"></a>

在遷移期間， **eb migrate**會提供即時狀態更新。請參閱下列輸出範例：

```
...
Creating application version
Creating environment... This may take a few minutes

2024-03-18 18:12:15    INFO    Environment details for: Production
  Application name: CorporateApp
  Region: us-west-2
  Deployed Version: app-230320_153045
  Environment ID: e-abcdef1234
  Platform: 64bit Windows Server 2019 v2.7.0 running IIS 10.0
  Tier: WebServer-Standard-1.0
  CNAME: production.us-west-2.elasticbeanstalk.com
  Updated: 2024-03-20 15:30:45
2025-03-18 18:12:17    INFO    createEnvironment is starting.
2025-03-18 18:12:19    INFO    Using elasticbeanstalk-us-east-1-180301529717 as Amazon S3 storage bucket for environment data.
2025-03-18 18:12:40    INFO    Created security group named: sg-0fdd4d696a26b086a
2025-03-18 18:12:48    INFO    Environment health has transitioned to Pending. Initialization in progress (running for 7 seconds). There are no instances.
...
2025-03-18 18:23:59    INFO    Application available at EBMigratedEnv-arrreal3.us-east-1.elasticbeanstalk.com.
2025-03-18 18:24:00    INFO    Successfully launched environment: EBMigratedEnv-arrreal3
```

## 驗證遷移
<a name="dotnet-migrating-applications-basic-migration-verifying"></a>

一旦環境準備就緒，Elastic Beanstalk 會提供數種方法來驗證您的部署。

存取您的應用程式  
在 Web 瀏覽器中開啟您的應用程式 URL (CNAME)，以確認其正常運作。

檢查環境運作狀態  
使用 **eb health**命令來檢視環境的運作狀態。  

```
PS C:\migrations_workspace> eb health
```
下列螢幕影像顯示執行個體運作狀態、應用程式回應指標和系統資源使用率。  

![從 eb 運作狀態命令的輸出會顯示執行個體運作狀態、應用程式回應指標和系統資源使用率。](http://docs.aws.amazon.com/zh_tw/elasticbeanstalk/latest/dg/images/eb-health-after-migration.png)


使用 **eb logs**命令來存取日誌，以疑難排解任何問題：  

```
PS C:\migrations_workspace> eb logs --zip
```
**eb logs** 命令會將日誌下載到 `.elasticbeanstalk/logs`目錄。如需詳細資訊，請參閱[搭配 Amazon CloudWatch Logs 使用 Elastic Beanstalk](AWSHowTo.cloudwatchlogs.md)。

連線至執行個體  
如果您在遷移期間指定了金鑰對，則可以使用 RDP 連接到執行個體以進行直接故障診斷。

存取 Elastic Beanstalk 主控台  
您可以透過環境[管理主控台](environments-console.md)檢視環境的運作狀態、日誌和組態屬性。

## 管理遷移成品
<a name="dotnet-migrating-applications-basic-migration-cleanup"></a>

**eb migrate** 命令會在遷移程序期間建立本機成品。這些成品包含敏感資訊，可能會隨著時間消耗大量磁碟空間。使用 **cleanup**子命令來管理這些成品，如下列範例所示：

```
PS C:\migrations_workspace> eb migrate cleanup
Are you sure you would like to cleanup older artifacts within ./migrations/? (Y/N):
```

若要強制清除而不進行確認，請使用 **--force**選項：

```
PS C:\migrations_workspace> eb migrate cleanup --force
```

清除程序會在 `./migrations/latest`目錄中保留最新的成功遷移，並移除較舊的遷移目錄