0

I have deployed Cassandra on Amazon Linux EC2 instance in default public subnet, and have installed python driver. Then I am able to successfully run - https://github.com/datastax/python-driver/blob/master/example_core.py on that EC2 instance. It worked fine.

Now, I spawned one more EC2 instance in default public subnet, have installed python cassandra driver on it, and have tried to execute the above-mentioned python file replacing 127.0.0.1 at line 33 with public IP address of the first EC2 instance where single node based cassandra installation is done, but it fails with the following error -

[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 ~]$

Can you please provide tips to resolve it?

Please note that the following inbound ports are open in my security group -

  • 9142
  • 9042
  • 9160
  • 7000-7001
  • 8182
  • 10000
  • 7199
  • 7437
  • 61621
  • 80
Martin
  • 190
  • 5
  • 14
  • What version of Cassandra are you running here and can you add to your question the output of `netstat -lnt` please? – markc May 02 '18 at 15:28
  • does your cassandra work as a systemd service? – pkisztelinski May 03 '18 at 13:16
  • https://stackoverflow.com/questions/26892330/cassandra-datastax-enterprise-using-amazon-elastic-ip/27256965#27256965 I think this is still valid advice – LHWizard May 04 '18 at 13:23

1 Answers1

1

Check your cassandra.yaml, it ca be a configuration problem. Set your Cassandra to listen for connections on the local machine’s IP address instead of on “localhost” This is required to connect to Cassandra from remote clients.

Check the variables “listen_address” and “rpc_address” in the cassandra.yaml, e.g:

listen_address: 54.244.59.178
rpc_address: 54.244.59.178

Use your machine’s IP address in your setup.

Andrea Nagy
  • 1,201
  • 9
  • 21
  • for clouds it's usually recommended to listen on private address, and also listen on broadcast address... – Alex Ott May 02 '18 at 13:52
  • in some cases you might want to broadcast the public IP especially in the case of the DS drivers, listen address has to be an ip on the machine that the cassandra process can bind to, on AWS the node will fail to startup if you set the above to to public IP as this is a NAT-ed IP and not present on the instance – markc May 02 '18 at 15:31