2011-09-20 50 views
1

我正在尝试使用将要在EC2上运行的Thrift创建一个简单的客户机/服务器应用程序。Python Thrift RPC在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 

我在两台机器上为我的安全组设置了0.0.0.0/0端口9090。我也试过UDP,它没有修复它。我究竟做错了什么?

更新:

回答

4

我hazarding猜测,当你的EC2实例(“节点1”)的一个尝试的RPC调用其他EC2实例(“节点2”),节点2返回它的内部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.

下面是一些例子说明了掏如何返回的值不同,比较在您使用一台机器亚马逊以外的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:

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

实际上问题是我在本地主机上运行我的服务器,没有0.0.0.0。只要我做了开关,并使用弹性ip调用客户端,服务器正在运行,那么一切都很好! – josephmisiti

+0

啊,我明白了。谢谢你让我知道! –