

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

# 取得閘道的啟用金鑰
<a name="get-activation-key"></a>

若要接收閘道的啟用金鑰，請向閘道虛擬機器 (VM) 發出網頁請求。虛擬機器會傳回包含啟用金鑰的重新導向，該重新導向會當做 `ActivateGateway` API 動作的其中一個參數傳遞，以指定閘道的組態。如需詳細資訊，請參閱 *Storage Gateway API 參考資料*中的 [ActivateGateway](https://docs.aws.amazon.com/storagegateway/latest/APIReference/API_ActivateGateway.html)。

**注意**  
如果未使用，閘道啟用金鑰會在 30 分鐘內過期。

您對閘道 VM 提出的請求包含進行啟用 AWS 的區域。重新導向在回應中傳回的 URL 會包含稱為 `activationkey` 的查詢字串參數。此查詢字串參數便是您的啟用金鑰。查詢字串的格式如下：`http://{{gateway_ip_address}}/?activationRegion={{activation_region}}`。此查詢的輸出傳回啟用區域和金鑰。

此 URL 也包含 `vpcEndpoint` 使用 VPC 端點類型連線之閘道的 VPC 端點識別碼。

**注意**  
 AWS Storage Gateway硬體設備、VM 映像範本和 Amazon EC2 Amazon Machine Image (AMI) 已預先設定 HTTP 服務，以接收和回應此頁面所述的 Web 請求。您不需要或建議您在閘道上安裝任何其他服務。

**Topics**
+ [Linux (curl)](#get-activation-key-linux-curl)
+ [Linux (bash/zsh)](#get-activation-key-linux)
+ [Microsoft Windows PowerShell](#get-activation-key-powershell)
+ [使用本機主控台](#using-local-console)

## Linux (curl)
<a name="get-activation-key-linux-curl"></a>

以下範例顯示如何使用 Linux (curl) 取得啟用金鑰。

**注意**  
將反白顯示的變數取代為閘道的實際值。可接受的值如下：  
{{gateway\_ip\_address}}：例如，閘道器的 IPV4 地址 `172.31.29.201`
{{gateway\_type}} - 您要啟用的閘道類型，例如 `STORED`、`CACHED`、`FILE_S3`、 `VTL`或 `FILE_FSX_SMB`。
{{region\_code}}：您要啟用閘道的區域。請參閱《AWS 一般參考指南》**中的[區域端點](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints)。如果未指定此參數，或提供的值拼字錯誤或不符合有效區域，則命令會預設為`us-east-1`區域。
{{vpc\_endpoint}}：例如，閘道的 VPC 端點名稱 `vpce-050f90485f28f2fd0-iep0e8vq.storagegateway.us-west-2.vpce.amazonaws.com`。

**公有端點**  
若要取得公有端點的啟用金鑰，請使用下列其中一個命令：

**標準端點**  
若要取得標準端點的啟用金鑰：

```
curl "http://{{gateway_ip_address}}/?activationRegion={{region_code}}&no_redirect"
```

**雙堆疊端點**  
若要取得雙堆疊端點的啟用金鑰：

IPv4

```
curl "http://{{gateway_ip_address}}/?activationRegion&endpointType=DUALSTACK&ipVersion=ipv4&no_redirect"
```

IPv6

```
curl "http://{{gateway_ip_address}}/?activationRegion&endpointType=DUALSTACK&ipVersion=ipv6&no_redirect"
```

**FIPS 端點**  
若要取得 FIPS 端點的啟用金鑰：

IPv4

```
curl "http://{{gateway_ip_address}}/?activationRegion&endpointType=FIPS_DUALSTACK&ipVersion=ipv4&no_redirect"
```

IPv6

```
curl "http://{{gateway_ip_address}}/?activationRegion&endpointType=FIPS_DUALSTACK&ipVersion=ipv6&no_redirect"
```

**VPC 端點**  
若要取得 VPC 端點的啟用金鑰：

```
curl "http://{{gateway_ip_address}}/?activationRegion={{region_code}}&vpcEndpoint={{vpc_endpoint}}&no_redirect"
```

## Linux (bash/zsh)
<a name="get-activation-key-linux"></a>

下列範例顯示如何使用 Linux (bash/zsh) 擷取 HTTP 回應、剖析 HTTP 標頭及取得啟用金鑰的方式。

```
  
function get-activation-key() {
  local ip_address=$1
  local activation_region=$2
  if [[ -z "$ip_address" || -z "$activation_region" || -z "$gateway_type" ]]; then
    echo "Usage: get-activation-key ip_address activation_region gateway_type"
    return 1
  fi

  if redirect_url=$(curl -f -s -S -w '%{redirect_url}' "http://$ip_address/?activationRegion=$activation_region&gatewayType=$gateway_type"); then
    activation_key_param=$(echo "$redirect_url" | grep -oE 'activationKey=[A-Z0-9-]+')
    echo "$activation_key_param" | cut -f2 -d=
  else
    return 1
  fi
}
```

## Microsoft Windows PowerShell
<a name="get-activation-key-powershell"></a>

下列範例顯示如何使用 Microsoft Windows PowerShell 擷取 HTTP 回應、剖析 HTTP 標頭及取得啟用金鑰的方式。

```
function Get-ActivationKey {
  [CmdletBinding()]
  Param(
    [parameter(Mandatory=$true)][string]$IpAddress, 
    [parameter(Mandatory=$true)][string]$ActivationRegion,
    [parameter(Mandatory=$true)][string]$GatewayType
  )
  PROCESS {
    $request = Invoke-WebRequest -UseBasicParsing -Uri "http://$IpAddress/?activationRegion=$ActivationRegion&gatewayType=$GatewayType" -MaximumRedirection 0 -ErrorAction SilentlyContinue
    if ($request) {
      $activationKeyParam = $request.Headers.Location | Select-String -Pattern "activationKey=([A-Z0-9-]+)"
      $activationKeyParam.Matches.Value.Split("=")[1]
    }
  }
}
```

## 使用本機主控台
<a name="using-local-console"></a>

下列範例示範如何使用本機主控台來產生和顯示啟用金鑰。

**Amazon Linux 2 (AL2) 型閘道**

您可以根據 AL2 為閘道選取標準或 FIPS 端點。

**注意**  
FIPS 端點並非全部可用 AWS 區域。如需詳細資訊，請參閱[依服務分類的 FIPS 端點](https://aws.amazon.com/compliance/fips/)。

**從本機主控台取得 AL2-based閘道的啟用金鑰**

1. 以*管理員*身分登入您的本機主控台。

1. 從**AWS 設備啟用 - 組態**主功能表中，選取 `0` 以選擇**取得啟用金鑰**。

1. 為閘道系列選項選取 **Storage Gateway**。

1. 輸入您要啟用閘道 AWS 的區域。

1. 針對網路類型，輸入 `1` 表示公有，或輸入 `2`表示 VPC。

1. 對於端點類型，輸入 `1` 表示標準，或輸入 `2` 表示聯邦資訊處理標準 (FIPS)。

**Amazon Linux 2023 (AL2023) 型閘道**

對於以 AL2023 為基礎的閘道，可使用下列端點：
+ 標準端點 （僅支援 IPv4)
+ FIPS 端點 （僅支援 IPv4)
+ 雙堆疊端點 （支援 IPv4 和 IPv6)
+ 雙堆疊 FIPS 端點 （支援 IPv4 和 IPv6)

如需詳細資訊，請參閱[端點類型](Requirements.md#endpoint-types-fgw)。

**從本機主控台取得 AL2023-based閘道的啟用金鑰**

1. 登入您的本機主控台。如果您是從 Windows 電腦連線到您的 Amazon EC2 執行個體，請以* admin *身分登入。

1. 從**AWS 設備啟用 - 組態**主功能表中，選取 `0` 以選擇**取得啟用金鑰**。

1. 為閘道系列選項選取 **Storage Gateway**。

1. 輸入您要啟用閘道 AWS 的區域。

1. 對於網路類型，輸入 `1` 表示公有或輸入 `2` 表示 VPC 端點。

1. 對於**選取端點類型**，**啟用 FIPS？**，輸入 `Y` 以啟用 FIPS `N` 或使用非 FIPS 端點。

1. 對於端點類型，輸入 `1` 表示標準端點，或輸入 `2` 表示雙堆疊端點。

   1. 對於雙堆疊端點，對於**選取 IP 版本或結束：**，輸入 `1` 表示 IPv4 或 `2` 表示 IPv6。