Python 无法从远程计算机连接到Cassandra服务器
我已经在默认公共子网中的AmazonLinuxEC2实例上部署了Cassandra,并安装了python驱动程序。然后我就能够在那个EC2实例上成功运行。它工作得很好 现在,我在默认公共子网中又生成了一个EC2实例,在其上安装了python cassandra驱动程序,并尝试执行上述python文件,将第33行的127.0.0.1替换为第一个EC2实例的公共IP地址,在第一个EC2实例中完成了基于单节点的cassandra安装,但失败了,错误如下-Python 无法从远程计算机连接到Cassandra服务器,python,amazon-ec2,cassandra,Python,Amazon Ec2,Cassandra,我已经在默认公共子网中的AmazonLinuxEC2实例上部署了Cassandra,并安装了python驱动程序。然后我就能够在那个EC2实例上成功运行。它工作得很好 现在,我在默认公共子网中又生成了一个EC2实例,在其上安装了python cassandra驱动程序,并尝试执行上述python文件,将第33行的127.0.0.1替换为第一个EC2实例的公共IP地址,在第一个EC2实例中完成了基于单节点的cassandra安装,但失败了,错误如下- [ec2-user@ip-172-31-43-
[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 ~]$
[ec2-user@ip-172-31-43-142~]$python example.py
2018-05-02 09:50:23061[警告]cassandra.cluster:cluster.\uuuuu init\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
指定了接触点,但没有负载平衡策略。接下来
主版本,这将引发错误;请指定负载平衡
政策(接触点=['54.244.59.178',lbp=无)
2018-05-02 09:50:23064[调试]cassandra.cluster:连接到群集,
联络点:['54.244.59.178'];协议版本:4
2018-05-02 09:50:23064[调试]cassandra.io.asyncorereactor:已验证的循环
使用cassandra.io.asyncorereactor进行调度。\u AsyncorePipeDispatcher
2018-05-02 09:50:23064[调试]cassandra.pool:主机54.244.59.178现在正在运行
标记
2018-05-02 09:50:23067[调试]cassandra.cluster:[控制连接]
打开到54.244.59.178的新连接
2018-05-02 09:50:23073[警告]cassandra.cluster:[控制连接]
连接到54.244.59.178时出错:
回溯(最近一次呼叫最后一次):
文件“cassandra/cluster.py”,第2798行,在
cassandra.cluster.ControlConnection.\u重新连接\u内部
返回自我。\u尝试连接(主机)
文件“cassandra/cluster.py”,第2820行,在
cassandra.cluster.ControlConnection.\u尝试\u连接
connection=self.\u cluster.connection\u工厂(host.address,
is_control_connection=True)
文件“cassandra/cluster.py”,第1205行,在
cassandra.cluster.cluster.connection\u工厂
返回self.connection\u class.factory(地址、self.connect\u超时、,
*args,**kwargs)
文件“cassandra/connection.py”,第332行,在
卡桑德拉。连接。连接。工厂
conn=cls(主机,*args,**kwargs)
文件“/usr/local/lib64/python2.7/site-
packages/cassandra/io/asyncorerereactor.py”,第344行,初始__
自连接插座()
文件“cassandra/connection.py”,第371行,在
卡桑德拉。连接。连接。\连接\插座
引发套接字。错误(sockerr.errno,“已尝试连接到%s。上次错误:%s”%
([a[4]表示地址中的a],sockerr.strerror或sockerr))
错误:[Errno 111]尝试连接到[('54.244.59.178',9042)]。最后的
错误:
拒绝连接
2018-05-02 09:50:23079[错误]cassandra.cluster:控制连接失败
要连接,请关闭群集:
回溯(最近一次呼叫最后一次):
文件“cassandra/cluster.py”,第1270行,在
cassandra.cluster.cluster.connect
self.control\u connection.connect()
文件“cassandra/cluster.py”,第2766行,在
cassandra.cluster.ControlConnection.connect
self.\u设置\u新连接(self.\u重新连接\u内部())
文件“cassandra/cluster.py”,第2809行,在
cassandra.cluster.ControlConnection.\u重新连接\u内部
raise NoHostAvailable(“无法连接到任何服务器”,错误)
NoHostAvailable:(“无法连接到任何服务器,{'54.244.59.178':
错误(111,“尝试连接到[('54.244.59.178',9042)]。最后一个错误:
连接被拒绝(})
2018-05-02 09:50:23082[调试]cassandra.cluster:关闭群集
调度程序
2018-05-02 09:50:23082[调试]cassandra.cluster:关闭控制
联系
回溯(最近一次呼叫最后一次):
文件“example.py”,第73行,在
main()
文件“example.py”,第22行,在main中
session=cluster.connect()
文件“cassandra/cluster.py”,第1247行,在
cassandra.cluster.cluster.connect
文件“cassandra/cluster.py”,第1283行,在
cassandra.cluster.cluster.connect
文件“cassandra/cluster.py”,第1270行,在
cassandra.cluster.cluster.connect
文件“cassandra/cluster.py”,第2766行,在
cassandra.cluster.ControlConnection.connect
文件“cassandra/cluster.py”,第2809行,在
cassandra.cluster.ControlConnection.\u重新连接\u内部
cassandra.cluster.NoHostAvailable:(“无法连接到任何服务器”,
{'54.244.59.178':错误(111,“尝试连接到[('54.244.59.178',9042)]。
最后一个错误:连接被拒绝(“}”)
[ec2-user@ip-172-31-43-142 ~]$
你能提供一些解决方法吗
请注意,以下入站端口在我的安全组中打开-
- 9142
- 9042
- 9160
- 7000-7001
- 8182
- 一万
- 7199
- 7437
- 61621
- 八十
listen_address: 54.244.59.178
rpc_address: 54.244.59.178
在设置中使用计算机的IP地址。对于云,通常建议监听私有地址,也监听广播地址…在某些情况下,您可能希望广播公共IP,尤其是在DS驱动程序的情况下,监听地址必须是计算机上cassandra进程可以绑定的IP,在AWS上,如果您将上述设置设置为公共IP,则节点将无法启动,因为这是一个NAT IP,并且不在实例上。您在这里运行的Cassandra版本是什么?您能否将
netstat-lnt
的输出添加到您的问题中?您的Cassandra是否作为systemd服务工作?我认为这仍然是有效的建议