24

I installed Cassandra on OSX. When trying to run cqlsh from /bin/, I get the following error:

> Connection error: ('Unable to connect to any servers', {'127.0.0.1':
> ConnectionShutdown('Connection <AsyncoreConnection(4522252560)
> 127.0.0.1:9160 (closed)> is already closed',)})

I had difficulty installing Cassandra, and had used brew install cassandra, installed DSE from datastax, and downloaded a binary from Apache.

Haim Raman
  • 10,340
  • 6
  • 39
  • 62
Peter Dietz
  • 2,349
  • 1
  • 19
  • 22

16 Answers16

41

I think the issue was the result of having a previous installation that wasn't properly uninstalled. My user .cassandra directory had some default configs, that must have been for a different version, and prevented cqlsh from starting.

rm -Rf ~/.cassandra

After that, I could run cqlsh properly.

$ bin/cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 2.1.2 | CQL spec 3.2.0 | Native protocol v3]
Use HELP for help.
cqlsh> 
muru
  • 4,232
  • 30
  • 69
Peter Dietz
  • 2,349
  • 1
  • 19
  • 22
  • 2
    I've had that problem too and just learned it's actually the cqlshrc file in the ~/.cassandra directory that I created and configured to use the old port 9160. – catpaws Nov 19 '14 at 00:49
  • +1 @catpaws is probably right in that it was the default .cqlshrc file. Good job on getting it fixed. FYI, as of 2.1.1 cqlsh has the ability to source-in a specific (or custom) .cqlshrc file, which can be useful when working with multiple installs/versions: https://issues.apache.org/jira/browse/CASSANDRA-7131 – Aaron Nov 19 '14 at 04:01
  • The uninstall seems greatly flawed. I had to delete a few things. Thanks for this as it solved my problem. – KingOfHypocrites Jun 08 '15 at 02:51
  • Thank you. You saved me several hours of troubleshooting – sat Jan 31 '19 at 23:55
  • In the same case same problem I am facing but the solution is not helps me. Anybody has idea on this? – Tejas Ratunawar Aug 27 '19 at 05:54
13

Running cassandra helped me to troubleshot the problem:

> cassandra
Cassandra 3.0 and later require Java 8u40 or later.

and:

> java -version
java version "1.7.0_95"
OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-3)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)

After installing Java 8 it worked.

Eric Saboia
  • 1,214
  • 12
  • 14
7

Cassandra-2.1 uses 9042 as cqlsh port.Connect on this it is default port.If you want to connect on 9160 port then change it by setting environment variable CQLSH_PORT and CQLSH_HOST but for setting this you have to change rpc_port from default 9160 to any other port.

7

Well, I faced same issue and this is what i did on Mac.

$cd /usr/local/Cellar/cassandra/3.10_1/bin/     

Or wherever your cassandra is installed.

$cassandra 

this initializes all configuration in your local system to start cassandra.

$./cqlsh 

This lets you enter cql query mode.

nik_7
  • 127
  • 1
  • 5
  • 7
    I get this error `Connection error: ('Unable to connect to any servers', {'127.0.0.1': error(61, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})` – awavi Sep 22 '17 at 16:41
  • No I actually ended up not using Cassandra – awavi Jan 15 '19 at 18:34
  • cassandra command will just start up a cassandra cluster. It does not initialize any local configuration. – GhostCode Feb 13 '20 at 13:11
5

I resolved this in DSE-5.0 by editing below file:

vi ~/.cassandra/cqlshrc 

And editing below configs to current IP address (192.168.1.6) of the machine I am running. In my case it's my MacBook.

[connection]
hostname = 192.168.1.6
port = 9042
; factory = cqlshlib.kerberos_ssl.kerberos_ssl_transport_factory

; [kerberos]
; hostname = 192.168.1.6
; service = cassandra
; optional
; principal = bill/cassandra-admin@foo.example.com

I hope it will help someone.

Thanks,

Chandan

Chandan Patra
  • 473
  • 2
  • 8
  • 18
4

I faced this issue when I was trying to connect to Cassandra 2.0.1 version using cqlsh 5.0.1 [cqlsh 4.1.1 | Cassandra 2.0.11.83 | CQL spec 3.1.1 | ] [cqlsh 5.0.1 | Cassandra 2.1.2 | CQL spec 3.2.0 ]

This is just one of the reasons for the error "Connection error: ('Unable to connect to any servers',".

When I used the cqlsh client compatible with Cassandra 2.0.1, I was able to connect to the cluster.

Hope this helps to find the root cause.

Karan
  • 41
  • 3
2

Just add/modify the following into the cassandra.yaml:

 rpc_address: 127.0.0.1
 seeds: "127.0.0.1"
 listen_address: 127.0.0.1

Note that, the values in all these fields must be same. That means, if you are pointing to a static IP, then the same IP should be used. And if you are just pointing the localhost, then localhost must be used in all fields.

