简体   繁体   English

如何在第一个实例内获取第二个ec2实例的公共DNS地址

[英]How to get the public DNS address of a second ec2 instance while inside the first instance

Building off of this question: 建立这个问题:

https://unix.stackexchange.com/questions/24355/is-there-a-way-to-get-the-public-dns-address-of-an-instance https://unix.stackexchange.com/questions/24355/is-there-a-way-to-get-the-public-dns-address-of-an-instance

I know how to get an ec2 instance's own public DNS address. 我知道如何获取ec2实例自己的公共DNS地址。 What I need is a way for this instance to get the public DNS instance of a second ec2 instance. 我需要的是此实例获取第二个ec2实例的公共DNS实例的方法。

The idea is that I will have ~50 instances running, one or two of which will be a spot instance that is constantly running. 我的想法是,我将运行约50个实例,其中一个或两个将是一直运行的竞价型实例。 All of the other worker instances need to know the spot, or master, instance's public DNS name to connect to it within my application. 所有其他辅助实例都需要知道该实例或主实例的公用DNS名称,才能在我的应用程序中连接到该实例。 How can I do this? 我怎样才能做到这一点?

On another note, is there a way I can create a backup of my spot master instance? 另一方面,是否可以创建我的竞价型主实例的备份? In case it fails, I would like to have another spot instance that immediately takes its place, but my worker ec2 instances would have to update their information about the spot instance's public dns address. 万一失败,我想立即使用另一个竞价型实例,但是我的worker ec2实例将必须更新有关竞价型实例的公共dns地址的信息。

I think the only way to get the public DNS of your other instance is by using the command line interface or Web API provided by amazon. 我认为获取其他实例的公共DNS的唯一方法是使用亚马逊提供的命令行界面或Web API。

The concrete command you need is ec2-describe-instances which provides data about public DNS settings for each instance. 您需要的具体命令是ec2-describe-instances ,它提供有关每个实例的公共DNS设置的数据。

http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-DescribeInstances.html http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-DescribeInstances.html

Of course you can do the same through the Web API: 当然,您可以通过Web API进行相同的操作:

http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeInstances.html http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeInstances.html

Regarding the backup you can map the spot instance to EBS (which is preferrable) and then make snapshot backups. 关于备份,您可以将竞价型实例映射到EBS(首选),然后进行快照备份。 The snapshot backups are still triggered manually in the amazon console (or again through command line tools and Web API). 快照备份仍可在Amazon控制台中手动触发(或再次通过命令行工具和Web API)。 Snapshots should be good for regular backups. 快照应适合常规备份。

You can also use a service like http://www.skeddly.com/ to automate your EC2 snapshot backups. 您还可以使用http://www.skeddly.com/之类的服务来自动执行EC2快照备份。

If you want to backup the full AMI image of your spot instance, so you can re-create it from scratch at a later time, or create multiple instances from the same image etc. go to the management console and do the following: 如果要备份竞价型实例的完整AMI映像,则可以在以后从头重新创建它,或者从同一映像创建多个实例,等等。请转到管理控制台并执行以下操作:

  1. Click on Instances 点击实例
  2. Select the instance you want to create an AMI from 选择要从中创建AMI的实例
  3. Click on "Actions" and select "Create Image" 点击“操作”,然后选择“创建图像”
  4. Set the Image name and other info and save 设置图像名称和其他信息并保存

An alternative is to use S3. 一种替代方法是使用S3。 When a spot instance comes up it will read its own public address and write it to a bucket in S3. 当竞价型实例出现时,它将读取自己的公共地址并将其写入S3中的存储桶。 The other instances will look up the bucket the first time they need it and use this value. 其他实例将在他们第一次需要存储桶时使用该值。 If the spot instance goes down, the workers will poll the bucket periodically until a new spot instance comes up and updates the bucket. 如果竞价型实例发生故障,工作人员将定期轮询存储桶,直到出现新的竞价型实例并更新存储桶。

Make sure to set the bucket to only allow authenticated access so only your applications can modify it. 确保将存储桶设置为仅允许经过身份验证的访问,以便只有您的应用程序才能对其进行修改。

This approach has a security advantage, as the VMs do not need access to your EC2 credentials. 这种方法具有安全性优势,因为VM不需要访问您的EC2凭据。 They only need access to a specific S3 bucket. 他们只需要访问特定的S3存储桶。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM