Install Apache Cassandra on Rocky Linux 9

In this guide, we want to teach you How To Install and Configure Apache Cassandra on Rocky Linux 9.

Cassandra is defined as an open-source NoSQL data storage system that leverages a distributed architecture to enable high availability, scalability, and reliability, managed by the Apache non-profit organization. 

Key features of Apache Cassandra:

  • Open-source availability
  • Distributed footprint
  • Scalability
  • Cassandra Query Language
  • Fault tolerance
  • Schema free

    Steps To Install and Configure Apache Cassandra on Rocky Linux 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 Rocky Linux 9.

    Install Dependencies for Cassandra

    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)

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

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

    NoteIf 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 Rocky Linux 9, let’s see how to configure it.

    Configure Apache Cassandra on Rocky Linux 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 Rocky Linux 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 Rocky Linux 9.

    Hope you enjoy it.

    You may be like these articles:

    How To Install Apache Tomcat on Rocky Linux 9

    How To Enable IP Forwarding in Linux

    LEAVE A REPLY

    Please enter your comment!
    Please enter your name here

    Latest Articles

    POPULAR TAGS

    Most Popular