Consul 简明教程
Consul - Using Consul on AWS
在本节中,我们将学习如何在 AWS(亚马逊网络服务)中使用 Consul。
In this chapter, we will learn how to use Consul on AWS (Amazon Web Services).
Features of AWS
在 AWS 中使用 Consul 期间的一些有用功能包括 −
Some features that are useful while using Consul in AWS are −
-
Easy to maintain cluster states.
-
Scalability and High Availability.
-
Great User Interface for managing clusters across multiple datacenters.
-
Easy to use Command Line Options.
如果你正在寻找一种解决方案,可以使用这种解决方案轻松在 AWS 上使用 Docker 部署 Consul。请查看以下链接 − https://github.com/dwmkerr/terraform-consul-cluster 。
If you are looking for a solution using which we can easily deploy Consul on AWS with Docker. Check out the following link − https://github.com/dwmkerr/terraform-consul-cluster.
AWS Deployment
为了使用 AWS,我们可以首先为其创建一个 VPC。为了在 AWS 中部署 consul,我们将使用 AWS Service 提供的快速启动模板。此模板可以很容易地在以下位置找到 – https://aws.amazon.com/quickstart/architecture/consul/ 。
For using AWS, we can start by creating a VPC for it. For deploying consul in AWS, we will use a quick start template as provided by the AWS Service. This template can be easily found at – https://aws.amazon.com/quickstart/architecture/consul/.
对于本节,我们假设你已经了解了 AWS 的基础知识。AWS CloudFormation 模板将创建以下组件 −
For this chapter, we assume that you already know the basics of AWS. The AWS CloudFormation template will create the following components −
-
A VPC with public and private subnets across three Availability Zones.
-
A Seed Consul server and a Seed client along with two Auto Scaling groups.
-
You can choose to create 3, 5, or 7 servers. The number of clients is set to three by default, but it is user-configurable.
-
Dnsmasq, which is installed and configured for Consul as part of the installation.
-
A Consul cluster using bootstrap_expect option.
请查看以下说明了解不同组件如何进行互连。
Take a look at the following illustration to understand how the different components are interconnected.

Using the AWS
请确保你使用 Web 控制台已登录你的 AWS 基础设施。现在,请将下列 URL 输入浏览器窗口。输入 URL 并按下回车后,AWS 网站将打开。
Please make sure you have already signed into your AWS infrastructure using the web console. Now, please put the following URL into the browser window. Once you type in the URL and press enter, the AWS website will open.

对于此次演示,我们将选择将其部署到新的 VPC(虚拟私有云)。你始终可以在以下链接上查看你的 AWS VPC 管理 – [role="bare"] [role="bare"]https://<awsregion>.console.aws.amazon.com/vpc/home 。对于首次用户,默认区域为美国西部俄勒冈州。因此,你可以直接访问以下 URL – [role="bare"] [role="bare"]https://us-west- 2.console.aws.amazon.com/vpc/home。
For this demo, we will choose to deploy it into a new VPC (Virtual Private Cloud). You can always check your VPC Management of AWS on the following link – [role="bare"]https://<awsregion>.console.aws.amazon.com/vpc/home. For the first time users, the by-default region is West Oregon in the USA. So, you can directly visit the URL at – [role="bare"]https://us-west- 2.console.aws.amazon.com/vpc/home.

正如你所看到的,AWS 的 VPC 服务正在运行,并且你没有 VPC,即已经在你的 AWS 账户上运行/配置。现在,请根据你的选择单击 AWS 中的部署选项,以进入新的 VPC 或部署到现有 VPC。你可以在网站上查看选项,如下面的屏幕截图所示。
As you can see the VPC service of the AWS is operational and you have no VPC, i.e. already running/configured on your AWS account. Now please click on the Deploy option on AWS into a new VPC or Deploy into an existing VPC according to your choice. You can view the option on the website as shown in the following screenshot.

单击上面描述的选项后,你将看到它打开另一个窗口,类似于下面所示的窗口。
On clicking the above-described option, you can see that it opens up another window, which is similar to the one shown below.

