How to Install Apache Cassandra on CentOS 8

Apache Cassandra is a robust free and opensource NoSQL database that stores data in key-value pairs. Cassandra was initially developed by Facebook and later on acquired by Apache Foundation.

Apache Cassandra is built to provide consistency, horizontal scalability, and high availability with no single point of failure. It implements a Dynamo-style replication providing fault tolerance and guaranteeing 99.99% uptime. This makes it ideal for use in business-critical applications that cannot afford any downtime.

Some of the notable companies that implement Apache Cassandra in their environments include Netflix, Facebook, Twitter, and eBay to mention a few.

In this guide, we focus on the installation of Apache Cassandra on CentOS 8 and RHEL 8 Linux distributions.

Installing Java in CentOS 8

To start off, we are going to install OpenJDK 8 on our system which will provide Java. But first, let’s check if Java is installed. To do so, invoke the command:

$ java -version

If Java is not present on your system, you will get the output shown:

bash: java: command not found...

To install OpenJDK 8, run the following dnf command.

$ sudo dnf install java-1.8.0-openjdk-devel

This will install OpenJDK 8 alongside other dependencies as shown.

Install Java on CentOS 8
Install Java on CentOS 8

Once the installation is done, once again verify that you have installed OpenJDK as shown:

$ java -version
Verify Java Version
Verify Java Version

NOTE: If another version of OpenJDK is installed apart from OpenJDK 8, you can set the default Java version to OpenJDK 8 by running the command below.

$ sudo alternatives --config java

Thereafter, select the option that corresponds to OpenJDK 8. In the screenshot below, we have switched the default Java version from OpenJDK 11 to OpenJDK 8.

Switch Java Version in CentOS
Switch Java Version in CentOS

Installing Apache Cassandra on CentOS 8

After installing Java, we can now proceed to install Apache Cassandra. Create a new repository file for Apache Cassandra as shown below:

$ sudo vim /etc/yum.repos.d/cassandra.repo

Then add Cassandra’s repository as shown.

[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

Save and exit the repository file.

Next, install Apache Cassandra using the command:

$ sudo dnf install Cassandra
Install Apache Cassandra in CentOS
Install Apache Cassandra in CentOS

Thereafter, accept numerous GPG keys.

Once the installation is complete. Verify that Apache Cassandra has been successfully installed by running the rpm command below:

$ rpm -qi Cassandra

You will get detailed information about Apache Cassandra such as the version, release, architecture, size, license, and a brief description to mention a few.

Verify Apache Cassandra Installation
Verify Apache Cassandra Installation

Thereafter, create a systemd service file for Cassandra as shown.

$ sudo vim /etc/systemd/system/cassandra.service

Add the following lines:

[Unit]
Description=Apache Cassandra
After=network.target

[Service]
PIDFile=/var/run/cassandra/cassandra.pid
User=cassandra
Group=cassandra
ExecStart=/usr/sbin/cassandra -f -p /var/run/cassandra/cassandra.pid
Restart=always

[Install]
WantedBy=multi-user.target

Save and exit the file.

Next, start Cassandra and confirm its status by invoking the command:

$ sudo systemctl start cassandra
$ sudo systemctl status Cassandra
Verify Apache Cassandra Status
Verify Apache Cassandra Status

The output confirms that Cassandra is up and running. Additionally, you can enable Cassandra to start on boot or upon a reboot by issuing the command:

$ sudo systemctl enable Cassandra

To log in to Cassandra and interact with Cassandra Query language, we are going to use the cqlsh command-line tool. But for this to work, we need to have Python2 interpreter installed.

If you try to log in without Python2 installed, you will get the error shown below:

$ cqlsh

No appropriate python interpreter found.

Therefore, Python2 is essential and needs to be installed. To install it, run the command:

$ sudo dnf install python2

This installs Python2 alongside other dependencies as shown.

Install Python2 in CentOS
Install Python2 in CentOS

Try logging in and this time around, the login will be successful.

$ cqlsh
Cassandra Query Language Shell
Cassandra Query Language Shell

Configuring Apache Cassandra in CentOS 8

To modify Cassandra’s default settings, check out the configuration files which are found in the /etc/cassandra directory. Data is stored in /var/lib/cassandra path. Start-up options can be tweaked in the /etc/default/cassandra file.

By default, Cassandra’s cluster name is ‘Test Cluster’. You can change this to your preferred cluster name by logging in and running the command below.

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

In this example, we have set the cluster name to ‘Tecmint Cluster’.

Next, head over to the cassandra.yaml file.

$ sudo vim /etc/cassandra/default.conf/cassandra.yaml

Modify the cluster_name directive accordingly as shown below.

Set Cassandra Cluster Name
Set Cassandra Cluster Name

Save and exit the configuration file and restart the Cassandra service.

$ sudo systemctl restart Cassandra

Log in again to confirm the cluster name as shown.

This brings us to the end of this tutorial. We hope that you have succeeded in installing Apache Cassandra on CentOS 8 and RHEL 8 Linux distributions.

If you read this far, tweet to the author to show them you care. Tweet a thanks
James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

4 thoughts on “How to Install Apache Cassandra on CentOS 8”

    • Thanks Fahad for your feedback, I’m glad that this guide was beneficial. We will work on providing in-depth guides on Apache Cassandra in the near future.

      Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.