Set up and Configure Apache Cassandra on Ubuntu 20.04

In this article, we want to teach you how to Set up and Configure Apache Cassandra on Ubuntu 20.04.

Apache Cassandra is a highly scalable, high-performance distributed database designed to handle large amounts of data across many commodity servers, providing high availability with no single point of failure. It is a type of NoSQL database.

How To Set up and Configure Apache Cassandra on Ubuntu 20.04

To install Apache Cassandra, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article about the Initial Server Setup with Ubuntu 20.04.

In this guide, you will install Java, enable the Apache Cassandra repository, import the repository GPG key, and install the Apache Cassandra server.

Let’s see how to do it.

Install Java on Ubuntu 20.04

First, update your local package index with the following command:

sudo apt update

The latest stable version of Apache Cassandra is 3.11 and it requires OpenJDK 8 to be installed on the system. To install OpenJDK 8 run the following command:

sudo apt install openjdk-8-jdk

Now verify your Java installation by checking its version:

java --version

In your output you will see:

Output
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~20.04-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)

Here you can start to install Apache Cassandra on Ubuntu 20.04.

Install Apache Cassandra on Ubuntu 20.04

First of all, you need to install the dependencies necessary to add a new repository over HTTPs:

sudo apt install apt-transport-https

Then, import the repository’s GPG key and add the Cassandra repository with the following commands:

$wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
$sudo sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 311x main" > /etc/apt/sources.list.d/cassandra.list'

When you have enabled the repository, update your local package again:

sudo apt update

Then, install Apache Cassandra with the command below:

sudo apt install cassandra

After your installation is completed, Apache Cassandra will start automatically. Verify your installation with the following command:

nodetool status

In your output you will see:

Output
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load       Tokens       Owns (effective)  Host ID                               Rack
UN  127.0.0.1  103.65 KiB  256          100.0%            e977023b-7dd7-4e89-9ee7-aaa4c45df51c  rack1

Now you have Cassandra service up and running on your server.

Configure Apache Cassandra

Apache Cassandra’s configuration files are located in /etc/cassandra.

Cassandra is configured to listen on localhost.

If the client connecting to the database is also running on the same host you don’t need to change the default configuration file.

You can use a command-line utility that comes with the Cassandra to interact with it:

cqlsh

In your output you will see:

Output
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.11 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh>

Note: If you run the cqlsh and face with the below error and something similar to this:

Traceback (most recent call last):
File "/usr/bin/cqlsh.py", line 169, in <module>
from cqlshlib import cql3handling, cqlhandling, pylexotron, sslhandling, cqlshhandling
ImportError: No module named cqlshlib

First, you need to find the path where cqlshlib exists:

find /usr/lib/ -name cqlshlib

The path obtained (in my case) is:

/usr/lib/python3.6/site-packages/cqlshlib

Export the path using the below variable name:

export PYTHONPATH=$PYTHONPATH:/usr/lib/python3.6/site-packages/

Now you can run the cqlsh again and connect to the test cluster.

you can rename your Apache Cassandra cluster on Ubuntu 20.04.

From the Cassandra CQL terminal, run the following command to change the cluster name:

cqlsh> UPDATE system.local SET cluster_name = 'Orcacore Cluster' WHERE KEY = 'local';

Here we use Orcacore Cluster, you can replace it with your own name.

Type exit to quit from the Cassandra:

cqlsh> exit

Now you need to edit the Cassandra configuration file on Ubuntu 20.04.

Open the file with your favorite text editor:

sudo vi /etc/cassandra/cassandra.yaml

Search for the Cluster_name line and change it to:

cluster_name: 'Orcacore Cluster'

Save and close the file when you are finished.

Clear the system cache with the following command:

nodetool flush system

Restart the Apache Cassandra on Ubuntu 20.04 to apply the changes:

sudo systemctl restart cassandra

Now you can access the Cassandra CQL terminal again:

cqlsh localhost

In your output you will see that your cluster name is changed:

Connected to Orcacore Cluster at localhost:9042.
[cqlsh 5.0.1 | Cassandra 3.11.11 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh>

Type exit to exit from the cluster.

Conclusion

At this point, you learn to Install and Configure Apache Cassandra on Ubuntu 20.04.

Hope you enjoy using it.

May this article about Setting up and Configure Apache Cassandra on Centos 7 be useful for you.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular