Python Thrift RPC不在EC2上工作

2024-04-16 20:30:02 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我创建的示例对于localhost非常有用,但是当我尝试在ec2上的两台不同的机器上进行RPC调用时(这两台机器都有单独分配的弹性IP地址),它不能工作,并出现以下错误:

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,但它没有修复它。我做错什么了?在

更新:


Tags: inpy机器libpackagesusrlocaldist
1条回答
网友
1楼 · 发布于 2024-04-16 20:30:02

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

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

引用:

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.

这里有一些例子说明dig如何返回不同的值,比较了使用Amazon之外的机器ping ec2实例与使用ec2实例ping另一个ec2实例的场景实例:-在

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:

^{pr2}$

相关问题 更多 >