相关文章推荐
获取网关的激活密钥 - AWSStorage Gateway

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

获取网关的激活密钥

要获取网关的激活密钥,需要向网关 VM 发出一个 Web 请求,它会返回一个包含激活密钥的重定向。此激活密钥作为一个参数传递到 ActivateGateway API 操作以指定网关的配置。有关更多信息,请参阅 。 ActivateGateway 中的 Storage Gateway API 参考 .

您向网关 VM 发出的请求包含AWS激活发生的区域。响应中重定向返回的 URL 包含称为 activationkey 的查询字符串参数。此查询字符串参数是您的激活密钥。此查询字符串的格式如下所示: http:// gateway_ip_address /?activationRegion= activation_region

AWS CLI

如果您尚未安装和配置 AWS CLI,则必须先执行此操作。为此,请按照 AWS Command Line Interface 用户指南 中的这些指示操作:

以下示例说明了如何使用AWS CLI要获取 HTTP 响应,请分析 HTTP 标头并获取激活密钥。

wget 'ec2_instance_ip_address/?activationRegion=eu-west-2' 2>&1 | \ grep -i location | \ grep -i key | \ cut -d'=' -f2 |\ cut -d'&' -f1

Linux (bash/zsh)

以下示例显示如何使用 Linux (bash/zsh) 获取 HTTP 响应、分析 HTTP 标头以及获取激活密钥。

function get-activation-key() { local ip_address=$1 local activation_region=$2 if [[ -z "$ip_address" || -z "$activation_region" ]]; then echo "Usage: get-activation-key ip_address activation_region" return 1 if redirect_url=$(curl -f -s -S -w '%{redirect_url}' "http://$ip_address/?activationRegion=$activation_region"); then activation_key_param=$(echo "$redirect_url" | grep -oE 'activationKey=[A-Z0-9-]+') echo "$activation_key_param" | cut -f2 -d= return 1

Microsoft Windows PowerShell

以下示例显示如何使用 Microsoft Windows PowerShell 获取 HTTP 响应、分析 HTTP 标头以及获取激活密钥。

function Get-ActivationKey { [CmdletBinding()] Param( [parameter(Mandatory=$true)][string]$IpAddress, [parameter(Mandatory=$true)][string]$ActivationRegion PROCESS { $request = Invoke-WebRequest -UseBasicParsing -Uri "http://$IpAddress/?activationRegion=$ActivationRegion" -MaximumRedirection 0 -ErrorAction SilentlyContinue if ($request) { $activationKeyParam = $request.Headers.Location | Select-String -Pattern "activationKey=([A-Z0-9-]+)"
 
推荐文章