将 ASDK 注册到 AzureRegister the ASDK with Azure

可将 Azure Stack 开发工具包 (ASDK) 安装注册到 Azure,以便从 Azure 下载市场项,并设置向 Azure 报告商务数据的功能。You can register your Azure Stack Development Kit (ASDK) installation with Azure to download marketplace items from Azure and to set up commerce data reporting back to Azure. 需要注册才能支持完整的 Azure Stack 功能,包括市场联合。Registration is required to support full Azure Stack functionality, including marketplace syndication. 需要注册才能测试重要的 Azure Stack 功能,如市场联合和使用情况报告。Registration is required to enable you to test important Azure Stack functionality like marketplace syndication and usage reporting. 注册 Azure Stack 之后,使用情况将报告给 Azure 商业组件。After you register Azure Stack, usage is reported to Azure commerce. 用于注册的订阅下会显示此信息。You can see it under the subscription you used for registration. 但是,ASDK 用户无需付费,不管他们报告的用量是多少。However, ASDK users aren't charged for any usage they report.

如果未注册 ASDK,你可能会看到“需要激活” 警告警报,其中建议注册 ASDK。If you don't register your ASDK, you might see an Activation Required warning alert that advises you to register your ASDK. 这是预期的行为。This behavior is expected.

必备条件Prerequisites

在按这些说明将 ASDK 注册到 Azure 之前,请确保已安装 Azure Stack PowerShell,并已下载部署后配置一文中所述的 Azure Stack 工具。Before using these instructions to register the ASDK with Azure, ensure that you've installed the Azure Stack PowerShell and downloaded the Azure Stack tools as described in the post-deployment configuration article.

此外,在用于向 Azure 注册 ASDK 的计算机上,PowerShell 语言模式必须设置为 FullLanguageThe PowerShell language mode must also be set to FullLanguage on the computer used to register the ASDK with Azure. 若要验证当前的语言模式是否设置为 Full,请打开权限提升的 PowerShell 窗口,并运行以下 PowerShell 命令:To verify that the current language mode is set to full, open an elevated PowerShell window and run the following PowerShell commands:

$ExecutionContext.SessionState.LanguageMode

确保输出返回的是 FullLanguageEnsure the output returns FullLanguage. 如果返回了其他任何语言模式,则需要在另一台计算机上运行注册,或者将语言模式设置为 FullLanguage,然后继续。If any other language mode is returned, registration needs to be run on another computer or the language mode set to FullLanguage before continuing.

用于注册的 Azure AD 帐户需要有权访问 Azure 订阅,并且有权在与该订阅关联的目录中创建标识应用和服务主体。The Azure AD account used for registration needs to have access to the Azure subscription and have permissions to create identity apps and service principals in the directory associated with that subscription. 我们建议通过创建用于注册的服务帐户将 Azure Stack 注册到 Azure,而不要使用全局管理员凭据。We recommend you register Azure Stack with Azure by creating a service account to use for registration rather than using global admin credentials.

注册 ASDKRegister the ASDK

遵循以下步骤将 ASDK 注册到 Azure。Follow these steps to register the ASDK with Azure.

Note

