26

I have installed Apache Cassandra on the remote Ubuntu server. How to allow remote access for an Apache Cassandra database? And how to make a connection?

user7337271
  • 1,662
  • 1
  • 14
  • 23
user1588782
  • 293
  • 1
  • 4
  • 6

4 Answers4

47

Remote access to Cassandra is via its thrift port (although note that the JMX port can be used to perform some limited operations).

The thrift port is defined in cassandra.yaml by the rpc_port parameter, which defaults to 9160. Your cassandra node should be bound to the IP address of your server's network card - it shouldn't be 127.0.0.1 or localhost which is the loopback interface's IP, binding to this will prevent direct remote access. You configure the bound address with the rpc_address parameter in cassandra.yaml. Setting this to 0.0.0.0 says "listen on all network interfaces" which may or may not be suitable for you.

To make a connection you can use:

  • The cassandra-cli in the cassandra distribution's bin directory provides simple get / set / list operations and depends on Java
  • The cqlsh shell which provides CQL access to cassandra, this depends on Python
  • A higher level interface such as Apollo
Tyler Hobbs
  • 6,872
  • 24
  • 31
CraigJPerry
  • 973
  • 1
  • 8
  • 16
  • 1
    Can you run these commands: ps -ef | grep CassandraDaemon ; netstat -lntp | grep This will show what IP / port combo(s) your cassandra is listening on. As an aside, try to avoid telneting to the thrift port - passing in any non thrift data can lead to OutOfMemory situations (it's quite a nasty 'feature' - to test & confirm this, telnet to the thrift port type in random text, hit return, then monitor memory usage of the CassandraDaemon pid over the next few mins). – CraigJPerry Sep 03 '12 at 20:58
  • 1
    Note that Cassandra is robust to random garbage on the Thrift port since version 0.7.0 two years ago. – jbellis Sep 04 '12 at 17:36
  • Ahh ok, yeah you're right - i just tried there on a v1.1-0 instance (while [1]; do nc 127.0.0.1 9168 < /mach_kernel; done) even after 2Gb of binary data, heap usage doesn't go above 240Mb for me. I feel a bit daft now for having been perpetuating a falsehood! I live and learn :-) (p.s. great product Mr Bellis) – CraigJPerry Sep 05 '12 at 00:33
  • tcp 0 0 0.0.0.0:57621 0.0.0.0:* LISTEN 8536/java tcp 0 0 0.0.0.0:7000 0.0.0.0:* LISTEN 8536/java tcp 0 0 0.0.0.0:7199 0.0.0.0:* LISTEN 8536/java tcp 0 0 0.0.0.0:47684 0.0.0.0:* LISTEN 8536/java tcp 0 0 127.0.0.1:9160 0.0.0.0:* LISTEN 8536/java – user1588782 Sep 06 '12 at 07:35
  • My output looks like this. Seems like it's listening only localhost on port 9160, although i configured rpc_address to 0.0.0.0 What's wrong? – user1588782 Sep 06 '12 at 07:37
  • Interesting. I guess we should check the basics first: Cassandra has been restarted since applying the change? The correct Cassandra.yaml was updated? Can you confirm nothing is already listening on 9160 on the network cards ip address (netstat -an | grep 9160) - just to be doubly sure that port is available can you run (nc -l -p 9160 -v) – CraigJPerry Sep 13 '12 at 18:19
  • i have running Cassandra cluster, In that i can able to connect Cluster from some of my network System, but i am not able to connect from my system. Even while running scala class with same cluster configuration connect successfully. but while running project it give message like does nor able to open native connection to cassandra for any of cluster node. Spark version 1.5.2, Scala version : 2.11.7 Cassandra Version 3.6, Spark Cassandra Connector version 1.5.0-RC1 i am stuck on it, any help will be appreciated. – Uttam Kasundara Jun 24 '16 at 07:41
7

For anyone finding this question now, the top answer is out of date.

Apache Cassandra's thrift interface is deprecated and will be removed in Cassandra 4.0. The default client port is now 9042.

As noted by Tyler Hobbs, you will need to ensure that the rpc_address parameter is not set to 127.0.0.1 or localhost (it is localhost by default). If you set it to 0.0.0.0 to listen on all interfaces, you will also need to set broadcast_rpc_address to either the node's public or private IP address (depending on how you plan to connect to Cassandra)

Cassandra-cli is also deprecated and Apollo is no longer active. Use cqlsh in lieu of cassandra-cli and the Java driver in lieu of Apollo.

I do not recommend making the JMX port accessible remotely unless you secure it properly by enabling SSL and strong authentication.

Hope this is helpful.

Community
  • 1
  • 1
Justin Cameron
  • 611
  • 4
  • 8
6

cassandra 3.11.3

I did the following to get mine working. Changes in cassandra.yaml :

start_rpc: true

rpc_address: 0.0.0.0

broadcast_rpc_address: ***.***.***.***

broadcast_rpc_address is the address of machine where cassandra is installed

 seed_provider:
  - class_name: ...
    - seeds: "127.0.0.1, ***.***.***.***"

In seeds i added/appended the ip address of machine where cassandra was running.

I accessed it from windows using tableplus. In tableplus, I wrote the ip address of the cassandra machine, in the port section I wrote 9042 and used the username and password, which i used for ssh connection.

Amit L
  • 89
  • 1
  • 4
3

For anyone using Azure, the issue may be that you need to create a public ip address since the virtual ip points to the cloud service itself and not the virtual machine. You can find more info in this post

Community
  • 1
  • 1
KingOfHypocrites
  • 9,316
  • 9
  • 47
  • 69