Oct 6, 2023 4 min read

How to Install Apache Cassandra on CentOS 7

Install Apache Cassandra on CentOS 7 with our step-by-step tutorial. Apache Cassandra is a powerful and scalable NoSQL database.

Install Apache Cassandra on CentOS 7
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to install Apache Cassandra on CentOS 7, let's briefly understand – What is Apache Cassandra?

Apache Cassandra is a powerful and scalable NoSQL database that efficiently handles massive amounts of data. It offers high availability and fault tolerance, making it ideal for mission-critical applications. With its decentralized architecture, Cassandra ensures seamless performance, making it a top choice for big data projects and real-time applications.

In this tutorial, you will learn how to install Apache Cassandra on CentOS 7.

Advantages of Apache Cassandra

  1. Scalability: Apache Cassandra effortlessly scales to accommodate large data volumes and traffic.
  2. High Availability: Ensures data accessibility and operational continuity even during node failures.
  3. Fault Tolerance: Maintains data integrity and reliability, preventing data loss or downtime.
  4. Flexibility: Schema-free design allows dynamic changes to data structure without disruptions.
  5. Low Latency: Offers speedy read and write operations for real-time applications and analytics.

Prerequisites to Install Apache Cassandra on CentOS 7

  • To install packages, you must be logged in as a user with sudo privileges.
  • Minimum 2GB of memory required.

Installing Apache Cassandra

Installing the rpm package from the official Apache Cassandra repository is the suggested method for installing Apache Cassandra on CentOS 7.

At the time of writing, the most recent version of Apache Cassandra is 4.1, which requires OpenJDK 8 to be installed on the system.

On your system, type the following to install OpenJDK:

sudo yum install java-1.8.0-openjdk-devel

Running the following command, which prints the Java version, will allow you to confirm the Java installation:

java -version

The output should look like the example below:

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 has been installed, adding the Apache Cassandra repository should be your next step.

Open your preferred editor, then create the repository file shown below:

sudo vi /etc/yum.repos.d/cassandra.repo

The following text should be pasted into the file::

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

Once the repository is enabled, use the following command to install the most recent version of Apache Cassandra:

sudo yum install cassandra

Launch and activate the Cassandra service:

sudo systemctl enable cassandra
sudo systemctl start cassandra

You may check if Cassandra is active by typing:

nodetool status

You will notice something like 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

Apache Cassandra has now been installed on your CentOS server.

đź’ˇ
If you got an error Error: The node does not have system_traces yet, probably still bootstrapping Then wait for some seconds and try again running the same command.

Configuring Apache Cassandra

Data for Apache Cassandra is kept in the /var/lib/cassandra directory, configuration files are found at /etc/cassandra, and Java startup options can be configured in the file /etc/default/cassandra.

Cassandra is set up by default to only listen on localhost. You don't need to modify the default configuration file if the client that is connecting to the database is also operating on the same host.

The command line tool cqlsh is included with the Cassandra package and can be used to communicate with Cassandra using CQL (the Cassandra Query Language).

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

“Test Cluster” is the default name of the Cassandra cluster. If you wish to change the name of the cluster, follow the below to these steps:

1) Using cqlsh to access the Cassandra CQL terminal:

cqlsh

The cluster name will be changed to “VegaStack Cluster” by running the command below:

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

Change “VegaStack Cluster” to the name you like. After finishing, type exit to close the console.

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

sudo vi /etc/cassandra/conf/cassandra.yaml

set cluster name:

cluster_name: 'VegaStack Cluster'

3) To clear the system cache, enter the following command:

nodetool flush system

4) After that, restart the Cassandra service:

sudo systemctl restart cassandra

5) Now, you should see the new cluster name:

cqlsh
Output

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

FAQs to Install Apache Cassandra on CentOS 7

Which Java version is compatible with Apache Cassandra?

Apache Cassandra is compatible with JDK 8. Make sure you have the correct version installed before proceeding with the installation.

How can I check if Cassandra is running?

Use the command nodetool status or sudo systemctl status cassandra to verify Cassandra's status and ensure it is running.

How to configure Cassandra for production use on CentOS 7?

For production, modify the cassandra.yaml file, located in /etc/cassandra/, to set memory, replication, and other parameters according to your requirements.

Can I access Cassandra from a remote machine?

Yes, you can. Edit the cassandra.yaml file to set the listen_address and rpc_address to the IP address of your machine to enable remote access.

How do I secure Apache Cassandra on CentOS 7?

Secure Cassandra by enabling authentication and encryption. Modify the cassandra.yaml file to configure authenticator and internode_encryption properties.

How can I backup my Cassandra data on CentOS 7?

Use the nodetool snapshot command to create backups. The snapshots are stored in the data directory, and you can copy them to a safe location.

How can I update Apache Cassandra to a newer version? 

To update Apache Cassandra to a newer version, you can follow the same steps as the installation process, but make sure to back up your data and configuration files before proceeding.

Conclusion

Apache Cassandra has been successfully installed on your CentOS 7 machine. You may now learn how to use Cassandra by visiting the official Apache Cassandra Documentation page.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.