安装云助手Agent

需要通过控制台或API进行免登录管理、执行命令或者发送文件等操作时,必须在目标实例上安装并运行云助手Agent。

适用范围

以下操作系统支持安装云助手Agent:

  • Linux:Alibaba Cloud Linux、AlmaLinux 8+、Anolis OS 7+、CentOS 5+、Debian 8+、Ubuntu 12+、RHEL 5+、SUSE 11+、Fedora 33+、CoreOS、OpenSUSE。

  • FreeBSD:11+。

  • Windows:Server 2012+。

2017121日起,通过公共镜像创建的ECS实例已预装云助手Agent。

操作步骤

控制台

  1. 访问ECS控制台-云助手

  2. 在页面左侧顶部,选择目标资源所在的资源组和地域。地域

  3. 单击ECS实例页签,查看当前地域ECS实例上的云助手状态。

    • 正常:已安装。

    • 未安装:单击一键安装,等待安装完成,需要重启实例之后查看状态是否变为正常

      image.png

    • 异常:请参见云助手异常状态处理

Linux实例

步骤一:检查是否已安装云助手Agent

  1. 使用Workbench登录Linux实例

  2. 判断初始化系统类型。

    初始化系统(init system)负责在系统启动时加载和管理服务进程,不同初始化系统对应的云助手Agent的命令不同。
    • systemd:Alibaba Cloud Linux、CentOS 7+、RHEL 7+、Fedora 15+、Ubuntu 15.04+、Debian 8+等。

    • Upstart:Ubuntu 6.10-14.10、RHEL 6、CentOS 6等。

    • SysVinit:RHEL 5、CentOS 5、Debian 6等。

  3. 验证是否安装云助手Agent。

    systemd

    systemctl status aliyun.service

    若回执信息包含 Unit aliyun.service could not be found提示,表示未安装。

    upstart

    /sbin/initctl status aliyun-service

    若回执信息包含 initctl: Unknown job: aliyun-service提示,表示未安装。

    sysvinit

    /etc/init.d/aliyun-service status

    若回执信息为空,表示未安装。

步骤二:下载并安装云助手Agent

脚本适用于阿里云ECS实例,默认安装最新版本的Agent,安装指定版本请修改VERSION=latest

#!/bin/bash

VERSION=latest
PACKAGE=
PKG_URI=

REGION=$(curl http://100.100.100.200/latest/meta-data/region-id)
DOMAIN=aliyun-client-assist-${REGION}.oss-${REGION}-internal.aliyuncs.com

arch=$(uname -m)
echo "[main] arch = ${arch}"
case $arch in
    "i386"|"i686"|"x86_64"|"amd64")
        if command -v rpm; then
            PACKAGE="aliyun_assist_${VERSION}.rpm"
        else
            PACKAGE="aliyun_assist_${VERSION}.deb"
        fi
        PKG_URI="https://$DOMAIN/linux/$PACKAGE"
        ;;
    *)
        if command -v rpm; then
            PACKAGE="aliyun-assist-${VERSION}-1.aarch64.rpm"
        else
            PACKAGE="aliyun-assist_${VERSION}-1_arm64.deb"
        fi
        PKG_URI="https://$DOMAIN/arm/$PACKAGE"
esac

if command -v wget; then
    sudo wget $PKG_URI
elif command -v curl; then
    curl -o $PACKAGE $PKG_URI
else
    echo "[WARN] command wget/curl not found,exit"
    exit 1;
fi;

if command -v rpm; then
    sudo rpm -ivh --force $PACKAGE
elif command -v dpkg; then
    sudo dpkg -i $PACKAGE
else
    echo "[WARN] command rpm/dpkg not found,exit"
    exit 2;
fi

if [[ -e /etc/redhat-release ]]; then
    if sudo systemctl status qemu-guest-agent; then
        sudo systemctl stop qemu-guest-agent
        sudo systemctl disable qemu-guest-agent
        sudo systemctl restart aliyun.service
    fi
fi

Windows实例

步骤一:检查是否已安装云助手Agent

  1. 通过密码认证登录Windows实例

  2. 查看云助手服务状态。

    1. 单击开始菜单,搜索计算机管理

    2. 选择服务和应用程序 > 服务

    3. 查找Aliyun Assist Service,若不存在,表示未安装。

      image