所有这些步骤必须在可以访问特权终结点的计算机上运行。All these steps must be run from a computer that has access to the privileged endpoint. 对于 ASDK 来说,该计算机是 ASDK 主计算机。For the ASDK, that's the ASDK host computer.

  1. 以管理员身份打开 PowerShell 控制台。Open a PowerShell console as an admin.

  2. 运行以下 PowerShell 命令,将 ASDK 安装注册到 Azure。Run the following PowerShell commands to register your ASDK installation with Azure. 同时登录到 Azure 计费订阅 ID 和本地 ASDK 安装。Sign in to both your Azure billing Subscription ID and the local ASDK installation. 如果你没有 Azure 计费订阅 ID,可在此处创建一个试用 Azure 帐户If you don't have an Azure billing subscription ID yet, you can create a trial Azure account here. 注册 Azure Stack 不会对 Azure 订阅收取任何费用。Registering Azure Stack incurs no cost on your Azure subscription.

    在运行 Set-AzsRegistration cmdlet 时设置适用于注册的唯一名称。Set a unique name for the registration when you run the Set-AzsRegistration cmdlet. RegistrationName 参数的默认值为 AzureStackRegistrationThe RegistrationName parameter has a default value of AzureStackRegistration. 但是,如果在多个 Azure Stack 实例上使用同一名称,该脚本会失败。However, if you use the same name on more than one instance of Azure Stack, the script will fail.

    # Add the Azure cloud subscription environment name. 
    # Supported environment name is AzureChinaCloud depending which Azure subscription you're using.
    Add-AzureRmAccount -EnvironmentName "AzureChinaCloud"
    
    # Register the Azure Stack resource provider in your Azure subscription
    Register-AzureRmResourceProvider -ProviderNamespace Microsoft.AzureStack
    
    # Import the registration module that was downloaded with the GitHub tools
    Import-Module C:\AzureStack-Tools-master\Registration\RegisterWithAzure.psm1
    
    # If you have multiple subscriptions, run the following command to select the one you want to use:
    # Get-AzureRmSubscription -SubscriptionID "<subscription ID>" | Select-AzureRmSubscription
    
    # Register Azure Stack
    $AzureContext = Get-AzureRmContext
    $CloudAdminCred = Get-Credential -UserName AZURESTACK\CloudAdmin -Message "Enter the credentials to access the privileged endpoint."
    $RegistrationName = "<unique-registration-name>"
    Set-AzsRegistration `
    -PrivilegedEndpointCredential $CloudAdminCred `
    -PrivilegedEndpoint AzS-ERCS01 `
    -BillingModel Development `
    -RegistrationName $RegistrationName `
    -UsageReportingEnabled:$true
    
  3. 该脚本完成后,会显示以下消息:“现已使用提供的参数注册并激活环境”。 When the script completes, you should see this message: Your environment is now registered and activated using the provided parameters.

    环境现已注册

在离线环境中注册Register in disconnected environments

若要在离线环境(未建立 Internet 连接)中注册 Azure Stack,需要从 Azure Stack 环境获取注册令牌,然后在可连接到 Azure 的计算机上使用该令牌,并为 ASDK 环境创建激活资源。If you're registering Azure Stack in a disconnected environment (with no internet connectivity), you need to get a registration token from the Azure Stack environment and then use that token on a computer that can connect to Azure to register and create an activation resource for your ASDK environment.

Important

在按这些说明注册 Azure Stack 之前,请确保根据部署后的配置一文中所述,在 ASDK 主机以及可访问 Internet 的、用于连接到 Azure 和注册的计算机上,安装适用于 Azure Stack 的 PowerShell 并下载 Azure Stack 工具。Before using these instructions to register Azure Stack, ensure that you've installed PowerShell for Azure Stack and downloaded the Azure Stack tools as described in the post-deployment configuration article on both the ASDK host computer and the computer with internet access used to connect to Azure and register.

从 Azure Stack 环境获取注册令牌Get a registration token from the Azure Stack environment

在 ASDK 主机上,以管理员身份启动 PowerShell,并导航到下载 Azure Stack 工具时所创建的 AzureStack-Tools-master 目录中的 Registration 文件夹。On the ASDK host computer, start PowerShell as an admin and navigate to the Registration folder in the AzureStack-Tools-master directory created when you downloaded the Azure Stack tools. 使用以下 PowerShell 命令导入 RegisterWithAzure.psm1 模块,然后使用 Get-AzsRegistrationToken cmdlet 获取注册令牌:Use the following PowerShell commands to import the RegisterWithAzure.psm1 module and then use the Get-AzsRegistrationToken cmdlet to get the registration token:

# Import the registration module that was downloaded with the GitHub tools
Import-Module C:\AzureStack-Tools-master\Registration\RegisterWithAzure.psm1

# Create registration token
$CloudAdminCred = Get-Credential -UserName AZURESTACK\CloudAdmin -Message "Enter the credentials to access the privileged endpoint."
# File path to save the token. This example saves the file as C:\RegistrationToken.txt.
$FilePathForRegistrationToken = "$env:SystemDrive\RegistrationToken.txt"
$RegistrationToken = Get-AzsRegistrationToken -PrivilegedEndpointCredential $CloudAdminCred `
-UsageReportingEnabled:$false `
-PrivilegedEndpoint AzS-ERCS01 `
-BillingModel Development `
-MarketplaceSyndicationEnabled:$false `
-TokenOutputFilePath $FilePathForRegistrationToken

