无法从远程计算机

时间:2018-05-02 11:10:37

标签: python amazon-ec2 cassandra

我已在默认公有子网中的Amazon Linux EC2实例上部署了Cassandra,并安装了python驱动程序。然后我能够在该EC2实例上成功运行 - https://github.com/datastax/python-driver/blob/master/example_core.py。它运作良好。

现在,我在默认公共子网中再生成一个EC2实例,在其上安装了python cassandra驱动程序,并尝试执行上述python文件,在第33行用第一个EC2的公共IP地址替换127.0.0.1完成基于单节点的cassandra安装的实例,但它失败并出现以下错误 -

[ec2-user@ip-172-31-43-142 ~]$ python example.py
2018-05-02 09:50:23,061 [WARNING] cassandra.cluster: Cluster.__init__ called 
with contact_points specified, but no load_balancing_policy. In the next 
major version, this will raise an error; please specify a load-balancing 
policy. (contact_points = ['54.244.59.178'], lbp = None)
2018-05-02 09:50:23,064 [DEBUG] cassandra.cluster: Connecting to cluster, 
contact points: ['54.244.59.178']; protocol version: 4
2018-05-02 09:50:23,064 [DEBUG] cassandra.io.asyncorereactor: Validated loop                 
dispatch with cassandra.io.asyncorereactor._AsyncorePipeDispatcher
2018-05-02 09:50:23,064 [DEBUG] cassandra.pool: Host 54.244.59.178 is now 
marked up
2018-05-02 09:50:23,067 [DEBUG] cassandra.cluster: [control connection] 
Opening new connection to 54.244.59.178
2018-05-02 09:50:23,073 [WARNING] cassandra.cluster: [control connection] 
Error connecting to 54.244.59.178:
Traceback (most recent call last):
  File "cassandra/cluster.py", line 2798, in 
cassandra.cluster.ControlConnection._reconnect_internal
    return self._try_connect(host)
File "cassandra/cluster.py", line 2820, in 
cassandra.cluster.ControlConnection._try_connect
    connection = self._cluster.connection_factory(host.address, 
is_control_connection=True)
    File "cassandra/cluster.py", line 1205, in 
cassandra.cluster.Cluster.connection_factory
    return self.connection_class.factory(address, self.connect_timeout, 
*args, **kwargs)
  File "cassandra/connection.py", line 332, in 
cassandra.connection.Connection.factory
    conn = cls(host, *args, **kwargs)
  File "/usr/local/lib64/python2.7/site- 
packages/cassandra/io/asyncorereactor.py", line 344, in __init__
    self._connect_socket()
  File "cassandra/connection.py", line 371, in 
cassandra.connection.Connection._connect_socket
raise socket.error(sockerr.errno, "Tried connecting to %s. Last error: %s" % 
([a[4] for a in addresses], sockerr.strerror or sockerr))
error: [Errno 111] Tried connecting to [('54.244.59.178', 9042)]. Last 
error: 
Connection refused
2018-05-02 09:50:23,079 [ERROR] cassandra.cluster: Control connection failed 
to connect, shutting down Cluster:
Traceback (most recent call last):
  File "cassandra/cluster.py", line 1270, in 
 cassandra.cluster.Cluster.connect
    self.control_connection.connect()
  File "cassandra/cluster.py", line 2766, in 
cassandra.cluster.ControlConnection.connect
    self._set_new_connection(self._reconnect_internal())
  File "cassandra/cluster.py", line 2809, in 
cassandra.cluster.ControlConnection._reconnect_internal
    raise NoHostAvailable("Unable to connect to any servers", errors)
NoHostAvailable: ('Unable to connect to any servers', {'54.244.59.178': 
error(111, "Tried connecting to [('54.244.59.178', 9042)]. Last error: 
Connection refused")})
2018-05-02 09:50:23,082 [DEBUG] cassandra.cluster: Shutting down Cluster 
Scheduler
2018-05-02 09:50:23,082 [DEBUG] cassandra.cluster: Shutting down control 
connection
Traceback (most recent call last):
  File "example.py", line 73, in <module>
    main()
  File "example.py", line 22, in main
    session = cluster.connect()
  File "cassandra/cluster.py", line 1247, in 
cassandra.cluster.Cluster.connect
 File "cassandra/cluster.py", line 1283, in 
cassandra.cluster.Cluster.connect
  File "cassandra/cluster.py", line 1270, in 
cassandra.cluster.Cluster.connect
  File "cassandra/cluster.py", line 2766, in 
cassandra.cluster.ControlConnection.connect
  File "cassandra/cluster.py", line 2809, in 
cassandra.cluster.ControlConnection._reconnect_internal
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', 
{'54.244.59.178': error(111, "Tried connecting to [('54.244.59.178', 9042)]. 
Last error: Connection refused")})
[ec2-user@ip-172-31-43-142 ~]$

您能提供解决方法吗?

请注意,我的安全组中已打开以下入站端口 -

  • 9142
  • 9042
  • 9160
  • 7000-7001
  • 8182
  • 10000
  • 7199
  • 7437
  • 61621
  • 80

1 个答案:

答案 0 :(得分:1)

检查你的cassandra.yaml,这可能是一个配置问题。 设置您的Cassandra以侦听本地计算机的IP地址而不是“localhost”上的连接 这是从远程客户端连接到Cassandra所必需的。

检查cassandra.yaml中的变量“listen_address”和“rpc_address”,例如:

listen_address: 54.244.59.178
rpc_address: 54.244.59.178

在设置中使用设备的IP地址。