How Do You Troubleshoot the Cassandra Problem about “Connection refused”?

Problem Scenario
You have installed Apache Cassandra on Linux.  It is deployed as a single node configuration (not a cluster).  When you run "cqlsh" you get this error:

"Connection error: ('Unable to connect to any servers', {'': error(111, "Tried connecting to [('', 9042)]. Last error: Connection refused")})"

How do you troubleshoot cqlsh when you get this message ""Tried connecting to [('', 9042)]. Last error: Connection refused")})"?

Possible solution #1
Try running this (but substitute x.x.x.x with internal IP address of the Cassandra server): cqlsh x.x.x.x

Possible solution #2
Modify /etc/cassandra/default.conf/cassandra.yaml so the rpc_address stanza uses the FQDN of the Cassandra server (as found with a hostname -f command).  Restart the Cassandra services with these commands:

sudo systemctl daemon-reload
sudo systemctl enable cassandra
sudo systemctl start cassandra

Possible solution #3
If you get cqlsh to work sometimes and not others, check /var/log/cassandra for clues.  Search for the word "error" in the .log files.  You may need to increase the amount of virtual memory or add RAM to your server.  Click this link for more information on how to add virtual memory (aka swap space).  If the server is in AWS click here for directions on how to resize it.  If the server is in GCP click here for directions on how to resize it.

Problem solution #4
You may want to see if a software firewall such as ufw or firewalld is running.  You may want to check if iptables is blocking the port.  For further network diagnosing, see this posting.  In our experience we do not see activity on port 9042 when Cassandra is properly listening and ready for a cqlsh command.

Possible solution #5
Deploy Cassandra again.  Remove the files that were deployed and created, and start over.  If you need directions for deploying Cassandra to a new, fresh Linux server, click on the link that corresponds with your distribution:

Debian or Ubuntu

Leave a comment

Your email address will not be published. Required fields are marked *