How to Install Apache Cassandra on Rocky Linux 9 or 8

This guide will demonstrate how to install Apache Cassandra on Rocky Linux 9 or 8 using the command-line terminal and the official RPM repository, ensuring access to the latest builds and simplified future upgrades.

Apache Cassandra stands out in the landscape of database management systems with its exceptional capabilities tailored for handling vast amounts of data across multiple servers without a single point of failure. This open-source NoSQL database is renowned for its outstanding scalability and reliability, making it the go-to choice for businesses that prioritize high availability and performance. Its distributed architecture is designed to meet the demands of complex, big data applications, offering features such as:

  • Fault tolerance: Data is automatically replicated to multiple nodes, ensuring no single point of failure.
  • Linear scalability: Performance increases linearly as more nodes are added, with no downtime or interruption to applications.
  • Decentralized management: Every node in the cluster is independent, eliminating bottlenecks and ensuring smooth operations.
  • Flexible data storage: Cassandra accommodates all types of data, whether structured, semi-structured, or unstructured, providing flexibility in data management.
  • High performance: Designed to handle large volumes of data with minimal latency, Cassandra ensures quick response times even under heavy loads.
  • Strong consistency: Offers tunable consistency levels to balance between consistency, availability, and partition tolerance.
  • Easy data distribution: Data can be distributed across multiple data centers, supporting geographical distribution and disaster recovery strategies.
  • Robust ecosystem: Integrates seamlessly with popular programming languages and frameworks, enhancing development flexibility and efficiency.

With its ability to handle complex, scalable applications, Cassandra is ideal for scenarios requiring real-time analytics, IoT, personalization, and more. This guide transitions seamlessly into the technical nuances of installing Apache Cassandra, equipping you with the knowledge to leverage its full potential.

Now, let’s dive into the installation process.

Update Rocky Linux System Before Apache Cassandra Installation

First, before installing Apache Cassandra, it is a good idea to ensure all system packages are up-to-date to avoid any potential issues when installing the NoSQL database.

In your terminal, run the following command and upgrade any outstanding packages.

sudo dnf upgrade --refresh

Import Apache Cassandra Repository on Rocky Linux

The first step involves importing the repository for Apache Cassandra. Fortunately, you can accomplish this with a single command. The tutorial will show how to import either the 4.0 or 4.1 branches. Since the 3.xx branch is nearing its end, the tutorial will not include instructions for adding these.

4.0 Apache Cassandra RPM Import

sudo tee /etc/yum.repos.d/cassandra-4.0.repo<<EOF
[cassandra]
name=Apache Cassandra 4.0
baseurl=https://redhat.cassandra.apache.org/41x/
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://downloads.apache.org/cassandra/KEYS
EOF

4.1 Apache Cassandra RPM Import

sudo tee /etc/yum.repos.d/cassandra-4.1.repo<<EOF
[cassandra]
name=Apache Cassandra 4.1
baseurl=https://redhat.cassandra.apache.org/41x/
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://downloads.apache.org/cassandra/KEYS
EOF

5.0 Apache Cassandra RPM Import

Note: Do not install this version for production use; this is an alpha release for those wanting to test the latest from Apache Cassandra’s upcoming new release.

sudo tee /etc/yum.repos.d/cassandra-5.0.alpha.repo<<EOF
[cassandra]
name=Apache Cassandra 5.0 Alpha
baseurl=https://redhat.cassandra.apache.org/50x/
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://downloads.apache.org/cassandra/KEYS
EOF

Install Apache Cassandra on Rocky Linux via DNF Command

You can install Cassandra with the following command with the repository now imported.

sudo dnf install cassandra -y

Confirm the version installed by running the following command.

cassandra -v

Note if you see the following error importing GPG keys.

Key import failed (code 2). Failing package is: cassandra-4.1~alpha1-1.noarch
 GPG Keys are configured as: https://www.apache.org/dist/cassandra/KEYS
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'dnf clean packages'.

Change the crypto policies and set the policy to LEGACY.

