Apache Cassandra is an increasingly popular NoSQL database that offers businesses and developers many advantages. Its high scalability across multiple commodity servers makes it an attractive choice for storing and accessing large amounts of data. Cassandra provides unparalleled fault tolerance and reliability, meaning the application can keep running even if one or more servers fail. This guide will discuss installing Apache Cassandra on Rocky Linux 9 or Rocky Linux 8 using either the command line.
Step 1. Update Rocky Linux
First thing before proceeding to install 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
Step 2. Import Cassandra Repo
The first step is to import the repository for 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 21: 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
Step 3: Install Cassandra
With the repository now imported, you can install Cassandra with the following command.
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 take place successfully. I found you did not need to, but it is advised.
reboot
Step 4: Start Cassandra SystemD Service
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
Example output:
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
Step 5: Install Apache Cassandra Client (cqlsh)
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 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
Example output:
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>
Conclusion:
Apache Cassandra is an excellent choice for those who need a scalable and fault-tolerant database. It is easy to install and run on Rocky Linux, making it an ideal choice for those who want a simple process. Following the steps in this article, you can have Apache Cassandra up and running on your system in no time.