保存此注册令牌,以便在连接到 Internet 的计算机上使用。Save this registration token for use on the internet-connected computer. 可以从通过 $FilePathForRegistrationToken 参数创建的文件中复制文件或文本。You can copy the file or the text from the file created by the $FilePathForRegistrationToken parameter.

连接到 Azure 并注册Connect to Azure and register

在已连接到 Internet 的计算机上,使用以下 PowerShell 命令导入 RegisterWithAzure.psm1 模块,然后通过 Register-AzsEnvironment cmdlet 并使用刚才创建的注册令牌和唯一的注册名称来注册到 Azure:On the internet-connected computer, use the following PowerShell commands to import the RegisterWithAzure.psm1 module and then use the Register-AzsEnvironment cmdlet to register with Azure using the registration token you just created and a unique registration name:

# Add the Azure cloud subscription environment name. 
# Supported environment names is AzureChinaCloud depending which Azure subscription you are using.
Add-AzureRmAccount -EnvironmentName "AzureChinaCloud"

# If you have multiple subscriptions, run the following command to select the one you want to use:
# Get-AzureRmSubscription -SubscriptionID "<subscription ID>" | Select-AzureRmSubscription

# Register the Azure Stack resource provider in your Azure subscription
Register-AzureRmResourceProvider -ProviderNamespace Microsoft.AzureStack

# Import the registration module that was downloaded with the GitHub tools
Import-Module C:\AzureStack-Tools-master\Registration\RegisterWithAzure.psm1

# Register with Azure
# This example uses the C:\RegistrationToken.txt file.
$registrationToken = Get-Content -Path "$env:SystemDrive\RegistrationToken.txt"
$RegistrationName = "<unique-registration-name>"
Register-AzsEnvironment -RegistrationToken $registrationToken `
-RegistrationName $RegistrationName

或者,可以使用 Get-Content cmdlet 指向包含注册令牌的文件:Alternatively, you can use the Get-Content cmdlet to point to a file that contains your registration token:

# Add the Azure cloud subscription environment name. 
# Supported environment names is AzureChinaCloud depending which Azure subscription you are using.
Add-AzureRmAccount -EnvironmentName "AzureChinaCloud"

# If you have multiple subscriptions, run the following command to select the one you want to use:
# Get-AzureRmSubscription -SubscriptionID "<subscription ID>" | Select-AzureRmSubscription

# Register the Azure Stack resource provider in your Azure subscription
Register-AzureRmResourceProvider -ProviderNamespace Microsoft.AzureStack

# Import the registration module that was downloaded with the GitHub tools
Import-Module C:\AzureStack-Tools-master\Registration\RegisterWithAzure.psm1

# Register with Azure 
# This example uses the C:\RegistrationToken.txt file.
$registrationToken = Get-Content -Path "$env:SystemDrive\RegistrationToken.txt"
Register-AzsEnvironment -RegistrationToken $registrationToken `
-RegistrationName $RegistrationName

注册完成后,应会看到如下所示的消息:“你的 Azure Stack 环境现已注册到 Azure”。 When registration is complete, you should see a message similar to: Your Azure Stack environment is now registered with Azure.

Important

不要关闭 PowerShell 窗口。Do not close the PowerShell window.

保存注册令牌和注册资源名称,供以后参考。Save the registration token and registration resource name for future reference.

从 Azure 注册资源检索激活密钥Retrieve an activation key from the Azure registration resource

仍然使用已连接到 Internet 的计算机和同一 PowerShell 控制台窗口,从注册到 Azure 时创建的注册资源中检索激活密钥。Still using the internet-connected computer, and the same PowerShell console window, retrieve an activation key from the registration resource created when you registered with Azure.

