Amazon EC2 中的分布式系统
我计划在 Amazon EC2 之上构建一个分布式系统。
如何获取每台机器的网络IP地址(如192.xxx.xx)?
这样,当一个新节点进入系统时,其他节点就会给出一个IP地址列表供他进行通信。
谢谢!
I'm planning to build a distributed system on top of Amazon EC2.
How can I get the network IP address of each machine (like 192.xxx.x.x)?
This way, when a new node enters the system, other nodes give a list of IP addresses for him to communicate.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用诸如 chef 或 puppet 来组织您的节点。这将允许您在实例启动时对其进行引导。
与 Amazon EC2 配合使用的方式是,它允许您传递 user-数据到每个实例——通常是某种运行命令的脚本,例如用于引导。
如果自己运行这个太困难,我会推荐这样的服务:
HTH
Use a framework like chef or puppet to organize your nodes. This will allow you to bootstrap instances as they start.
The way this works with Amazon EC2 is that it allows you to pass user-data to each instance -- generally a script of some sort to run commands, e.g. for bootstrapping.
If running this yourself is too much of an obstacle, I'd recommend a service like:
HTH
如果“节点进入系统”,我假设它连接到某个端口。这正是您获取 IP 的地方。例如,在 Java 中:
或者,您可以解析系统的 FQDN。
FQDN 取决于您的主机配置,并且可能解析为 127.0.0.1,这不是很有帮助。
作为特定于 EC2 的第三个选项,您还可以使用 AWS SDK 或 EC2 CLI:
这会返回一个公共 DNS 名称列表,这些名称在从 EC2 内部解析时解析为私有 IP(尝试将输出通过管道传输到 xargs -n1分别在 EC2 实例上或 EC2 外部进行 nslookup)。当然,您可以过滤列表以仅显示从您感兴趣的特殊 AMI 启动的实例。
If a "node enters the system" I assume that it connects to some port. And that's exactly where you get the IP from. e.g. in Java:
Alternatively, you could resolve the FQDN of your system.
The FQDN depends on your host configuration though and might resolve to 127.0.0.1 which isn't very helpful.
As a third option that's specific to EC2, you could also use the AWS SDK or EC2 CLI:
This returns a list of public DNS names that resolve to private IPs when resolved from within EC2 (try piping the output into
xargs -n1 nslookup
on an EC2 instance or outside EC2 respectively). You could of course filter the list to only show instances started from special AMIs you're interested in.