

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

# 使用二进制方法将本地 Go Web 应用程序迁移至 AWS Elastic Beanstalk
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method"></a>

*Suhas Basavaraj 和 Shumaz Mukhtar Kazi，Amazon Web Services*

## Summary
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-summary"></a>

此模式介绍如何将本地 Go Web 应用程序迁移至 AWS Elastic Beanstalk。应用程序迁移后，Elastic Beanstalk 会为源包构建二进制文件，并将其部署到亚马逊弹性计算云 (Amazon) 实例。 EC2

根据更换主机迁移策略，该模式的方法速度很快，并且不需要更改代码，这意味着更少的测试和迁移时间。 

## 先决条件和限制
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-prereqs"></a>

**先决条件**
+ 一个有效的 Amazon Web Services account。
+ 本地 Go Web 应用程序。
+ 包含 Go 应用程序源代码的 GitHub 存储库。如果您不使用 GitHub，还有其他方法可以为 Elasti [c Beanstalk 创建应用程序源包](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/applications-sourcebundle.html)。

**产品版本**
+ Elastic Beanstalk 支持最新 Go 版本。有关更多信息，请参阅 [Elastic Beanstalk 文档](https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html#platforms-supported.go)。

## 架构
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-architecture"></a>

**源技术堆栈**
+ 本地 Go Web 应用程序 

**目标技术堆栈**
+ AWS Elastic Beanstalk
+ Amazon CloudWatch

**目标架构*** *

![将 Go 应用程序迁移至 Elastic Beanstalk 的架构](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/cd8d660d-5621-4ea7-8f97-7a1e321c57d3/images/1df543d9-7073-43d8-abd3-f1f7e57278eb.png)


## 工具
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-tools"></a>
+ [AWS Elastic Beanstalk](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.html) 可在 Amazon Web Services Cloud 中快速部署和管理应用程序，用户不必了解运行这些应用程序的基础设施。Elastic Beanstalk 可降低管理的复杂性，但不会影响选择或控制。
+ [GitHub](https://github.com/)是一个开源的分布式版本控制系统。

## 操作说明
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-epics"></a>

### 创建 Go Web 应用程序源捆绑包 .zip 文件
<a name="create-the-go-web-application-source-bundle-zip-file"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 为 Go 应用程序创建源捆绑包。 | 打开包含 Go 应用程序源代码的 GitHub 存储库并准备源包。源捆绑包在根目录中包含 `application.go` 源文件，该文件托管 Go 应用程序的主软件包。如果您不使用 GitHub，请参阅此模式前面的 “*先决条件*” 部分，了解创建应用程序源包的其他方法。 | 系统管理员、应用程序开发人员 | 
| 创建配置文件。 | 在源捆绑包中创建 `.ebextensions` 文件夹，然后在该文件夹中创建 `options.config` 文件。有关更多信息，请参阅 [Elastic Beanstalk 文档](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html)。 | 系统管理员、应用程序开发人员 | 
|  创建源捆绑包 .zip 文件。 | 运行如下命令。<pre>git archive -o ../godemoapp.zip HEAD</pre><br />这将创建源捆绑包 .zip 文件。下载 .zip 文件并将其另存为本地文件。.zip 文件不能超过 512 MB，并且不能包含父文件夹或顶级目录。 | 系统管理员、应用程序开发人员 | 

### 将 Go Web 应用程序迁移至 Elastic Beanstalk
<a name="migrate-the-go-web-application-to-elastic-beanstalk"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 选择 Elastic Beanstalk 应用程序。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method.html)有关如何创建 Elastic Beanstalk 应用程序的说明，请参阅 [Elastic Beanstalk 文档](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.CreateApp.html)。 | 系统管理员、应用程序开发人员 | 
| 初始化 Elastic Beanstalk Web 服务器环境。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method.html) | 系统管理员、应用程序开发人员 | 
| 将源捆绑包 .zip 文件上传到 Elastic Beanstalk。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method.html) | 系统管理员、应用程序开发人员 | 
| 测试已部署的 Go Web 应用程序。 | 您将被重定向至 Elastic Beanstalk 应用程序概述页面。在概述顶部的**环境 ID** 旁边，选择结尾为 `elasticbeanstalk.com` 的 URL，以导航到您的应用程序。您的应用程序必须在其配置文件中使用此名称作为环境变量，并将其显示在网页上。 | 系统管理员、应用程序开发人员 | 

## 问题排查
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-troubleshooting"></a>


| 问题 | 解决方案 | 
| --- | --- | 
| 无法通过应用程序负载均衡器访问应用程序 | 检查包含 Elastic Beanstalk 应用程序的目标群体。如果运行状况不佳，请登录您的 Elastic Beanstalk 实例并检查 `nginx.conf` 文件配置，以验证其路由到的运行状况网址是否正确。您可能需要更改目标群组的运行状况检查 URL。 | 

## 相关资源
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-resources"></a>
+ [Elastic Beanstalk 支持的 Go 平台版本](https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html#platforms-supported.go)
+ [在 Elastic Beanstalk 中使用配置文件](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html)
+ [在 Elastic Beanstalk 中创建示例应用程序](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.CreateApp.html) 