How to install Apache Cassandra on Ubuntu 20.04

s2 0

Apache Cassandra is a free, open source NoSQL database with no single point of failure. It offers linear scalability and high availability without compromising on performance. Apache Cassandra is used by many companies that have large, active data sets, including Reddit, NetFlix, Instagram, and Github.

This article will walk you through installing Apache Cassandra on Ubuntu 20.04.

Installing Apache Cassandra on Ubuntu is straightforward. We install Java, activate the Apache Cassandra repository, import the repository GPG key and install the Apache Cassandra server.

Install Java

At the time of this writing, the latest version of Apache is Cassandra 3.11 and requires OpenJDK 8 to be installed on the system.

Run the following command as root or user with sudo privileges to install OpenJDK:

sudo apt updatesudo apt install openjdk-8-jdk

Check the Java installation by printing the Java version:

java -version

The output should look something like this:

openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~20.04-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)

Install Apache Cassandra

Install the dependencies required to add a new repository over HTTPS:

sudo apt install apt-transport-https

Import the GPG key of the repository and add the Cassandra repository to the system:

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

Once the repository is enabled, update the package list and install the latest version of Apache Cassandra:

sudo apt updatesudo apt install cassandra

The Apache Cassandra service will start automatically after the installation process is complete. You can check it out by typing:

nodetool status

You should see something like this:

Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load    Tokens  Owns (effective)  Host ID                               Rack
UN  127.0.0.1  70 KiB  256     100.0%            2eaab399-be32-49c8-80d1-780dcbab694f  rack1

That’s it. At this point, you have Apache Cassandra installed on your Ubuntu server.

Configuring Apache Cassandra

Apache Cassandra data is stored in /var/lib/cassandra Directory, configuration files are in /etc/cassandra, and Java startup options can be found in /etc/default/cassandra File.

By default, Cassandra is configured to only listen on localhost. If the client that connects to the database is also running on the same host, you do not need to change the default configuration file.

To interact with Cassandra through CQL (the Cassandra Query Language), you can use a command line tool called. use cqlsh which comes with the Cassandra package.

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

Rename the Apache Cassandra cluster

The standard Cassandra cluster is called the “test cluster”. If you want to change the cluster name, do the following:

  1. Sign up with. at the Cassandra CQL terminal cqlsh:

    cqlsh

    Run the following command to change the cluster name to Linuxize Cluster:

    UPDATE system.local SET cluster_name = 'Linuxize Cluster' WHERE KEY = 'local';

    Change “Linuxize Cluster” with your desired name.

    When you’re done, type exit to exit the console.

  2. Open that cassandra.yaml Configuration file and enter your new cluster name.

    /etc/cassandra/cassandra.yaml
    cluster_name: 'Linuxize Cluster'

    Save and close the file.

  3. Clear the system cache:

    nodetool flush system
  4. Restart the Cassandra service:

    sudo systemctl restart cassandra

diploma

We showed you how to install Apache Cassandra on Ubuntu 20.04. You can now visit the official Apache Cassandra Documentation
Page and learn how to get started with Cassandra.

If you run into any problem or have any feedback, please leave a comment below.

Tags: