How to Install Apache Cassandra on Rocky Linux EL9 or EL8

For those seeking a robust NoSQL database solution, learning how to install Apache Cassandra on Rocky Linux 9 or the older stable Enterprise Linux release of Rocky Linux 8 is essential. Recognized for its scalability and resilience, Apache Cassandra stands out in databases designed to manage large volumes of data across distributed servers. Its decentralized architecture ensures no single point of failure, offering businesses and developers a reliable platform for their data-intensive applications.

Key Features of Apache Cassandra:

  • High Scalability: With its ability to scale horizontally, Cassandra can accommodate growing data needs by adding more servers to the existing cluster.
  • Fault Tolerance: Cassandra’s design ensures that even if multiple nodes fail, the database remains operational, providing uninterrupted access to data.
  • Decentralized Design: Every node in a Cassandra cluster is identical, ensuring data is evenly distributed across the network, which enhances its reliability and performance.
  • Flexible Schema: Cassandra’s dynamic data structure capabilities, being schema-less, cater to diverse application needs, a departure from traditional relational databases.

Apache Cassandra’s promise of scalability, reliability, and flexibility makes it a top choice for businesses and developers. This guide will delve into the detailed steps to install Apache Cassandra on Rocky Linux 9 and 8. By the end of this guide, users will be equipped with the knowledge to set up and run Cassandra seamlessly on their Rocky Linux systems.

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 9 or 8

The first step is to import the repository for Apache Cassandra. Luckily, this can be done simply with a single command. The tutorial will list how to import the 4.0 branch or 4.1 branches. The 3.xx branch ends soon, so the tutorial will not cover adding these.

Option 1: Import Apache Cassandra 4.0

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

Option 2: Import Apache Cassandra 4.1

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

Option 3: Import Apache Cassandra 5.0 Alpha

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://downloads.apache.org/cassandra/5.0-alpha1/
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://www.apache.org/dist/cassandra/KEYS
EOF

Install Apache Cassandra on Rocky Linux 9 or 8

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

Example output:

4.1-alpha1

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 9 or 8

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 will need to reload the daemon to begin using the Cassandra service, and this cannot be skipped.

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.Pin
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 9 or 8

Step 1: Install Python cqlsh is written in Python. If Python is not installed on your system, you can install it by running the following command.

sudo dnf install python3 -y

Step 2: Install pip cqlsh also requires pip, the package installer for Python. If pip is not installed, you can install it by running the following command.

sudo dnf install python3-pip -y

Step 3: Install Cassandra Python Driver cqlsh, which requires the Cassandra Python driver to connect to the database. You can install it by running the following Python PIP command.

pip install cassandra-driver

Step 4: Once the prerequisites are installed, you can install cqlsh by running the following Python PIP command.

pip install cqlsh
Screenshot of the cqlsh command-line interface following installation on Rocky Linux 9 or 8.Pin
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 9 or 8

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 on Rocky Linux

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.

Monitoring Logs: To ensure no errors, especially after making changes: Keep an eye on the logs located at /var/log/cassandra. They can provide valuable information about the cluster’s operation and potential issues.

Performance Tuning: While the earlier steps dealt with basic configuration, always remember to optimize Cassandra’s performance. JVM configurations, Garbage collection logs, and other parameters in the cassandra.yaml file might need periodic tuning based on the use case and system load.

Security: Beyond setting up a superuser, think about network security, encryption, and other means to protect data. Ensure that your configurations meet operational requirements and comply with security best practices.

Backups: Always schedule regular backups. Ensure that not only configuration files but also data is backed up. Recovery strategies can be a lifesaver in the event of unforeseen mishaps.

Conclusion

Learning how to install, set up, and configure Apache Cassandra is crucial in ensuring its performance, security, and reliability. You will have set up a solid foundation by following the steps outlined. Stay updated with the latest best practices and periodically review and adjust configurations as necessary.

Share to...