How to configure cassandra for remote connection

45,657

Solution 1

Remote access to Cassandra is via its thrift port for Cassandra 2.0. In Cassandra 2.0.x, the default cqlsh listen port is 9160 which is defined in cassandra.yaml by the rpc_port parameter. By default, Cassandra 2.0.x and earlier enables Thrift by configuring start_rpc to true in the cassandra.yaml file.

In Cassandra 2.1, the cqlsh utility uses the native protocol. In Cassandra 2.1, which uses the Datastax python driver, the default cqlsh listen port is 9042.

The 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. To configure the bound address, use the rpc_address parameter in cassandra.yaml. Setting this to 0.0.0.0 will listen on all network interfaces.

Have you checked that the remote machine can connect to the Cassandra node? Is there a firewall between the machines? You can try these steps to test this out:

1) Ensure you can connect to that IP from the server you are on:

$ ssh [email protected]

2) Check the node's status and also confirm it shows the same IP:

$nodetool status

3) Run the command to connect with the IP (only specify the port if you are not using the default):

$ cqlsh xxx.xxx.xx.xx

Solution 2

How about this:

Make these changes in the cassandra.yaml config file:

start_rpc: true

rpc_address: 0.0.0.0

broadcast_rpc_address: [node-ip]

listen_address: [node-ip]

seed_provider:
  - class_name: ...
    - seeds: "[node-ip]"

reference: https://gist.github.com/andykuszyk/7644f334586e8ce29eaf8b93ec6418c4

Solution 3

Alternate solution to Kat. Worked with Ubuntu 16.04

  1. ssh into server server_user@**.**.**.**
  2. Stop cassandra if running:

    • Check if running with ps aux | grep cassandra
    • If running, will output a large block of commands / flags, e.g.

      ubuntu 14018 4.6 70.1 2335692 712080 pts/2 Sl+ 04:15 0:11 java -Xloggc:./../logs/gc.log ........

      Note 14018 in the example is the process id

    • Stop with kill <process_id> (in this case 14018)
  3. edit cassandra.yaml file to be the following

    • rpc_address: 0.0.0.0
    • broadcast_rpc_address: **.**.**.** <- your server's IP (cannot be set to 0.0.0.0)
  4. Restart cassandra ./bin/cassandra -f (from within cassandra root)
  5. Open another terminal on local machine & connect via cqlsh **.**.**.** (your server's IP) to test.

The ./bin/nodetool status address reported my localhost IP (127.0.0.1), but cqlsh remotely still worked despite that.

Share:
45,657
Obama
Author by

Obama

Entrepreneur, Software &amp; Web Developer, Web Administrator, Former Hacker ~~ when Chuck Norris needs a developer, he calls me!

Updated on September 27, 2020

Comments

  • Obama
    Obama over 3 years

    I am trying to configure Cassandra Datastax Community Edition for remote connection on windows,

    Cassandra Server is installed on a Windows 7 PC, With the local CQLSH it connects perfectly to the local server.

    But when i try to connect with CQLSH from another PC in the same Network, i get this error message:

    Connection error: ('Unable to connect to any servers', {'MYHOST': error(10061, "Tried connecting to [('HOST_IP', 9042)]. Last error: No connection could be made because the target machine actively refused it")})

    So i am wondering how to configure correctly (what changes should i make on cassandra.yaml config file) the Cassandra server to allow remote connections.

    Thank you in advance!

  • Obama
    Obama about 8 years
    Hello, Thank you for your help, actually your second point was very helpful for me to find out what was causing the issue. the nodetool status printed showed that the node isn't pointing on the local ip of the machine, then with an "ipconfig" command, i found that the machine was using the Virtualbox Ethernet Adapter. So after disabling the Virtualbox virtual adapter, the nodetool printed the true local ip and the remote connection worked for me !!! thank you again !
  • Ritesh Sinha
    Ritesh Sinha almost 6 years
    This answer is more crisp and to the point than the accepted one.
  • Nilesh
    Nilesh over 4 years
  • Amos Kosgei
    Amos Kosgei over 2 years
    This should be the accepted answer. worked like charm