

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

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

在 Windows 服务器实例上，您可以使用以下方法之一来下载和安装 CodeDeploy 代理：
+ 使用 Amazon 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 代理 Amazon 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.  加载 Amazon Tools for Windows PowerShell.

   ```
   Import-Module AWSPowerShell
   ```

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

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

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

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

   **对于中国（北京）区域**：

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

     ```
     powershell.exe -Command Read-S3Object -BucketName aws-codedeploy-cn-north-1 -Key latest/codedeploy-agent.msi -File c:\temp\codedeploy-agent.msi
     ```

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

     ```
     powershell.exe -Command Read-S3Object -BucketName aws-codedeploy-cn-north-1 -Key releases/codedeploy-agent-###.msi -File c:\temp\codedeploy-agent.msi
     ```

   **对于中国（宁夏）区域**：

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

     ```
     powershell.exe -Command Read-S3Object -BucketName aws-codedeploy-cn-northwest-1 -Key latest/codedeploy-agent.msi -File c:\temp\codedeploy-agent.msi
     ```

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

     ```
     powershell.exe -Command Read-S3Object -BucketName aws-codedeploy-cn-northwest-1 -Key releases/codedeploy-agent-###.msi -File c:\temp\codedeploy-agent.msi
     ```

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 实例上的浏览器安全设置提供了权限（例如，向`http://*.amazonaws.com`），则可以使用直接链接下载 CodeDeploy 代理，然后手动运行安装程序。

对于中国（北京）区域：

```
[https://aws-codedeploy-cn-north-1.s3.cn-north-1.amazonaws.com.cn/latest/codedeploy-agent.msi](https://aws-codedeploy-cn-north-1.s3.cn-north-1.amazonaws.com.cn/latest/codedeploy-agent.msi)
```

对于中国（宁夏）区域：

```
[https://aws-codedeploy-cn-northwest-1.s3.cn-northwest-1.amazonaws.com.cn/latest/codedeploy-agent.msi](https://aws-codedeploy-cn-northwest-1.s3.cn-northwest-1.amazonaws.com.cn/latest/codedeploy-agent.msi)
```

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

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

对于中国（北京）区域，使用：

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

对于中国（宁夏）区域，使用：

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