步骤二:下载并安装云助手Agent

方法一:通过浏览器下载云助手Agent
  1. 下载云助手Agent。

    将地址中的{regionId}替换为实例所在地域ID后,在浏览器中打开。

    https://aliyun-client-assist-{regionId}.oss-{regionId}-internal.aliyuncs.com/windows/aliyun_agent_latest_setup.exe
    
    # 示例:杭州(cn-hangzhou)下载地址
    https://aliyun-client-assist-cn-hangzhou.oss-cn-hangzhou-internal.aliyuncs.com/windows/aliyun_agent_latest_setup.exe
  2. 安装云助手Agent。

    双击云助手Agent文件,根据安装向导完成安装。默认安装路径为C:\ProgramData\aliyun\assist\

方法二:通过PowerShell安装并启动云助手Agent

将脚本中的{regionId}替换为实例所在地域ID后,在PowerShell中执行。

curl -UseBasicParsing -Uri https://aliyun-client-assist-{regionId}.oss-{regionId}-internal.aliyuncs.com/windows/aliyun_agent_latest_setup.exe -OutFile 'C:\\aliyun_agent_latest_setup.exe'
;"C:\\aliyun_agent_latest_setup.exe" '/S' 

API

通过API安装云助手Agent不区分操作系统类型。

  1. 调用DescribeCloudAssistantStatus查询目标ECS实例是否安装了云助手Agent。

    CloudAssistantStatus返回false时,表示未安装。

  2. 若实例未安装云助手Agent,则调用InstallCloudAssistant安装云助手Agent。

  3. 安装完成之后,调用RebootInstance重启ECS实例使安装生效。

CLI

通过阿里云CLI安装云助手Agent不区分操作系统类型。请替换命令中的<YOUR-REGION-ID>为ECS实例所在地域ID,<YOUR-INSTANCE-ID>为ECS实例ID。

Red Hat Enterprise Linux (RHEL) 不支持通过阿里云CLI安装。
  1. 调用DescribeCloudAssistantStatus查询目标ECS实例是否安装了云助手Agent。

    aliyun ecs DescribeCloudAssistantStatus --RegionId <YOUR-REGION-ID> --InstanceId.1 <YOUR-INSTANCE-ID> --output cols=CloudAssistantStatus rows=InstanceCloudAssistantStatusSet.InstanceCloudAssistantStatus[]

    返回CloudAssistantStatus=true时,表示ECS实例已安装云助手Agent。

  2. 调用InstallCloudAssistant安装云助手Agent。

    aliyun ecs InstallCloudAssistant --RegionId <YOUR-REGION-ID> --InstanceId.1 <YOUR-INSTANCE-ID>
  3. 调用RebootInstance重启ECS实例。

    aliyun ecs RebootInstance --InstanceId <YOUR-INSTANCE-ID>

常见问题

如果我的操作系统不支持安装云助手Agent,该怎么办?

为什么操作系统支持但无法安装最新版本的云助手Agent?

部分内核在安装云助手时存在最高可安装版本的限制。

执行uname -r查看内核版本。

实例的内核版本号

云助手Agent可升级的最高版本

Linux内核版本 < 2.6.32

  • X86/X64架构:2.2.3.398

  • ARM架构:2.4.3.398

FreeBSD 内核版本 < 12.x

2.3.3.529

