26

I set rpc_port to the public IP address, and now I can connect to Cassandra just fine from an outside server.

However, I cannot connect from the Cassandra server itself, using cqlsh

I am getting an error.Thar are:

 Connection error: Could not connect to localhost:9160

Is there a configuration, I can change to be able to connect from the server itself ?

Aaron
  • 55,518
  • 11
  • 116
  • 132
Albert Lim
  • 311
  • 1
  • 3
  • 8

14 Answers14

21
  1. Check the cassandra.yaml file on the line with rpc_port : normally by default = 9160
  2. Login to the machine hosting cassandra
  3. Try cqlsh 127.0.0.1 9160 : should be ok in any case
  4. try cqlsh [IP of host] 9160 : if ok then cassandra reachable from lan, if ok then cassandra is not reachable from lan but only localhost 127.0.0.1
Abdullah Khan
  • 12,010
  • 6
  • 65
  • 78
LeGeekDOzoZoo
  • 402
  • 3
  • 7
  • 5
    Thank you for pointing the direction, actually in my case I found `start_rpc: false`, setting it to true fixed the problem. – Custodio Dec 02 '15 at 09:13
9

You need to connect to cassandra through the rpc_address defined in cassandra.yaml. For example, I use cqlsh 10.0.80.49 9160.

Daniel Compton
  • 13,878
  • 4
  • 40
  • 60
  • Daniel - I am trying to run `cassandra` on google cloud and want to use external IP. I specified the external address in `rpc_address` but got error when trying to start `cassandra`- `INFO [main] 2019-12-17 19:00:37,251 Server.java:159 - Starting listening for CQL clients on /xx.xx.xxx.xx:9042 (unencrypted)... Exception (java.lang.IllegalStateException) encountered during startup: Failed to bind port 9042 on xx.xx.x.xx. java.lang.IllegalStateException: Failed to bind port 9042 on x.x.x.x.x.`. Would you know what I might be doing wrong? – Manu Chadha Dec 17 '19 at 19:04
  • Sorry no, I don't know what the issue is from your description. Perhaps try the Cassandra users mailing list or other community support forums? – Daniel Compton Dec 18 '19 at 08:44
9

Consider changing /etc/cassandra.yaml:

# Whether to start the thrift rpc server.
start_rpc: false

to

start_rpc: true
Yahor
  • 639
  • 8
  • 16
Hall Newman
  • 111
  • 1
  • 1
8

if you see this in cassandra logs:

INFO  [main] 2015-07-21 12:06:27,426 CassandraDaemon.java:406 - Not starting RPC server as requested. Use JMX (StorageService->startRPCServer()) or nodetool (enablethrift) to start it

then just open a terminal and

$ nodetool enablethrift

as written in the INFO message. Should now work. Got this when my system upgraded to cassandra 2.2.0

Vincent de Lagabbe
  • 4,964
  • 3
  • 31
  • 38
5

If you are on OSX

brew install cassandra

First start the Cassandra

cassandra

Start the Cassandra Connect via CQL shell

cqlsh 127.0.0.1

enter image description here

Gajen Sunthara
  • 4,470
  • 37
  • 23
4

Maybe start cassandra on your local machine by bin/cassandra -f first?

Jun
  • 560
  • 1
  • 6
  • 17
3

It's not listening on 127.0.0.1 since you told it to only listen on <public IP>. Make the listen address 0.0.0.0 to listen on all addresses (or just omit it if possible as this is usually the default). See Listening Sockets .NET tutorial or any other socket tutorial to get a basic understanding of socket binding.

Update (@c45556037):

Note that listen_address is the one for other nodes to use to connect to this one (a misleading name). rpc_address is the actual address to locally bind to. It's unclear from the 2.0 docs and is explained better in the 1.0 docs.

Community
  • 1
  • 1
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
  • 4
    But cassandra from datastax, says not to set 0.0.0.0 to listen addres in the .yaml file itself? Why so – Gibbs Feb 20 '15 at 11:24
  • Cassandra throws an error when I do this. It is not recommended – Uzer Oct 23 '15 at 11:58
  • @JonathanKelsey without more details, your comment isn't very helpful – ivan_pozdeev Oct 23 '15 at 16:19
  • 1
    Ok, this causes an error in Cassandra 2.1.5.469. A typical yaml will have this comment about the listen address: 'Setting this to 0.0.0.0 is always wrong.' Or from the Cassandra apache FAQ we have this note 'Cassandra is a gossip-based distributed system. ListenAddress is also "contact me here address," i.e., the address it tells other nodes to reach it at. Telling other nodes "contact me on any of my addresses" is a bad idea; if different nodes in the cluster pick different addresses for you, Bad Things happen.' In short this is simply bad advice – Uzer Oct 23 '15 at 16:24
  • @JonathanKelsey Sigh. See the 2nd part, it clearly tells one to set `rpc_address` rather that `listen_address`. – ivan_pozdeev Oct 23 '15 at 20:16
1

I faced same situation while starting cqlsh . I got following error while starting cassandra

Enter only ----cassandra----- in terminal.

it will show all jars and log files . if terminal hang , just escape from it and then enter cqlsh. then it will enter to cassandra cli.

This worked for me

0

Exception connecting to localhost/9160. reason: connection refused

Connection refused to cassandra cli mode .

goto the root directory of cassandra :

bin/cassandra -- host {host-ip} --port {9160}

if you are having trouble with this , check your {cassandra-root-directory}/conf/cassandra.yaml

the thrift ip or rpc_address is the address used as the host-ip for connecting to cli . make it your local IP and if you are having trouble connecting using the port 9160 , try changing the rpc_port to 8070 and now try connecting to cassandra-cli mode using the command

bin/cassandra --host {local-IP} --port 8070

This worked for me, hope it works for you too .

tomrozb
  • 25,773
  • 31
  • 101
  • 122
user3617840
  • 67
  • 2
  • 10
0

for 2.0.5 the following works for me ..

   $CASSANDRA_HOME/bin/cqlsh xx.xx.xxx.xxx 9160
user2720864
  • 8,015
  • 5
  • 48
  • 60
0

Please execute the below query to resolve the issue

#!/bin/bash
export CASSANDRA_HOME=/opt/apache-cassandra-2.1.8
export CQLSH_HOST=192.168.1.200
export CQLSH_PORT=9042
echo $@
$CASSANDRA_HOME/bin/cqlsh $@'    

Make sure to change the IP and location of cassandra Home Directory

0

Use this command

sudo service cassandra start

to start cassandra and then use

cqlsh command
Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162
0

Consider changing /etc/cassandra-env.sh:

JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.ssl=true"
not "true" but "false"
JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.ssl=false"

sudo service cassandra restart

Master rsl
  • 46
  • 3
0

How to change default port 9042 in Cassandra ?

I resolved issue using below steps :

1) Stop cassandara services

sudo su -
systemctl stop datastax-agent
systemctl stop opscenterd
systemctl stop app-dse

2) Take backup and Change port from 9042 to 9035

cp /opt/dse/resources/cassandra/conf/cassandra.yaml /opt/dse/resources/cassandra/conf/bkp_cassandra.yaml
vi /opt/dse/resources/cassandra/conf/cassandra.yaml

native_transport_port: 9035

3) Start Cassandra services

systemctl start datastax-agent
systemctl start opscenterd
systemctl start app-dse

4) create cqlshrc file.

vi  /root/.cassandra/cqlshrc

[connection]
hostname = 198.168.1.100
port = 9035
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40