Atlantic.Net Blog

How to Install Apache Cassandra on Rocky Linux 8

Apache Cassandra is a free and open-source distributed NoSQL database management system. It is specially designed to handle large amounts of data across many commodity servers. Generally, it is used as a real-time data store for transactional applications and as a read-intensive database. It supports relational databases including MySQL, PostgreSQL, and Microsoft SQL. It is used by many companies that use large data sets including, Instagram, GitHub, Netflix, Reddit, and more.

In this guide, we will show you how to install Apache Cassandra on Rocky Linux 8.

Step 1 – Install Java 8

Apache Cassandra supports Java version 8, so you will need to install OpenJDK 8 to your system. You can install it with other required packages using the following command:

dnf install epel-release python2 python2-pip java-1.8.0-openjdk -y

Once Java is installed, verify the Java installation using the following command:

java -version

Sample output:

openjdk version "1.8.0_302"
OpenJDK Runtime Environment (build 1.8.0_302-b08)
OpenJDK 64-Bit Server VM (build 25.302-b08, mixed mode)

You will also need to install cqlsh utility to your system. You can install it using the following command:

pip2 install cqlsh

Step 2 – Install Apache Cassandra

By default, the Apache Cassandra package is not included in the RockyLinux 8 default repository, so you will need to create a repository for Apache Cassandra.

nano /etc/yum.repos.d/cassandra.repo

Add the following lines:

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

Save and close the file, then install the Apache Cassandra with the following command:

dnf install cassandra -y

Step 3 – Create a Service File for Cassandra

Next, you will need to create a systemd service file to manage the Apache Cassandra service. You can create it with the following command:

nano /etc/systemd/system/cassandra.service

Add the following lines:

[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

Save and close the file, then reload the systemd daemon to apply the changes:

systemctl daemon-reload

Next, start and enable the Cassandra service with the following command:

systemctl start cassandra
systemctl enable cassandra

Next, verify the status of Apache Cassandra with the following command:

systemctl status cassandra

You should see the following output:

● cassandra.service - Apache Cassandra
   Loaded: loaded (/etc/systemd/system/cassandra.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-09-22 08:07:05 UTC; 603ms ago
 Main PID: 11515 (cassandra)
    Tasks: 4 (limit: 11411)
   Memory: 156.1M
   CGroup: /system.slice/cassandra.service
           ├─11515 /bin/sh /usr/sbin/cassandra -f -p /var/run/cassandra/cassandra.pid
           ├─11584 /bin/sh /usr/sbin/cassandra -f -p /var/run/cassandra/cassandra.pid
           ├─11588 find /lib64 /lib /usr/lib64 /usr/lib /usr/lib64//bind9-export /lib /lib64 /lib/sse2 /lib64/sse2 /lib64/tls -regex .*/libjem>
           └─11589 head -n 1

Sep 22 08:07:05 RockyLinux8 systemd[1]: cassandra.service: Service RestartSec=100ms expired, scheduling restart.
Sep 22 08:07:05 RockyLinux8 systemd[1]: cassandra.service: Scheduled restart job, restart counter is at 5.
Sep 22 08:07:05 RockyLinux8 systemd[1]: Stopped Apache Cassandra.
Sep 22 08:07:05 RockyLinux8 systemd[1]: Started Apache Cassandra.

Step 4 – Verify Apache Cassandra

Wait for some time to bring up Apache Cassandra completely, then verify the Apache Cassandra using the following command:

nodetool status

You should get the following output:

Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load       Tokens  Owns (effective)  Host ID                               Rack 
UN  127.0.0.1  69.08 KiB  16      100.0%            d6672930-2b15-426b-8445-e6f6a2e923f2  rack1

You can also connect to Cassandra with the following command:

cqlsh

Once you are connected, you should get the following output:

Python 2.7 support is deprecated. Install Python 3.6+ or set CQLSH_NO_WARN_PY2 to suppress this message.

Connected to Test Cluster at 127.0.0.1:9042
[cqlsh 6.0.0 | Cassandra 4.0.1 | CQL spec 3.4.5 | Native protocol v5]
Use HELP for help.
cqlsh> 

Step 5 – Change Cassandra Cluster Name

In order to change the Cassandra cluster name, connect to the Cassandra with the following command:

cqlsh

Next, change the cluster name with the following command:

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

Next, exit from the Cassandra shell with the following command:

cqlsh> exit

Next, edit the Apache Cassandra main configuration file:

nano /etc/cassandra/default.conf/cassandra.yaml

Change the Cassandra cluster name as shown below:

cluster_name: 'Atlantic Cluster'

Save and close the file, then restart the Apache Cassandra to apply the changes:

systemctl restart cassandra

Now, verify the Cassandra cluster name with the following command:

cqlsh

You should get your new cluster name in the following output:

Connected to Atlantic Cluster at 127.0.0.1:9042
[cqlsh 6.0.0 | Cassandra 4.0.1 | CQL spec 3.4.5 | Native protocol v5]
Use HELP for help.

Conclusion

In the above guide, we explained how to install Apache Cassandra on RockyLinux 8. You can now use Apache Cassandra to handle and manage large data sets. Try it on dedicated hosting from Atlantic.Net today!

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year