FreeBSD操作系统如何安装云助手Agent?

  • 适用于阿里云ECS实例

    #!/bin/sh
    
    VERSION=latest
    use_curl=0
    which curl >/dev/null 2>&1 && use_curl=1
    if [ $use_curl -eq 1 ];then
        REGION=$(curl http://100.100.100.200/latest/meta-data/region-id)
    else
        REGION=$(wget -O - http://100.100.100.200/latest/meta-data/region-id)
    fi
    DOMAIN=aliyun-client-assist-${REGION}.oss-${REGION}-internal.aliyuncs.com
    PACKAGE=aliyun_assist_${VERSION}.txz
    PKG_URI="https://$DOMAIN/freebsd/$PACKAGE"
    
    if [ $use_curl -eq 1 ];then
        curl -o $PACKAGE $PKG_URI
    else
        wget -O $PACKAGE $PKG_URI
    fi
    pkg install -U -y $PACKAGE
    service aliyun start
  • 适用于托管实例(非阿里云服务器)

    #!/bin/sh
    
    VERSION=latest
    DOMAIN=aliyun-client-assist.oss-accelerate.aliyuncs.com
    PACKAGE=aliyun_assist_${VERSION}.txz
    PKG_URI="https://$DOMAIN/freebsd/$PACKAGE"
    
    use_curl=0
    which curl >/dev/null 2>&1 && use_curl=1
    if [ $use_curl -eq 1 ];then
        curl -o $PACKAGE $PKG_URI
    else
        wget -O $PACKAGE $PKG_URI
    fi
    pkg install -U -y $PACKAGE
    service aliyun start

托管实例(非阿里云服务器)如何安装云助手Agent?

Linux

脚本默认安装最新版本的Agent,安装指定版本请修改VERSION=latest
#!/bin/bash

VERSION=latest
PACKAGE=
PKG_URI=

DOMAIN=aliyun-client-assist.oss-accelerate.aliyuncs.com

arch=$(uname -m)
echo "[main] arch = ${arch}"
case $arch in
    "i386"|"i686"|"x86_64"|"amd64")
        if command -v rpm; then
            PACKAGE="aliyun_assist_${VERSION}.rpm"
        else
            PACKAGE="aliyun_assist_${VERSION}.deb"
        fi
        PKG_URI="https://$DOMAIN/linux/$PACKAGE"
        ;;
    *)
        if command -v rpm; then
            PACKAGE="aliyun-assist-${VERSION}-1.aarch64.rpm"
        else
            PACKAGE="aliyun-assist_${VERSION}-1_arm64.deb"
        fi
        PKG_URI="https://$DOMAIN/arm/$PACKAGE"
esac

if command -v wget; then
    sudo wget $PKG_URI
elif command -v curl; then
    curl -o $PACKAGE $PKG_URI
else
    echo "[WARN] command wget/curl not found,exit"
    exit 1;
fi;

if command -v rpm; then
    sudo rpm -ivh --force $PACKAGE
elif command -v dpkg; then
    sudo dpkg -i $PACKAGE
else
    echo "[WARN] command rpm/dpkg not found,exit"
    exit 2;
fi

if [[ -e /etc/redhat-release ]]; then
    if sudo systemctl status qemu-guest-agent; then
        sudo systemctl stop qemu-guest-agent
        sudo systemctl disable qemu-guest-agent
        sudo systemctl restart aliyun.service
    fi
fi

Windows

方法一:通过浏览器打开网址下载云助手Agent。
  1. 在浏览器中打开网址下载云助手Agent。

    https://aliyun-client-assist.oss-accelerate.aliyuncs.com/windows/aliyun_agent_latest_setup.exe
  2. 安装云助手Agent。

    双击云助手Agent文件,根据安装向导完成安装。默认安装路径为C:\ProgramData\aliyun\assist\

方法二:通过PowerShell安装并启动云助手Agent
curl -UseBasicParsing -Uri https://aliyun-client-assist.oss-accelerate.aliyuncs.com/windows/aliyun_agent_latest_setup.exe -OutFile 'C:\\aliyun_agent_latest_setup.exe'
;"C:\\aliyun_agent_latest_setup.exe" '/S' 

云助手Agent如何通过二进制包或者源码等方式安装?

