

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

# 安装适用于 Windows 服务器的 CodeDeploy 代理
<a name="codedeploy-agent-operations-install-windows"></a>

在 Windows 服务器实例上，您可以使用以下方法之一来下载和安装 CodeDeploy 代理：
+ 使用 AWS Systems Manager （推荐）
+ 运行一系列 Windows PowerShell 命令。
+ 选择直接下载链接。
+ 运行 Amazon S3 复制命令。

**注意**  
安装 CodeDeploy 代理的文件夹是`C:\Program Data\Amazon\CodeDeploy`。确保此路径上没有目录连接或符号链接。

**Topics**
+ [使用 Systems Manager](#codedeploy-agent-operations-install-system-manager)
+ [使用 Windows PowerShell](#codedeploy-agent-operations-install-windows-powershell)
+ [使用直接链接](#codedeploy-agent-operations-install-windows-direct-link)
+ [使用 Amazon S3 复制命令](#codedeploy-agent-operations-install-windows-s3-copy)

## 使用 Systems Manager
<a name="codedeploy-agent-operations-install-system-manager"></a>

按照中的[使用安装 CodeDeploy 代理 AWS Systems Manager](codedeploy-agent-operations-install-ssm.md)说明安装代 CodeDeploy理。

## 使用 Windows PowerShell
<a name="codedeploy-agent-operations-install-windows-powershell"></a>

登录到该实例，然后在 Windows 中运行以下命令 PowerShell：

1.  要求从 Internet 下载的所有脚本和配置文件由可信发布者签名。如果系统提示您更改执行策略，请键入“**Y**”。

   ```
    Set-ExecutionPolicy RemoteSigned
   ```

1.  加载 AWS Tools for Windows PowerShell.

   ```
   Import-Module AWSPowerShell
   ```

1.  创建一个下载 CodeDeploy 代理安装文件的目录。

   ```
   New-Item -Path "c:\temp" -ItemType "directory" -Force
   ```

1. 使用`Set-AWSCredential`和`Initialize-AWSDefaultConfiguration`命令配置 AWS 凭证。有关更多信息，请参阅《* PowerShell 用户指南》AWS 工具*中的[使用 AWS 凭证](https://docs.aws.amazon.com/powershell/latest/userguide/specifying-your-aws-credentials.html)。

1.  下载 CodeDeploy 代理安装文件。
**注意**  
AWS 支持 CodeDeploy 代理的最新次要版本。目前，最新的次要版本是 1.7.x。

   要安装最新版本的 CodeDeploy代理，请执行以下操作：
   + 

     ```
     powershell.exe -Command Read-S3Object -BucketName bucket-name -Key latest/codedeploy-agent.msi -File c:\temp\codedeploy-agent.msi
     ```

   要安装特定版本的 CodeDeploy代理，请执行以下操作：
   + 

     ```
     powershell.exe -Command Read-S3Object -BucketName bucket-name -Key releases/codedeploy-agent-###.msi -File c:\temp\codedeploy-agent.msi
     ```

   *bucket-name*是包含您所在地区的 CodeDeploy 资源包文件的 Amazon S3 存储桶的名称。例如，对于美国东部（俄亥俄州）区域，请*bucket-name*替换为`aws-codedeploy-us-east-2`。有关存储桶名称的列表，请参阅[各区域的资源工具包存储桶名称](resource-kit.md#resource-kit-bucket-names)。

1.  运行 CodeDeploy 代理安装文件。

   ```
   c:\temp\codedeploy-agent.msi /quiet /l c:\temp\host-agent-install-log.txt
   ```

要检查服务是否正在运行，请运行以下命令：

```
powershell.exe -Command Get-Service -Name codedeployagent
```

 如果 CodeDeploy 代理刚刚安装且尚未启动，则在运行**Get-Service**命令后，在 “**状态**” 下，您应该会看到**Start...**：

```
Status     Name                DisplayName
------     ----                -----------
Start...   codedeployagent    CodeDeploy Host Agent Service
```

如果 CodeDeploy 代理已经在运行，则在运行**Get-Service**命令后，在 “**状态**” 下，您应该会看到**Running**：

```
Status     Name                DisplayName
------     ----                -----------
Running    codedeployagent    CodeDeploy Host Agent Service
```

## 使用直接链接
<a name="codedeploy-agent-operations-install-windows-direct-link"></a>

如果 Windows Server 实例上的浏览器安全设置提供了权限（例如，向`https://s3.*.amazonaws.com`），则可以使用您所在地区的直接链接下载 CodeDeploy 代理，然后手动运行安装程序。

链接是：

```
https://s3.region.amazonaws.com/aws-codedeploy-region/latest/codedeploy-agent.msi
```

... 您要部署应用程序的 AWS 区域在哪里。*region*

例如：

```
https://s3.af-south-1.amazonaws.com/aws-codedeploy-af-south-1/latest/codedeploy-agent.msi
```

**重要**  
从与您的 CodeDeploy应用程序相同的地区获取`.msi`文件。选择不同的区域可能会导致运行 `.msi` 文件时 `codedeploy-agent-log` 文件中出现 `inconsistent region` 错误。

## 使用 Amazon S3 复制命令
<a name="codedeploy-agent-operations-install-windows-s3-copy"></a>

如果实例上安装了，则可以使用 Amazon S3 [cp](https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html) 命令下载 CodeDeploy 代理，然后手动运行安装程序。 AWS CLI 有关信息，请参阅[AWS Command Line Interface 在微软 Windows 上安装](https://docs.aws.amazon.com/cli/latest/userguide/awscli-install-windows.html)。

Amazon S3 命令是：

```
aws s3 cp s3://aws-codedeploy-region/latest/codedeploy-agent.msi codedeploy-agent.msi --region region
```

... 您要部署应用程序的 AWS 区域在哪里。*region*

例如：

```
aws s3 cp s3://aws-codedeploy-af-south-1/latest/codedeploy-agent.msi codedeploy-agent.msi --region af-south-1
```