Python Thrift RPC 不适用于 EC2

发布于 2024-12-06 03:40:20 字数 785 浏览 2 评论 0原文

我正在尝试使用 Thrift 创建一个简单的客户端/服务器应用程序,该应用程序将在 EC2 上运行。

我创建的示例对于 localhost 来说效果很好,但是当我尝试在 ec2 上的两台不同计算机(两台计算机都单独分配了弹性 IP 地址)之间进行 RPC 调用时,它不起作用并出现以下错误:

raceback (most recent call last):
  File "SocialQClient.py", line 25, in <module>
    transport.open()
  File "/usr/local/lib/python2.6/dist-packages/thrift/transport/TTransport.py", line 150, in open
    return self.__trans.open()
  File "/usr/local/lib/python2.6/dist-packages/thrift/transport/TSocket.py", line 90, in open
    raise TTransportException(type=TTransportException.NOT_OPEN, message=message)
thrift.transport.TTransport.TTransportException: Could not connect to <MY-ELASTIC-IP>:9090

我有我的安全组在两台机器上的 TCP 端口 9090 设置为 0.0.0.0/0。我也尝试过UDP,但没有解决这个问题。我做错了什么?

更新:

I am trying to create a simple client/server application using Thrift which is going to be run on EC2.

The example I created works awesome for localhost, but when I try to make the RPC call across two different machines on ec2 (both of which have separately allocated elastic IP addresses), it does not work with the following error:

raceback (most recent call last):
  File "SocialQClient.py", line 25, in <module>
    transport.open()
  File "/usr/local/lib/python2.6/dist-packages/thrift/transport/TTransport.py", line 150, in open
    return self.__trans.open()
  File "/usr/local/lib/python2.6/dist-packages/thrift/transport/TSocket.py", line 90, in open
    raise TTransportException(type=TTransportException.NOT_OPEN, message=message)
thrift.transport.TTransport.TTransportException: Could not connect to <MY-ELASTIC-IP>:9090

I have my security group set up for 0.0.0.0/0 for port 9090 on both machines for TCP. I tried UDP also and it did not fix it. What am I doing wrong?

Update:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把人绕傻吧 2024-12-13 03:40:20

我大胆猜测,当您的一个 ec2 实例(“node1”)尝试对另一个 ec2 实例(“node2”)进行 RPC 调用时,node2 会返回其内部 IP 地址。

参考 - http://alestic.com/2009/06/ec2-elastic-ip -内部

引用:

最后一个选项使用了弹性 IP 地址的一个鲜为人知的功能
由 Amazon EC2 实现的系统:

当 EC2 实例查询 Elastic 的外部 DNS 名称时
IP,EC2 DNS服务器返回实例的内部IP地址
当前已为其分配弹性 IP 地址。

下面的一些示例说明了 dig 如何返回不同的值,比较了您使用 Amazon 外部的计算机来 ping 一个 ec2 实例的场景与使用一个 ec2 实例来 ping 另一个 ec2 实例的场景:-

这是该弹性 IP 地址的永久外部 DNS 名称
无论您更改分配给它的实例多少次。
如果您从 EC2 外部查询此 DNS 名称,它将解析为
外部IP地址如上所示:

$ dig +short ec2-75-101-137-243.compute-1.amazonaws.com
75.101.137.243

但是,如果您从 EC2 实例内部查询此 DNS 名称,它会
将解析为它所连接到的实例的内部 IP 地址
目前已分配:

$ dig +short ec2-75-101-137-243.compute-1.amazonaws.com
10.254.171.132

I am hazarding a guess that when one of your ec2 instance ("node1") attempts the RPC call to the other ec2 instance ("node2"), node2 returns its internal IP address instead.

Reference - http://alestic.com/2009/06/ec2-elastic-ip-internal

Quote:

This last option uses a little-known feature of the Elastic IP Address
system as implemented by Amazon EC2:

When an EC2 instance queries the external DNS name of an Elastic
IP, the EC2 DNS server returns the internal IP address of the instance
to which the Elastic IP address is currently assigned.

And here's some examples which illustrates how dig returns different values, comparing the scenario where you use a machine outside of Amazon to ping an ec2 instance, versus when you use an ec2 instance to ping another ec2 instance:-

This is the permanent external DNS name for that Elastic IP address no
matter how many times you change the instance to which it is assigned.
If you query this DNS name from outside of EC2, it will resolve to the
external IP address as shown above:

$ dig +short ec2-75-101-137-243.compute-1.amazonaws.com
75.101.137.243

However, if you query this DNS name from inside an EC2 instance, it
will resolve to the internal IP address for the instance to which it
is currently assigned:

$ dig +short ec2-75-101-137-243.compute-1.amazonaws.com
10.254.171.132
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文