如何火EC2实例并上传/运行启动脚本上的每个人? [英] How to fire EC2 instances and upload/run a startup script on each of them?

查看:186
本文介绍了如何火EC2实例并上传/运行启动脚本上的每个人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要自动启动了一套Linux的EC2实例的。

I want to automate the launch of a set of Linux EC2 instances.

基本上,我想编写一个脚本/程序将:

Basically, I want to write a script/program that would :

  • 在实例化n个矿井一个给定的急性心肌梗死。
  • 对于每个启动例如,它会上传自定义脚本,让脚本运行到该实例。

使用VMware,我通常会做的,使用的 vmrun 的或波动率指数SDK。

Using VMWare, I would typically do that using vmrun or the Vix SDK.

什么是亚马逊AWS的选项/ EC2?

What are the options in Amazon AWS/EC2?

推荐答案

答案取决于有点什么AMI正在运行所提供的功能是完全AMI依赖。

The answer depends a bit on what AMI you are running as the features provided are entirely AMI dependent.

亚马逊Linux的非盟特派团和Ubuntu官方的AMI安装href="https://help.ubuntu.com/community/CloudInit">云初始化包用户数据脚本。

The Amazon Linux AMIS and the official Ubuntu AMIs have the cloud-init package installed. This has a number of ways you can trigger startup actions, but the one that matches your request most closely (and my favorite because I invented it) is the concept of a user-data script.

启动EC2实例时,您可以简单地传递任何脚本(启动这两个字符#!),作为用户的数据。这将是该实例的第一个启动以root身份运行。

You can simply pass any script (starting with the two characters #!) as the user-data when starting the EC2 instances. It will be run as root on the first boot of the instance.

有关如何工作的一个具体的例子,我在最近的一篇文章使用这个确切的方法:上传已知SSH主机密钥在EC2用户数据的脚本

For a specific example of how this works, I use this exact technique in my recent article: Uploading Known ssh Host Key in EC2 user-data Script

您也想用同样的脚本来运行一个以上的EC2实例。在EC2-运行实例命令和相关的API和Web控制台使您可以指定任意数量的实例,开始使用相同的用户数据。例如:

You also wanted to run more than one EC2 instance with the same script. The ec2-run-instances command and the related APIs and web console allow you to specify any number of instances to start with the same user-data. For example:

ec2-run-instances            \
  --instance-count 10        \
  --user-data-file $MYSCRIPT \
  --key $USER                \
  $SOMEAMI

如果您当前正在运行不具有云初始化安装了一个AMI,你可以做一个:

If you are currently running an AMI that does not have cloud-init installed, you could do one of:

  • 切换到一个AMI有云初始化安装,或

  • Switch to an AMI that has cloud-init installed, or

建立您的AMI的定制版本,有云初始化安装,或

Build a custom version of your AMI that has cloud-init installed, or

写一个更复杂的包装脚本,使所有他们正在拉开序幕后,实例ID的记录,等待所有实例移动到运行状态,等待sshd的接受连接,上传你的启动脚本每个实例,并运行在每个实例的启动脚本。

Write a more complicated wrapper script that makes a record of all of the instance ids after they are kicked off, waits for all of the instances to move to the running state, waits for the sshd to accept connections, uploads your startup script to each instance, and runs the startup script on each instance.

这篇关于如何火EC2实例并上传/运行启动脚本上的每个人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