若要获取激活密钥,请运行以下 PowerShell 命令。To get the activation key, run the following PowerShell commands. 使用在上一步骤中注册到 Azure 时提供的同一个唯一注册名称值:Use the same unique registration name value you provided when registering with Azure in the previous step:

$RegistrationResourceName = "<unique-registration-name>"
# File path to save the activation key. This example saves the file as C:\ActivationKey.txt.
$KeyOutputFilePath = "$env:SystemDrive\ActivationKey.txt"
$ActivationKey = Get-AzsActivationKey -RegistrationName $RegistrationResourceName `
-KeyOutputFilePath $KeyOutputFilePath

在 Azure Stack 中创建激活资源Create an Activation Resource in Azure Stack

使用 Get-AzsActivationKey 从创建的激活密钥中获取文件或文本后,返回到 Azure Stack 环境。Return to the Azure Stack environment with the file or text from the activation key created from Get-AzsActivationKey. 运行以下 PowerShell 命令,使用该激活密钥在 Azure Stack 中创建激活资源:Run the following PowerShell commands to create an activation resource in Azure Stack using that activation key:

# Import the registration module that was downloaded with the GitHub tools
Import-Module C:\AzureStack-Tools-master\Registration\RegisterWithAzure.psm1

$CloudAdminCred = Get-Credential -UserName AZURESTACK\CloudAdmin -Message "Enter the credentials to access the privileged endpoint."
$ActivationKey = "<activation key>"
New-AzsActivationResource -PrivilegedEndpointCredential $CloudAdminCred `
-PrivilegedEndpoint AzS-ERCS01 `
-ActivationKey $ActivationKey

或者,可以使用 Get-Content cmdlet 指向包含注册令牌的文件:Alternatively, you can use the Get-Content cmdlet to point to a file that contains your registration token:

# Import the registration module that was downloaded with the GitHub tools
Import-Module C:\AzureStack-Tools-master\Registration\RegisterWithAzure.psm1

$CloudAdminCred = Get-Credential -UserName AZURESTACK\CloudAdmin -Message "Enter the credentials to access the privileged endpoint."
# This example uses the C:\ActivationKey.txt file.
$ActivationKey = Get-Content -Path "$env:SystemDrive\Activationkey.txt"
New-AzsActivationResource -PrivilegedEndpointCredential $CloudAdminCred `
-PrivilegedEndpoint AzS-ERCS01 `
-ActivationKey $ActivationKey

激活完成后,应会看到如下所示的消息:“你的环境已完成注册和激活过程”。 When activation is complete, you should see a message similar to: Your environment has finished the registration and activation process.

验证注册是否成功Verify the registration was successful

可以使用“区域管理”磁贴,验证 Azure Stack 注册是否成功。You can use the Region management tile to verify that the Azure Stack registration was successful. 可在管理员门户的默认仪表板上使用此磁贴。This tile is available on the default dashboard in the administrator portal.

  1. 登录到 Azure Stack 管理员门户Sign in to the Azure Stack administrator portal.

  2. 在“仪表板”中,选择“区域管理”。 From the Dashboard, select Region management.

    Azure Stack 管理员门户中的“区域管理”磁贴Region management tile in Azure Stack administrator portal

  3. 选择“属性” 。Select Properties. 此边栏选项卡显示环境的状态和详细信息。This blade shows the status and details of your environment. 状态可能是“已注册”,也可能是“未注册”。 The status can be Registered or Not registered. 如果是已注册,则还会显示用于注册 Azure Stack 的 Azure 订阅 ID,以及注册资源组和名称。If registered, it also shows the Azure subscription ID that you used to register your Azure Stack, along with the registration resource group and name.

移动注册资源Move a registration resource

支持在同一订阅下的资源组之间移动注册资源 。Moving a registration resource between resource groups under the same subscription is supported. 有关将资源移到新资源组的详细信息,请参阅将资源移到新的资源组或订阅For more info on moving resources to a new resource group, see Move resources to new resource group or subscription.

后续步骤Next steps