sudo update-crypto-policies --set LEGACY

Sometimes, you may need to reboot for this change to occur successfully. I found you did not need to, but it is advised.

reboot

Create Apache Cassandra Systemd Service on Rocky Linux

After the installation is complete, you need to create the systemd service. Again, this is a simple task; copy and paste the following command to create the file.

sudo tee /etc/systemd/system/cassandra.service<<EOF
[Unit]
Description=Apache Cassandra
After=network.target

[Service]
Type=simple
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
EOF

You must reload the daemon to start using the Cassandra service, and you cannot skip this step.

sudo systemctl daemon-reload

Now, start the Cassandra service.

sudo systemctl start cassandra

Next, check the systemctl status of Cassandra to ensure there are no errors.

systemctl status cassandra
Terminal screenshot showing systemctl status of Apache Cassandra service on Rocky Linux 9 or 8.
Example terminal output revealing the operational status of Apache Cassandra service on Rocky Linux.

Optionally, you can enable the Cassandra service on automatic start when you start your computer or server using the following command.

sudo systemctl enable cassandra

Install Apache Cassandra Client (cqlsh) on Rocky Linux

Install Python

Before installing the Cassandra client, ensure Python is available on your system. Apache Cassandra’s client, cqlsh, is Python-based, making Python a prerequisite. Install Python on Rocky Linux by executing:

sudo dnf install python3 -y

Install PIP

Next, install PIP, Python’s package manager, required for managing Python packages. PIP is essential for installing the Cassandra Python driver. If PIP is not already installed on your system, add it by running:

sudo dnf install python3-pip -y

Install Cassandra Python Driver

The Cassandra Python driver is necessary for cqlsh to connect to the Cassandra database. This driver enables communication between the client and the database. Install the driver using PIP with the command:

pip install cassandra-driver

Installing cqlsh

With the prerequisites in place, you’re now ready to install cqlsh. This command-line interface allows for interaction with Apache Cassandra, enabling you to execute queries and manage your database. Install cqlsh by executing:

pip install cqlsh
Screenshot of the cqlsh command-line interface following installation on Rocky Linux 9 or 8.
Demonstration of the cqlsh interface post-installation on Rocky Linux.

Lastly, connect with cqlsh with the following command.

cqlsh

Example output of your successful connection:

[cqlsh 6.1.0 | Cassandra 4.1-alpha1 | CQL spec 3.4.5 | Native protocol v5]
Use HELP for help.
cqlsh> 

Configure Apache Cassandra on Rocky Linux

Setting up and personalizing Cassandra requires alterations in its configuration files and utilizing certain command line utilities.

Setting Up Basic Configuration

The principal configuration files for Cassandra are located in /etc/cassandra. Meanwhile, logs and data directories are typically situated at /var/log/cassandra and /var/lib/cassandra respectively.

For adjustments at the JVM level, such as heap size, you’d look towards the /etc/cassandra/conf/cassandra-env.sh file. Within this file, you can add supplementary JVM command-line arguments to the JVM_OPTS variable which Cassandra reads upon startup.

Enabling User Authentication with Apache Cassandra on Rocky Linux

Before activating user authentication, it’s wise to create a backup of the /etc/cassandra/conf/cassandra.yaml file:

sudo cp /etc/cassandra/conf/cassandra.yaml /etc/cassandra/conf/cassandra.yaml.backup

Subsequently, open the cassandra.yaml file:

sudo nano /etc/cassandra/conf/cassandra.yaml

Within the file, you’d want to search for and modify these parameters:

authenticator: org.apache.cassandra.auth.PasswordAuthenticator
authorizer: org.apache.cassandra.auth.CassandraAuthorizer
roles_validity_in_ms: 0
permissions_validity_in_ms: 0

Tweak other settings per your needs, and if they appear commented out, ensure you uncomment them. Complete the editing process by saving the file.

Afterward, reboot Cassandra to apply your modifications:

sudo systemctl restart cassandra

