How to Install Apache Cassandra on CentOS 7

By 

Published on

3 min read

Install Apache Cassandra on CentOS 7

Apache Cassandra is an open-source NoSQL database with no single point of failure, providing linear scalability and high availability without compromising performance. In Cassandra, records are structured in a similar way as in the relational database with tables, rows, and columns. Apache Cassandra is used by a number of organizations including Apple, NetFlix, eBay, and Easou.

This tutorial describes how to install Apache Cassandra on CentOS 7.

Prerequisites

The user you are logged in as must have sudo privileges to be able to install packages.

Installing Apache Cassandra

The recommended way to install Apache Cassandra on CentOS 7 is by installing the rpm package from the official Apache Cassandra repository.

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

To install OpenJDK , on your system type:

Terminal
sudo yum install java-1.8.0-openjdk-devel

Verify the Java installation by running the following command which will print the Java version :

Terminal
java -version

The output should look something like this:

output
openjdk version "1.8.0_201"
OpenJDK Runtime Environment (build 1.8.0_201-b09)
OpenJDK 64-Bit Server VM (build 25.201-b09, mixed mode)

Now that Java is installed, the next step is to add the Apache Cassandra repository.

Open your editor of choice and create the following repository file:

Terminal
sudo nano /etc/yum.repos.d/cassandra.repo

Paste the following content into the file:

/etc/yum.repos.d/cassandra.repoini
[cassandra]
name=Apache Cassandra
baseurl=https://archive.apache.org/dist/cassandra/redhat/311x/
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://www.apache.org/dist/cassandra/KEYS

Once the repository is enabled, install the latest version of Apache Cassandra by typing:

Terminal
sudo yum install cassandra

Start and enable the Cassandra service:

Terminal
sudo systemctl enable cassandra
sudo systemctl start cassandra

Verify that Cassandra is running by typing:

Terminal
nodetool status

You should see something similar to this:

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.68 KiB  256          100.0%            129a9437-377d-415b-b6b2-5dc46b73a763  rack1

At this point, Apache Cassandra has been installed on your CentOS server.

Configuring Apache Cassandra

Apache Cassandra data is stored in the /var/lib/cassandra directory, configuration files are located in /etc/cassandra and Java start-up options can be configured in the /etc/default/cassandra file.

By default, Cassandra is configured to listen on localhost only. If the client connecting to the database is also running on the same host you don’t need to change the default configuration file.

To interact with Cassandra through CQL (the Cassandra Query Language) you can use a command line utility named cqlsh that is shipped with the Cassandra package.

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

Renaming Apache Cassandra Cluster

By default, the Cassandra cluster is named “Test Cluster”. Follow the steps below if you want to change the cluster name:

  1. Login to the Cassandra CQL terminal with cqlsh:

    Terminal
    cqlsh

    The following command will change the cluster name to “Linuxize Cluster”:

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

    Replace “Linuxize Cluster” with your desired name. Once done type exit to exit the console.

  2. Edit the cassandra.yaml configuration file and enter your new cluster name.

    /etc/cassandra/default.conf/cassandra.yamlyaml
    cluster_name: 'Linuxize Cluster'
  3. Run the following command to clear the system cache:

    Terminal
    nodetool flush system
  4. Finally restart the Cassandra service:

    Terminal
    sudo systemctl restart cassandra

Conclusion

You have successfully installed Apache Cassandra on your CentOS 7. You can now visit the official Apache Cassandra Documentation page and learn how to get started with Cassandra.

If you hit a problem or have feedback, leave a comment below.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page