KayV
  • 9,560
  • 8
  • 68
  • 111
  • 1
    Thank you! In my case, seeds were set to "127.0.0.1". Change it to the same IP address as `listen_address` it worked. – Devy Jan 31 '20 at 04:27
2

I got the same error after moving from Java 8 to Java 11. From https://github.com/nosan/embedded-cassandra/issues/21, Apache Cassandra does not yet have support for java 11.

Reverting to the system's current java version to Java 8 solved the problem.

0

I got myself into a mess so here was my scenario if anyone else runs into it:

  1. I followed this tutorial http://www.datastax.com/2012/01/working-with-apache-cassandra-on-mac-os-x (which is somewhat outdated).
  2. I got everything installed and working - all good. Then I decided to download Datastax Enterprise tools to try them out
  3. Ran into errors during the install but the install went through. Again following the tutorial above, tried running the ./datastax-agent program and it failed. Decided to just bag it so ran their uninstaller in their installation folder.
  4. Tried to go back to original cassandra folder (what I had working in step 2) and run "sudo ./cassandra" then I started getting JMX error (message "Unable to bind JMX, is Cassandra already running?") which led me to this link about changing the port which i did (not really fixing the issue but working around it) run two cassandra versions in the same machine.
  5. Got the server service running underneath a new port but when trying to connect with the client "sudo ./cqlsh" would not work (would get "Error=none" or destination not found).
  6. Did the remove step @Peter mentioned above and tried again and still did not work.
  7. Decided to go back and see what was holding onto the original port cassandra was using which I changed in step 4 Who is listening on a given TCP port on Mac OS X?
  8. Determined that JAVA.app was hanging onto it so killed it within Activity Monitor.
  9. Reran the remove command @Peter mentioned above again and decided to download the stable release (v2.0.13) instead of the dev release and walk through the tutorial from step 1 again.
  10. Exited and re-opened terminal. Ran "sudo ./cassandra" - worked perfect running under standard ports. Open another terminal window and ran "sudo ./cqlsh" and this also worked correctly.

I believe between Java hanging onto the default port 9042 (maybe from the DataStax install errors), version/host/port settings within ~/.cassandra/cqlshrc and using the dev version of cassandra these were all causing me fits.

Community
  • 1
  • 1
Chris Smith
  • 661
  • 7
  • 16
  • 1
    Sounds like a fun Cassandra battle. But yeah, my similar experience was just following any guide that might get it working, which is just digging myself deeper. I suppose, you could reboot your pc. To find out who is listening to port 9042, you could run this: `sudo lsof -i -n -P | grep TCP | grep 9042` and to kill that process `kill -9 51014` where 51014 is the process ID from previous. Another trick to find out what Java processes are running is `jps` or `ps aux | grep java` or `ps aux | grep cassandra` . – Peter Dietz Mar 18 '15 at 13:22
  • Thanks. I found out in my case that Apache was listening, because I was using the Cassandra PHP driver and the Python driver together. Isn't that possible? I mean you can also connect multiple MySQL connections to the same server right? – danger89 Sep 22 '15 at 19:40
0

I was having trouble connecting Cassandra from the terminal

[Cassandra image]

and then I tried to connect using /usr/local/Cellar/

[Cassandra image]

and then invoke cassandra. Then opened a new terminal and typed cqlsh the Cassandra started.

Hope this may also applicable one to resolve Cassandra issue.

Hitesh
  • 3,092
  • 8
  • 33
  • 50
PET_Maya
  • 1
  • 1
0

install java jdk and Set JAVA_HOME in Environment Variables or set JAVA_HOME = java path in command prompt.

after

run cassandra.bat

it will show the logs if you get any error

0

You need to start Cassandra form the install_location's bin directory. For example, this command will start Cassandra in the foreground:

$ ./cassandra -f

Then open another terminal tab (command + t) and run cqlsh

$ ./cqlsh
0

Ensure that DEFAULT_HOST = '127.0.0.1' in script cqlsh.py is pointing to the node IP where you have done your cassandra installation. In my case I had installed cassandra on 10.160.1.5, edited above file and it started working.

0

Running cqlsh gets this error for me but running bin/cqlsh from the cassandra directory works.

Tanya Branagan
  • 381
  • 1
  • 7
  • 17
0

I faced the same issue. I ran cassandra.bat --> This appears to have started the server. Then I opened a new command prompt (run as an administrator), changed directory to the cassandra/bin location. When I ran the command cqlsh, voila it worked!

-1

I was having the same problem with Cassandra configured with SSL. cqlsh --ssl Solves connects correctly.

adrianlzt
  • 1,484
  • 14
  • 11
  • It asks for a certificate: `Validation is enabled; SSL transport factory requires a valid certfile to be specified. Please provide path to the certfile in [ssl] section as 'certfile' option in /Users/myuser/.cassandra/cqlshrc (or use [certfiles] section) or set SSL_CERTFILE environment variable.` – awavi Sep 22 '17 at 16:43