Connecting to Instaclustr Using Cqlsh

Cqlsh is a utility for running simple CQL commands on a local or remote Cassandra cluster. This article describes how cqlsh can be used to connect to clusters in Instaclustr. In this article, we assume that your cluster has been set up and provisioned properly as shown in our previous tutorial “Creating a Cluster”.

 

1.Prerequisites

Python 2.7 or later version needs to be installed. If you don’t have python installed on your local machine, please refer to the appendices at the end of this article.

You have the Cassandra binaries. Cassandra can be downloaded from http://archive.apache.org/dist/cassandra/ and we recommend Cassandra 2.1 or later. You don’t have to install Cassandra after downloading, if you only want to use cqlsh.

The public IP address of your machine must be added to the “Cassandra Allowed Addresses” in “Settings” tag under your cluster panel in the Instaclustr console.

 

2. Connecting to Instaclustr without SSL

If encryption is not enabled in your cluster, you can connect to it using cqlsh without SSL.

(1) For Mac/Linux:

Open your terminal and use the following command to connect to your cluster. Note: if authentication is not enabled in your cluster, you don’t need the options “-u” and “-p”. Username and password can be found in “Connection Info” tag under your cluster panel in Instaclustr dashboard.

For tarball installation:

Cassandra/bin/cqlsh public_ip_of_your_node  9042 -u username -p your_password

For package installation:

cqlsh public_ip_of_your_node 9042 -u your_username -p your_password

For binary/source download:

Cassandra/bin/cqlsh public_ip_of_your_node  9042 -u username -p your_password

(2) For Windows:

Run cmd.exe as administrator and enter the user home directory where your Cassandra is downloaded.

For tarball installation and binary/source download:

python Cassandra/bin/cqlsh public_ip_of_your_node 9042 -u your_username -p your_password

For package installation:

python cqlsh  public_ip_of_your_node 9042 -u your_username -p your_password

 

3. Connecting to Instaclustr with SSL

If encryption is enabled in your cluster, SSL is needed for connecting to the cluster and cqlshrc file is used to configure SSL encryption.

(1) For Mac/Linux

Open your terminal and using the following command to create a “.cassandra/cqlshrc” file in your user home directory.

cd
touch .cassandra/cqlshrc

Open the empty cqlshrc file using the following command.

vi .cassandra/cqlshrc

Copy the following content and past it into the empty cqlshrc file. Then save the file. Note: username and password can be found in and certificate file can be downloaded from “Connection Info” of Instaclustr dashboard.

[authentication]
username = your_username
password = your_password

[cql]
version = 3.2.1

[connection]
hostname = public_ip_of_your_node
port = 9042

[tracing]
max_trace_wait = 10.0

[ssl]
certfile = full_path_to_cluster-ca-certificate.pem
validate = true
factory = cqlshlib.ssl.ssl_transport_factory

Now you can start cqlsh with the --ssl option.

For tarball installation and binary download:

Cassandra/bin/cqlsh -ssl public_ip_of_your_node

For package installation:

cqlsh -ssl

For source download:

Cassandra/bin/cqlsh -ssl

(2) For Windows

Open the notepad, create a new file and name it to “cqlshrc”. Copy the following content and past it into the file. Then save the file into the “.cassandra” directory under your user home directory. Note: username and password can be found in and certificate file can be downloaded from “Connection Info” tag under your cluster panel in Instaclustr dashboard.

[authentication]
username = your_username
password = your_password

[cql]
version = 3.2.1

[connection]
hostname = public_ip_of_your_node
port = 9042

[tracing]
max_trace_wait = 10.0

[ssl]
certfile = full_path_to_cluster-ca-certificate.pem
validate = true
factory = cqlshlib.ssl.ssl_transport_factory

Now you can start cqlsh with the --ssl option.

For tarball installation or binary download:

python Cassandra/bin/cqlsh --ssl public_ip_of_your_node

For package installation:

python cqlsh --ssl

For source download:

python Cassandra/bin/cqlsh --ssl

 

4. Troubleshooting

When you try to start cqlsh, sometimes, you may encounter an error like: "cql_version '3.3.1' is not supported by remote (w/ native protocol). Supported versions: [u'3.2.1']". To quickly solve the problem, you can try to start your cqlsh with an extra option “--cqlshversion=’3.2.1’”. You can follow the example below:

For tarball installation and binary/source download:

Cassandra/bin/cqlsh --cqlshversion=’3.2.1’

For package installation:

cqlsh --ssl --cqlshversion=’3.2.1’

 

Appendices

Appendix A: Install Python on Windows

Download Python from https://www.python.org/downloads/windows/ and we recommend version 2.7 or later.

Navigate to the download location on your computer, double clicking the Python MSI file and press the "Run" button when the dialog box pops up. Then you will see the following window.

If you only have one user account on your computer, you can select the “Install for all users” option. If you have multiple accounts on your computer and don’t want to install it across all accounts, you can select the “Install just for me” option. Press the “Next” button, then you will see the following window.

If you want to change the install location, feel free to do so. However, it is best to leave it as is. Then press the "Next" button and you will see the following window.

Scroll down in the window, find the “Add Python.exe to Path”, click on the small red “x” button and choose the “Will be installed on local hard drive” option. Press the “Next” button, then the installation starts. You will notice that the installation will bring up a command prompt window. Please wait and do nothing until you see the following window.

Click the "Finish" button to exit the installer. 

If you chose Python 3.4.1 or later version, you will not need to manully add Python to System Path Variable. Then you can skip the following procedure. 

Once you have successfully installed Python, it is time to add it to the System Path Variable. Doing this will allow Python to run scripts on your computer without any conflicts of problems.

Open the start menu, search “environment” and select the option called “Edit the system environment variables.”

After the “System Properties” window pops up, select "Advanced" panel and click on “Environment Variables…”. 

After the "Environment Variables" window pops up, click the “New…” button in the "System variables" group to create a new variable for Python as shown in the following picture. Then Press the "OK" button to save the changes.

 

Appendix B: Install Python on Mac

If you already have homebrew installed on your computer, you can skip this step. Otherwise using the following commands to install homebrew.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

Once homebrew is installed, you can install Python using the following command.

brew install python

 

Appendix C: Install Python on Linux

Download Python and extract it using the following commands. 

wget --no-check-certificate https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz

tar -xzf Python-2.7.11.tgz

Build and install Python with the following commands.

cd Python-2.7.11

./configure

make
sudo make install

 

Last updated:
If you have questions regarding this article, feel free to add it to the comments below.

0 Comments

Please sign in to leave a comment.