Adding an Administrative Superuser For Apache Cassandra

With authentication now activated, it’s essential to configure a user. Using the Cassandra Command shell utility, log in using the default user credentials:

cqlsh -u cassandra -p cassandra

Initiate a new superuser by replacing [username] and [yourpassword] with your specifics:

CREATE ROLE [username] WITH PASSWORD = '[yourpassword]' AND SUPERUSER = true AND LOGIN = true;

After that, exit and re-login with your new superuser details:

cqlsh -u username -p yourpassword

Diminish the default Cassandra account’s elevated permissions:

ALTER ROLE cassandra WITH PASSWORD = 'cassandra' AND SUPERUSER = false AND LOGIN = false;
REVOKE ALL PERMISSIONS ON ALL KEYSPACES FROM cassandra;

And, grant full permissions to your superuser:

GRANT ALL PERMISSIONS ON ALL KEYSPACES TO '[username]';

Conclude this section by logging out.

Customizing the Console Configuration

The Cassandra Shell can be tailored to your needs. It reads its configuration from the cqlshrc file found in the ~/.cassandra directory. A sample file providing insights into possible settings lies at /etc/cassandra/conf/cqlshrc.sample.

Begin by copying this sample file:

sudo cp /etc/cassandra/conf/cqlshrc.sample ~/.cassandra/cqlshrc

Adjust the cqlshrc file’s permissions:

sudo chmod 600 ~/.cassandra/cqlshrc
sudo chown $USER:$USER ~/.cassandra/cqlshrc

Open it for editing:

nano ~/.cassandra/cqlshrc

To automate login with superuser credentials, locate and edit the following section:

[authentication]
username = [superuser]
password = [password]

Remember to save after completing your edits. Now, when you log in to the Cassandra shell, it will reflect your changes:

cqlsh

Renaming the Cluster

You might want to rename the cluster to make the system more identifiable. Initiate by logging into the cqlsh terminal:

cqlsh

Replace [new_name] with your desired cluster name:

UPDATE system.local SET cluster_name = '[new_name]' WHERE KEY = 'local';

Exit the terminal and open /etc/cassandra/conf/cassandra.yaml for further editing:

sudo nano /etc/cassandra/conf/cassandra.yaml

Locate the cluster_name variable and replace its value with your chosen name. Save your changes.

Lastly, clear Cassandra’s system cache:

nodetool flush system

Restart Cassandra:

sudo systemctl restart cassandra

When you log in to the shell, it will display your chosen cluster name.

Verifying Configuration Changes

After making configuration alterations, it’s always a good practice to ensure they’ve taken effect and check the Cassandra cluster’s overall health.

Cluster Name Verification: Post the renaming process when you log back into the cqlsh shell:

cqlsh

The prompt should now display the newly set cluster name.

Conclusion

Wrapping up this guide, we’ve covered the essential steps to install Apache Cassandra on Rocky Linux, including both versions 9 and 8. Following these steps equips you with a powerful, scalable database solution ready to meet your big data challenges. Our final advice: regularly check for updates to Cassandra to maintain optimal performance and security. Remember, mastering Cassandra comes from practicing and experimenting. So, dive in, explore its features, and discover how it can revolutionize your data management strategy. Enjoy your journey into data management!

3 thoughts on “How to Install Apache Cassandra on Rocky Linux 9 or 8”

  1. This blog post only 2 months old, and already, its outdated and incorrect.

    https://downloads.apache.org/cassandra/ has no subfolder called “redhat” anymore, because every person involved in anything to do with linux is a moron who cannot leave things alone when they’re working well enough. Every bloody thing that gets done, gets done, then updated then changed then reverted then fixed then its found to have a bug because it wasnt fixed properly, and then its decided the code is a mess, and the product is abandoned in favour of some new thing that’s supposed to be full of advantages, but then after a few years more wasted effort, then that new product is a useless mess too. Just pathetic.

    Reply

Leave a Comment


Your Mastodon Instance
Share to...