二进制包(Binary)安装

  • 适用于阿里云ECS实例

    脚本默认安装最新版本的Agent,安装指定版本请修改VERSION=latest
    #!/bin/bash
    
    VERSION=latest
    PACKAGE=
    PKG_URI=
    
    REGION=$(curl http://100.100.100.200/latest/meta-data/region-id)
    DOMAIN=aliyun-client-assist-${REGION}.oss-${REGION}-internal.aliyuncs.com
    
    arch=$(uname -m)
    echo "[main] arch = ${arch}"
    case $arch in
        "i386"|"i686"|"x86_64"|"amd64")
            PACKAGE="aliyun_assist_${VERSION}_update.zip"
            PKG_URI="https://$DOMAIN/linux/$PACKAGE"
            ;;
        *)
            PACKAGE="aliyun_assist_${VERSION}_update_arm.zip"
            PKG_URI="https://$DOMAIN/arm/$PACKAGE"
    esac
    
    if command -v wget; then
        sudo wget $PKG_URI
    elif command -v curl; then
        curl -o $PACKAGE $PKG_URI
    else
        echo "[WARN] command wget/curl not found,exit"
        exit 1
    fi;
    
    TARGET_DIR=/usr/local/share/aliyun-assist
    sudo unzip -o $PACKAGE -d $TARGET_DIR/
    TRUE_VERSION=$(cat $TARGET_DIR/version)
    sudo chmod a+x $TARGET_DIR/$TRUE_VERSION/update_install
    sudo bash $TARGET_DIR/$TRUE_VERSION/update_install
  • 适用于托管实例(非阿里云服务器)

    #!/bin/bash
    
    VERSION=latest
    PACKAGE=
    PKG_URI=
    
    DOMAIN=aliyun-client-assist.oss-accelerate.aliyuncs.com
    
    arch=$(uname -m)
    echo "[main] arch = ${arch}"
    case $arch in
        "i386"|"i686"|"x86_64"|"amd64")
            PACKAGE="aliyun_assist_${VERSION}_update.zip"
            PKG_URI="https://$DOMAIN/linux/$PACKAGE"
            ;;
        *)
            PACKAGE="aliyun_assist_${VERSION}_update_arm.zip"
            PKG_URI="https://$DOMAIN/arm/$PACKAGE"
    esac
    
    if command -v wget; then
        sudo wget $PKG_URI
    elif command -v curl; then
        curl -o $PACKAGE $PKG_URI
    else
        echo "[WARN] command wget/curl not found,exit"
        exit 1
    fi;
    
    TARGET_DIR=/usr/local/share/aliyun-assist
    sudo unzip -o $PACKAGE -d $TARGET_DIR/
    TRUE_VERSION=$(cat $TARGET_DIR/version)
    sudo chmod a+x $TARGET_DIR/$TRUE_VERSION/update_install
    sudo bash $TARGET_DIR/$TRUE_VERSION/update_install

源码安装

示例通过yum安装,如果使用其他Linux版本,请修改为对应的包管理工具。

  1. 安装GitGo等必要的软件。

    # 安装Git
    sudo yum install git -y
    
    # 安装Go
    sudo yum install go -y
  2. 下载云助手Agent源码。

    sudo git clone https://github.com/aliyun/aliyun_assist_client
  3. 进入源码存放目录,编译源码。

    # 进入源码存放目录
    cd ./aliyun_assist_client
    
    # 编译源码
    sudo go build

    如果返回结果无报错信息,表示安装成功。

经典网络实例安装了云助手Agent之后为什么无法使用?

对于经典网络的ECS实例,云助手Agent无法自动获取地域信息,需要手动配置,在实例内部添加所属地域声明。

经典网络是阿里云早期提供的网络类型,现已停止售卖,建议迁移到专有网络以获得更优的性能和安全性。

Linux

  1. 在云助手的安装目录下,创建名为region-id的文件,并在文件中填入ECS实例所属地域的ID。

    以杭州地域为例,在默认安装目录/opt/local/share/aliyun-assist/下创建region-id文件。

    • CoreOS操作系统:

      sudo sh -c 'echo "cn-hangzhou" > /opt/local/share/aliyun-assist/region-id'
    • 其他操作系统(Alibaba Cloud Linux、Ubuntu、Debian、RedHat、SUSE Linux Enterprise ServerOpenSUSE等):

      sudo sh -c 'echo "cn-hangzhou" > /usr/local/share/aliyun-assist/region-id'
  2. 运行云助手Agent。

    aliyun-service -d

Windows

  1. 在云助手的安装目录下,创建名为region-id的文件(不要添加类似.txt.conf的扩展名)。

    Windows系统默认隐藏已知文件类型的扩展名,需设置显示已知文件类型的扩展名以确认region-id文件是否带有扩展名。
  2. region-id文件中填入ECS实例所属地域的ID,例如cn-hangzhou

示例:Windows Server 2012 R2为例,在云助手默认安装路径C:\ProgramData\aliyun\assist\下新建的region-id文件及填入cn-hangzhou地域ID的结果如下:在Windows上添加文件