How to Run Cassandra (Cqlsh) from Anywhere

How to run Cassandra (cqlsh) from anywhere

To get this work work, you have to add your Cassandra bin directory to your $PATH.

From a terminal prompt, check the contents of your $PATH.

$ echo $PATH

On my Ubuntu VM, this is what I see:

/usr/local/apache-maven/apache-maven-3.1.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk1.7.0_45/bin

Since you mention Python3, I'll check the location of that on my system as well:

$ which python3
/usr/bin/python3

As you can see, Python3 is in my /usr/bin directory, and /usr/bin is in my $PATH, which is why simply typing python3 works for me (and you as well).

There are a few ways to get your Cassandra bin directory into your $PATH. There is some debate about which is the "correct" way to do accomplish this. So in lieu of telling you how I would do it, I will provide a link to a question on AskUbuntu that details something like 3 ways to add a directory into your $PATH: How to add a directory to my path?

Using cqlsh with -f option

Have you tried echoing it to the command line:

echo "DESC KEYSPACE ks1; exit" | cqlsh

How to configure cassandra for remote connection

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 user@xxx.xxx.xx.xx

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

How can we install just cqlsh (just CLI) on RHEL instead of complete cassandra?

Just install it via pip:

pip install cqlsh

See propject at pypi.

Cassandra cqlsh unable to import cqlshhandling

The correct way is stated in the following answer.

Find the path where cqlshlib exists:

find /usr/lib/ -name cqlshlib

The path obtained (in my case) is:

/usr/lib/python2.7/dist-packages/cqlshlib 

Export the path using below variable name:

export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7/dist-packages/

cqlsh installed via pip DO NOT help and COPY function will lead to the following error:

'module' object has no attribute 'parse_options'

Cassandra 2.0.3 cqlsh Fail to start

ValueError: invalid literal for int() with base10:'Unknown'

It happens when you run Cassandra from sources, and version.properties file is missing. Just execute ant generate-eclipse-files in the cassandra folder, that will generate the file.



Related Topics



Leave a reply



Submit