aws上部署hadoop
First off, a deployable artifact is a snapshot or configuration for a server to be deployed. For example, an Amazon Machine Image (AMI) provides the information to launch an instance on Amazon Web Services. Deployable artifacts are sometimes referred to as "golden images", and allow operators to configure a server once and reuse that configuration to reliably and repeatably provision more servers.
首先, 可部署的工件是要部署的服务器的快照或配置。 例如,Amazon Machine Image(AMI)提供了在Amazon Web Services上启动实例的信息。 可部署的工件有时被称为“黄金映像”,并允许操作员一次配置服务器,然后重新使用该配置以可靠且可重复地配置更多服务器。
使用Packer创建AMI (Using Packer to create AMIs)
Packer by HashiCorp is a tool for creating identical machine images for multiple platforms from a single source configuration. You can write one Packer configuration to create identical machine images for AWS, Google Cloud Engine, DigitalOcean, OpenStack, and more.
HashiCorp的Packer是一个工具,可从一个源配置为多个平台创建相同的机器映像。 您可以编写一个Packer配置来为AWS,Google Cloud Engine,DigitalOcean,OpenStack等创建相同的机器映像。
In this LAMP tutorial, we use Packer to create three AMIs — one that configures Consul instances, one that configures a MySQL instance, and one that configures Apache+PHP instances. A key benefit of these AMIs is that they can be re-used with confidence that newly provisioned instances will be identically configured.
在本LAMP教程中,我们使用Packer创建三个AMI,一个用于配置Consul实例,一个用于配置MySQL实例,另一个用于配置Apache + PHP实例。 这些AMI的主要优点是可以放心地重用它们,因为新配置的实例将被相同地配置。
常规设置 (General setup)
To finish this tutorial, you will need to:
要完成本教程,您将需要:
- Clone this repository 克隆此存储库
- Create an Atlas account 创建一个Atlas帐户
- Generate an Atlas token and save as environment variable.
export ATLAS_TOKEN=<your_token>生成Atlas令牌并将其另存为环境变量。export ATLAS_TOKEN=<your_token> - In the Vagrantfile, Packer, and Terraform files, replace all instances of
<username>,YOUR_ATLAS_TOKEN,YOUR_SECRET_HERE, andYOUR_KEY_HEREwith your Atlas username, Atlas token, and AWS keys. Using "find and replace" in your text editor is probably the fastest way to do this. 在Vagrantfile,Packer和Terraform文件中,将<username>,YOUR_ATLAS_TOKEN,YOUR_SECRET_HERE和YOUR_KEY_HERE所有实例替换为Atlas用户名,Atlas令牌和AWS密钥。 在文本编辑器中使用“查找并替换”可能是最快的方法。
Packer配置概述 (Packer configuration overview)
Packer configurations have four key sections:
Packer配置包含四个关键部分:
- builders 建设者
- provisioners 供应者
- post-processors 后处理器
- push 推
The builders section defines the type of artifact to be created. The provisioners section defines what steps will be run to configure the artifact itself. The post-processors section defines what to do with the artifact once it is created. Finally, the push section defines how the build configuration is sent, stored, and versioned in Atlas.
构建器部分定义了要创建的工件的类型。 供应者部分定义将运行哪些步骤来配置工件本身。 后处理器部分定义了工件创建后的处理方式。 最后, 推送部分定义如何在Atlas中发送,存储和版本化构建配置。
For more information on Packer and its configurations, read through the Packer documenation.
有关Packer及其配置的更多信息,请阅读Packer文档 。
步骤1:使用Packer和Atlas构建Apache + PHP AMI (Step 1: Use Packer and Atlas to build an Apache+PHP AMI)
The first thing to do is to build an AMI with Apache and PHP installed. To do this, run this in the ops directory:
首先要做的是使用安装的Apache和PHP构建AMI。 为此,请在ops目录中运行此命令:
packer push -create apache-php.json
This will send the build configuration to Atlas so it can remotely build your AMI with Apache and PHP installed.
这会将构建配置发送到Atlas,以便它可以在安装了Apache和PHP的情况下远程构建AMI。
View the status of your build in the Operations tab of your Atlas account. This creates an AMI with Apache and PHP installed, and now you need to send the actual PHP application code to Atlas and link it to the build configuration. You can easily do this from the app directory with vagrant by running the following command:
在Atlas帐户的“操作”选项卡中查看构建状态。 这将创建一个安装了Apache和PHP的AMI,现在您需要将实际PHP应用程序代码发送到Atlas,并将其链接到构建配置。 您可以通过运行以下命令轻松地从app目录中的vagrant中执行此操作:
vagrant push
This will send your PHP application, which is just the test.php file for now. Next, link the PHP application with the Apache+PHP build configuration by clicking on your build configuration, then "Links" in the left navigation. Complete the form with your username, "php" as the application name, and "/app" as the destination path.
这将发送您PHP应用程序,该应用程序现在仅是test.php文件。 接下来,通过单击构建配置,然后单击左侧导航中的“链接”,将PHP应用程序与Apache + PHP构建配置链接。 使用您的用户名,“ php”作为应用程序名称以及“ / app”作为目标路径来填写表格。
Now that your application and build configuration are linked, simply rebuild the Apache+PHP configuration and you will have a fully-baked AMI with Apache and PHP installed and your application code in place. When an AWS instance is provisioned using this AMI, the instance will be fully configured and have your application code on it.
现在,您的应用程序和构建配置已链接在一起,只需重新构建Apache + PHP配置,您将拥有安装了Apache和PHP的完全成熟的AMI,并且您的应用程序代码已经就绪。 使用此AMI设置AWS实例后,该实例将被完全配置并在其上添加您的应用程序代码。
步骤2:使用Packer和Atlas构建Consul AMI (Step 2: Use Packer and Atlas to build a Consul AMI)
Now we're going to build an AMI with Consul installed. To do this, navigate to the ops directory and run:
现在,我们将安装Consul来构建AMI。 为此,请导航至ops目录并运行:
packer push -create consul.json
This will send the build configuration to Atlas so it can build your Consul AMI remotely. You can view the status of your build in the Operations tab of your Atlas account.
这会将构建配置发送到Atlas,以便可以远程构建Consul AMI。 您可以在Atlas帐户的“操作”选项卡中查看构建状态。
步骤3:使用Packer和Atlas构建MySQL AMI (Step 3: Use Packer and Atlas to build a MySQL AMI)
Now, let's build an AMI with MySQL installed. To do this, we can run the following code from the ops directory:
现在,让我们构建一个安装有MySQL的AMI。 为此,我们可以从ops目录运行以下代码:
packer push -create mysql.json
This will send the build configuration to Atlas so it can build your MySQL AMI remotely. Again, you can view the status of your build in the Operations tab of your Atlas account.
这会将构建配置发送到Atlas,以便它可以远程构建MySQL AMI。 同样,您可以在Atlas帐户的“操作”选项卡中查看构建状态。
评论 (Review)
In your Atlas account there are now three deployable artifacts:
在您的Atlas帐户中,现在有三个可部署的工件 :
- an AMI with Apache+PHP and your application code configured 带有Apache + PHP的AMI,并配置了您的应用程序代码
- an AMI with MySQL configured 配置了MySQL的AMI
- an AMI with Consul master configured 配置了Consul主服务器的AMI
The next step is provisioning infrastructure on AWS using these artifacts as source configurations. Before that step, it's important to understand how each of these services will connect once deployed.
下一步是使用这些工件作为源配置在AWS上配置基础架构。 在执行此步骤之前,重要的是要了解一旦部署这些服务将如何连接。
For LAMP to work properly in a distributed system, the servers running Apache+PHP must know which servers are running MySQL. To accomplish this, we use Consul and Consul Template. Any time a server is created, destroyed, or changes in health state, the PHP configuration updates to match by using the Consul Template php.ctmpl. Pay close attention to the database connection details:
为了使LAMP在分布式系统中正常工作,运行Apache + PHP的服务器必须知道哪些服务器正在运行MySQL。 为此,我们使用Consul和Consul Template 。 每当服务器创建,销毁或运行状况发生变化时,PHP配置都会通过使用Consul Template php.ctmpl进行更新以匹配。 请密切注意数据库连接详细信息:
$password = "password";{{range service "mysql.database"}}
$hostname = "{{.Address}}"{{end}};
Consul Template will query Consul for all "database" servers with the tag "mysql", and then iterate through the list to populate the PHP configuration. When rendered, my.cnf will look like:
Consul模板将使用标签“ mysql”向Consul查询所有“数据库”服务器,然后遍历列表以填充PHP配置。 呈现后, my.cnf将如下所示:
$password = "password";
$hostname = "172.29.28.10";
This setup allows us to destroy and create Apache+PHP servers with confidence that their configurations will always be correct and they will always write to the proper MySQL instances. You can think of Consul and Consul Template as the connective webbing between services.
此设置使我们可以确信并销毁并创建Apache + PHP服务器,这些服务器的配置将始终正确,并且将始终写入正确MySQL实例。 您可以将Consul和Consul模板视为服务之间的连接网。
下一步 (Next Steps)
Now that the deployable artifacts are fully configured, the next and final step is provisioning infrastructure on AWS using these deployable artifacts. This will be walked-through in our next and final article in the Getting Started with Atlas series.
现在已经完全配置了可部署工件,下一步也是最后一步是使用这些可部署工件在AWS上配置基础架构。 这将在“ Atlas入门”系列的下一篇也是最后一篇文章中逐步介绍。
翻译自: https://scotch.io/tutorials/build-deployable-artifacts-with-packer
aws上部署hadoop
本文介绍如何使用HashiCorp的Packer工具为多个平台创建一致的机器映像,包括AWS、Google Cloud Engine等。并通过创建Apache+PHP、Consul和MySQL的AMI,展示如何在Atlas工作流中构建和配置LAMP堆栈。
:使用Packer构建可部署工件&spm=1001.2101.3001.5002&articleId=107546135&d=1&t=3&u=263fd637503845d6a23d01a9b939c442)
242

被折叠的 条评论
为什么被折叠?



