How To Install Apache Cassandra on AlmaLinux 9

In this guide, you will learn to Install and Configure Apache Cassandra on AlmaLinux 9.

Apache Cassandra is a distributed database management system that is built to handle large amounts of data across multiple data centers and the cloud. Key features include:

  • Highly scalable
  • Offers high availability
  • Has no single point of failure

Written in Java, it’s a NoSQL database offering many things that other NoSQL and relational databases cannot.

Steps To Install and Configure Apache Cassandra on AlmaLinux 9

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with AlmaLinux 9.

Install Java on AlmaLinux 9

Apache Cassandra is written in Java, so you need to have Java installed on your server.

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

sudo dnf update -y

Then, use the command below to install OpenJDK on your server:

sudo dnf install java-1.8.0-openjdk-devel -y

Verify your Java installation by checking its version:

java -version
Output
openjdk version "1.8.0_352"
OpenJDK Runtime Environment (build 1.8.0_352-b08)
OpenJDK 64-Bit Server VM (build 25.352-b08, mixed mode)

Install Python and Pip 3

At this point, you need to install Python and Pip 3 on your server by using the command below:

sudo yum install python3 python-pip 

Then, use the pip to install cqlsh on your server:

sudo pip3 install cqlsh 

Install Apache Cassandra on AlmaLinux 9

At this point, you need to add the Cassandra repository to your server.

Add Apache Cassandra Repository

You need to create a yum repository file with your favorite text editor, here we use vi:

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

Then, add the following content for the latest version to the file:

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

When you are done, save and close the file.

Run the system update:

sudo dnf update -y

Note: If you get an error while importing GPG keys, update the crypto policies to LEGACY to ensure compatibility then reboot your system.

# sudo update-crypto-policies --set LEGACY
# sudo reboot

Install Cassandra

At this point, use the following command to install Cassandra on AlmaLinux 9:

sudo dnf install cassandra -y

Create a systemd Unit File for Cassandra

At this point, you need to create a systemd unit file to manage Cassandra on AlmaLinux 9.

Create and open the file with your favorite text editor, here we use vi:

sudo vi /etc/systemd/system/cassandra.service

Add the following content to the file:

[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

When you are done, save and close the file.

Then reload the daemon:

sudo systemctl daemon-reload

Start and enable your Cassandra service:

# sudo systemctl start cassandra 
# sudo systemctl enable cassandra

Verify your Apache Cassandra is active and running on AlmaLinux 9:

sudo systemctl status cassandra

In your output you will see:

Output
● cassandra.service - Apache Cassandra
     Loaded: loaded (/etc/systemd/system/cassandra.service; disabled; vendor pr>
     Active: active (running) since Sat 2022-12-03 05:01:02 EST; 10s ago
   Main PID: 4053 (java)
      Tasks: 24 (limit: 23157)
     Memory: 1.2G
        CPU: 11.239s
     CGroup: /system.slice/cassandra.service
...

Also, you can use the command below to check your Cassandra status:

nodetool status
Output
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load        Tokens  Owns (effective)  Host ID                               Rack
UN  127.0.0.1  104.32 KiB  16      100.0%            84dd23e9-13a0-4098-8954-b93c181cef1d  rack1

The UN option means that your service is up and normal.

Log in to your Cluster

At this point, you can log in to your cluster with the following command:

cqlsh

Your output should similar to this:

Output
Connected to Test Cluster at 127.0.0.1:9042
[cqlsh 6.1.0 | Cassandra 4.1-rc1 | CQL spec 3.4.6 | Native protocol v5]
Use HELP for help.
cqlsh>

Note: If you get this error ImportError: cannot import name ‘authproviderhandling’ from ‘cqlshlib’, you can fix it by following the steps below:

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 below variable name:

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

Then, re-run the cqlsh command.

Here that you have Apache Cassandra installed on your AlmaLinux 9, let’s see how to configure it.

Configure Apache Cassandra on AlmaLinux 9

At this point, you can change your default cluster name. From the cqlsh shell run the command below to change your cluster name. Remember to replace the name with your own.

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

Then, exit from your cluster with the following command:

cqlsh> exit

Now you need to edit the Cassandra YAML file. Open the file with your favorite text editor here we use vi:

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

Find the cluster_name directive and change it to your name:

cluster_name: 'Orca Cluster'

When you are done, save and close the file.

To apply the changes restart Apache Cassandra on AlmaLinux 9 with the following command:

sudo systemctl restart cassandra

Again log in to your cluster and you will see that it changed to the name that you have given to it:

cqlsh
Output
Connected to Orca Cluster at 127.0.0.1:9042
[cqlsh 6.1.0 | Cassandra 4.1-rc1 | CQL spec 3.4.6 | Native protocol v5]
Use HELP for help.
cqlsh>

Conclusion

At this point, you have learned to Install and Configure Apache Cassandra on AlmaLinux 9.

Hope you enjoy it.

You may be like these articles:

How To Install GitLab on Ubuntu 20.04

How To Install TensorFlow on Ubuntu 22.04

Install PostgreSQL 15 on Rocky Linux 9

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!