正如你可以在模板中看到的那样,URL 已经由 AWS 代表你选择。它还让你可以自由地自定义云形成模板。如果你愿意,可以自定义它,然后单击下一步按钮以继续。
As you can see in the template, the URL is already chosen on your behalf by AWS. It also gives you the freedom to customize the cloud formation template as you like. You can customize it if you want and click on the Next Button to proceed.

正如你所看到的,这里有各种不同的值和选项可以配置。对于某些更改,你可以根据自己的选择将其重命名,以取代 HashiCorp-Consul 名称。请随时根据你的方便更改其他选项。
As you can see that, there are various different values and options that you can configure here. For some changes, you can rename it as per your choice in replacement of the name HashiCorp-Consul. Please feel free to change the other options according to your convenience.

正如你上面看到的,根据你的选择可以自定义多个选项。正如你可以在 Consul Setup(Consul 设置)部分中看到的那样,默认的 Consul Cluster(Consul 集群)实例类型是 t2.medium 。你可以更改为你的实例选择。
As you can see above, several options can be customized according to your choice. As you can see in the Consul Setup section, the default Consul Cluster instance type is t2.medium. You can change it to your choice of instance.
Note − 填充允许范围为 0.0.0.0/0,以允许任何 IP 地址。
Note − Fill the Permitted Range as 0.0.0.0/0 for allowing any IP Address.
默认情况下,consul 服务器的数量为三个。你可以将其更改为五个,以便在 consul 环境中测试更多服务器。在快速启动配置下,你可以看到 S3 bucket 也被使用并默认命名为 quick start-reference(快速启动参考)。在你完成更改后,单击屏幕底部的下一步按钮。
By default, the number of consul servers are three. You can change it to five for testing out more servers in the consul environment. Under the quick start configuration, you can see that a S3 bucket is also used and named to the quick start-reference by default. When you are done with the changes, click on the Next button at the bottom of the screen.

在上面的屏幕截图中,你可以看到有一个选项可以使用标签进行更好的识别和使用。除此之外,你还可以选择 IAM 角色,以便向其他人提供对你的 VPC Stack 的访问权限。你可以根据自己的选择选择。
In the above screenshot, you can see that there is an option to use Tags for better identification and usage. Along with it, you are also given an option to choose the IAM Role for providing access to others to your VPC Stack. You can choose according to your choice of options.
对于更高级的选项,请选择 advanced tab ,你可以在其中为你的 VPC 启用 Amazon SNS,以接收其通知。在你完成详细信息后,请转到下一步选项。
For more advanced options, please select the advanced tab, where you can enable Amazon SNS for your VPC for its notifications. Please proceed to the Next option when you have completed the details.

上面屏幕向你展示了所选 consul 栈的已审阅详细信息。你可以查看 VPC 栈的所选选项,然后转到屏幕底部,选中创建 IAM 资源的确认复选框,然后单击创建按钮以完成栈的形成。
The above screen shows you reviewed details of the consul stack which you have chosen. You can review the selected options for the VPC stack and proceed to the bottom of the screen, check the box of the acknowledgement for creation of IAM Resources and proceed to click on the Create button to complete the formation of stack.
你可以在 AWS 管理控制台的 CloudFormation Stack(CloudFormation 栈)部分下查看输出。根据 VPC 输出,你还可以按照下面屏幕截图中所示在 AWS 控制台的 VPC 部分中查看它。
You can check the output under the CloudFormation Stack section of the AWS management console. As per the VPC output, you can also check it out at the VPC Section of the AWS Console as shown in the screenshot below.

如果您仅对 Consul Template 进行测试,请务必删除您使用过的资源。您可以通过删除 CloudFormation 部分下的 CloudFormation 堆栈以及 VPC 仪表板上的 VPC 来轻松完成此操作。
If you are only testing out the Consul Template, please make sure that you delete the resources you have used. You can easily do that by deleting the CloudFormation Stack under the CloudFormation section and the VPC on the VPC Dashboard.