Cassandra CQLSH – Unable to connect to any servers Tried connecting to [(‘127.0.0.1’, 9042)

cassandralogo
When trying to connect to a node in the Cassandra Cluster using cqlsh, I get the “Unable to connect to any servers. Tried connecting to [(‘127.0.0.1’, 9042)” message.

[[email protected] ~]$ cqlsh
Connection error: ('Unable to connect to any servers', {'127.0.0.1': error(111, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused"))

However when I provide the hostname I am able to connect to the database.

[[email protected] ~]$ cqlsh test2-sandbox
Connected to Cassandra Sandbox Cluster at test2-sandbox:9042.
[cqlsh 5.0.1 | Cassandra 3.0.9.1346 | DSE 5.0.3 | CQL spec 3.4.0 | Native protocol v4] Use HELP for help.
cqlsh>

Reviewing the parameters in cassandra.yaml file, the rpc_address appears to have the hostname.

vi /etc/dse/cassandra/cassandra.yaml
# If you choose to specify the interface by name and the interface has an ipv4 and an ipv6 address
# you can specify which should be chosen using rpc_interface_prefer_ipv6. If false the first ipv4
# address will be used. If true the first ipv6 address will be used. Defaults to false preferring
# ipv4. If there is only one address it will be selected regardless of ipv4/ipv6.
rpc_address: test2-sandbox.networkfleet.com

This appears to be the problem so I changed the rpc_address to 127.0.0.1 and restarted the Cassandra node.

Modify rpc_address Parameter
# If you choose to specify the interface by name and the interface has an ipv4 and an ipv6 address
# you can specify which should be chosen using rpc_interface_prefer_ipv6. If false the first ipv4
# address will be used. If true the first ipv6 address will be used. Defaults to false preferring
# ipv4. If there is only one address it will be selected regardless of ipv4/ipv6.
rpc_address: 127.0.0.1
# rpc_interface: eth1
# rpc_interface_prefer_ipv6: false

Stop Cassandra
[[email protected] ~]$ dse cassandra-stop

Start Cassandra
[[email protected] ~]$ dse cassandra[[email protected] ~]$ CompilerOracle: dontinline org/apache/cassandra/db/Columns$Serializer.deserializeLargeSubset (Lorg/apache/cassandra/io/util/DataInputPlus;Lorg/apache/cassandra/db/Columns;I)Lorg/apache/cassandra/db/Columns;
CompilerOracle: dontinline org/apache/cassandra/db/Columns$Serializer.serializeLargeSubset (Ljava/util/Collection;ILorg/apache/cassandra/db/Columns;ILorg/apache/cassandra/io/util/DataOutputPlus;)V
CompilerOracle: dontinline org/apache/cassandra/db/Columns$Serializer.serializeLargeSubsetSize (Ljava/util/Collection;ILorg/apache/cassandra/db/Columns;I)I
CompilerOracle: dontinline org/apache/cassandra/db/transform/BaseIterator.tryGetMoreContents ()Z
....
....
INFO 15:58:12,472 HiveMetaStorePlugin.java:40 - Hive metastore version: 1
INFO 15:58:12,600 VersionBarrier.java:65 - DigestTokensManager unlocked after upgrade!

Verify Connection
I am able to login without providing the host name. This change was made to all nodes in the cluster.

[[email protected] ~]$ cqlsh
Connected to Cassandra Sandbox Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.0.9.1346 | DSE 5.0.3 | CQL spec 3.4.0 | Native protocol v4] Use HELP for help.

cqlsh> desc keyspaces;
dse_security cfs datastax_postcode_demo dse_system
solr_admin system cfs_archive system_traces
system_schema "OpsCenter" dse_perf dse_demo
system_auth dse_leases system_distributed "HiveMetaStore"

I can now connect to Cassandra using cqlsh without providing the hostname. Success!

Leave a Reply

Your email address will not be published.