您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

将现有 Linux 服务器连接到 Azure ArcConnect an existing Linux server to Azure Arc

本文提供使用简单 shell 脚本将 Linux 服务器连接到 Azure Arc 的指南。This article provides guidance for connecting a Linux server to Azure Arc using a simple shell script.

先决条件Prerequisites

  1. 安装或 Azure CLI 更新到版本2.7 及更高版本Install or update Azure CLI to version 2.7 and above. 使用以下命令检查当前安装的版本。Use the following command to check your current installed version.

    az --version
    
  2. 创建 Azure 服务主体。Create an Azure service principal.

    若要将服务器连接到 Azure Arc,需要具有 "参与者" 角色分配的 Azure 服务主体。To connect a server to Azure Arc, an Azure service principal assigned with the Contributor role is required. 若要创建它,请登录到 Azure 帐户,并运行以下命令。To create it, sign in to your Azure account and run the following command. 你还可以在 Azure Cloud Shell中运行此命令。You can also run this command in Azure Cloud Shell.

    az login
    az ad sp create-for-rbac -n "<Unique SP Name>" --role contributor
    

    例如:For example:

    az ad sp create-for-rbac -n "http://AzureArcServers" --role contributor
    

    输出应如下所示:Output should look like this:

    {
      "appId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "displayName": "AzureArcServers",
      "name": "http://AzureArcServers",
      "password": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "tenant": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    }
    

    备注

    我们强烈建议你将服务主体的范围限定为特定的 Azure 订阅和资源组We highly recommend that you scope the service principal to a specific Azure subscription and resource group.

  3. 为服务器创建新的 Azure 资源组。Create a new Azure resource group for your servers.

    带有空资源组的 Azure 门户的屏幕截图。

  4. 下载 az_connect_linux shell 脚本。Download the az_connect_linux shell script.

  5. 根据环境更改环境变量。Change the environment variables according to your environment.

    要更改的环境变量的屏幕截图。

  6. 使用所选的首选工具将脚本复制到指定的服务器 (或将脚本复制/粘贴到服务器) 中的新文件。Copy the script to the designated server using your preferred tool of choice (or copy/paste the script to a new file inside the server). 下面的示例演示如何使用将脚本从 macOS 复制到服务器 scpThe following example shows how to copy the script from macOS to the server using scp.

    "Scp" 脚本的屏幕截图。

部署Deployment

使用命令运行脚本 . ./az_connect_linux.shRun the script using the . ./az_connect_linux.sh command.

备注

额外的点是,因为该脚本具有 导出 函数,并且需要在与其余命令相同的 shell 会话中导出变量。The extra dot is because the script has an export function and needs to have the vars exported in the same shell session as the rest of the commands.

成功完成后,会将 Linux 服务器作为新的 Azure Arc 资源连接到资源组中。Upon successful completion, you will have your Linux server, connected as a new Azure Arc resource inside your resource group.

运行 "az_connect_linux sh" Linux 脚本的屏幕截图。

Azure 门户中启用了 Azure Arc 的资源的屏幕截图。

Azure 门户中启用了 Azure Arc 资源的详细信息的屏幕截图。

删除部署Delete the deployment

若要删除服务器,请选择该服务器,然后从 Azure 门户中将其删除。To delete the server, select the server and delete it from the Azure portal.

用于删除 Azure 门户中的资源的选项的屏幕截图。

若要删除整个部署,请从 Azure 门户中删除 Azure 资源组。To delete the entire deployment, delete the Azure resource group from the Azure portal.

通过 Azure 门户删除资源组的选项的屏幕截图。