Atlantic.Net Blog

How to Install Apache Cassandra on Oracle Linux 8

Apache Cassandra is an open-source, wide-column store NoSQL database management system designed to handle large amounts of data. Cassandra can be distributed across many servers to achieve high availability with no single point of failure. Generally, it is used to serve as a real-time operational data store for online transactional applications and as a read-intensive database for large-scale systems. Currently, it is used by many organizations including Netflix, Digg, Adobe, Twitter, HP, IBM, Rackspace, Cisco, and Reddit.

In this guide, we will explain how to install Apache Cassandra on Oracle Linux 8.

Step 1 – Install Java 8

By default, Apache Cassandra supports only Java version 8, so Java 8 must be installed on your server. If it is not installed, you can install it with other dependencies using the following command:

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

After installation, verify the Java installation with the following command:

java -version

You will get the Java version in the following output:

openjdk version "1.8.0_332"
OpenJDK Runtime Environment (build 1.8.0_332-b09)
OpenJDK 64-Bit Server VM (build 25.332-b09, mixed mode)

Next, install the cqlsh command-line utility to connect to Cassandra via command-line.

pip2 install cqlsh

Step 2 – Install Apache Cassandra

By default, the Apache Cassandra package is not included in the Oracle Linux 8 default repository, so you will need to create a repo for Apache Cassandra. You can create an Apache Cassandra repo using the following command:

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 when you are done, then install Apache Cassandra with the following command:

dnf install cassandra -y

Step 3 – Create a Service File for Cassandra

It is recommended to create a service file to manage the Apache Cassandra service via systemd. 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

To verify the status of Apache Cassandra, run 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 Sat 2022-04-30 07:54:46 EDT; 15s ago
 Main PID: 2170 (java)
    Tasks: 23 (limit: 23694)
   Memory: 1.1G
   CGroup: /system.slice/cassandra.service
           └─2170 /usr/bin/java -ea -da:net.openhft... -XX:+UseThreadPriorities -XX:+HeapDumpOnOutOfMemoryError -Xss256k -XX:+AlwaysPreTouch >

Apr 30 07:55:00 oraclelinux cassandra[2170]: INFO  [main] 2022-04-30 07:55:00,318 CassandraDaemon.java:640 - Classpath: /etc/cassandra/conf:/>
Apr 30 07:55:00 oraclelinux cassandra[2170]: INFO  [main] 2022-04-30 07:55:00,319 CassandraDaemon.java:642 - JVM Arguments: [-ea, -da:net.ope>
Apr 30 07:55:00 oraclelinux cassandra[2170]: WARN  [main] 2022-04-30 07:55:00,405 NativeLibrary.java:201 - Unable to lock JVM memory (ENOMEM)>
Apr 30 07:55:00 oraclelinux cassandra[2170]: INFO  [main] 2022-04-30 07:55:00,569 MonotonicClock.java:202 - Scheduling approximate time conve>
Apr 30 07:55:00 oraclelinux cassandra[2170]: INFO  [main] 2022-04-30 07:55:00,577 MonotonicClock.java:338 - Scheduling approximate time-check>
Apr 30 07:55:00 oraclelinux cassandra[2170]: WARN  [main] 2022-04-30 07:55:00,585 StartupChecks.java:143 - jemalloc shared library could not >
Apr 30 07:55:00 oraclelinux cassandra[2170]: WARN  [main] 2022-04-30 07:55:00,585 StartupChecks.java:187 - JMX is not enabled to receive remo>
Apr 30 07:55:00 oraclelinux cassandra[2170]: INFO  [main] 2022-04-30 07:55:00,590 SigarLibrary.java:44 - Initializing SIGAR library
Apr 30 07:55:00 oraclelinux cassandra[2170]: WARN  [main] 2022-04-30 07:55:00,603 SigarLibrary.java:174 - Cassandra server running in degrade>
Apr 30 07:55:00 oraclelinux cassandra[2170]: WARN  [main] 2022-04-30 07:55:00,604 StartupChecks.java:329 - Maximum number of memory map areas>

Step 4 – Verify Apache Cassandra

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

nodetool status

You will get the following error:

nodetool: Failed to connect to '127.0.0.1:7199' - URISyntaxException: 'Malformed IPv6 address at index 7: rmi://[127.0.0.1]:7199'.

To resolve this error, add the “legacy” parsing flag when running nodetool:

nodetool -Dcom.sun.jndi.rmiURLParsing=legacy 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.06 KiB  16      100.0%            91f2092e-f428-40f8-8093-efe820abe917  rack1

Next, connect to the Cassandra shell using the cqlsh utility:

cqlsh

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

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

Step 5 – Change Cassandra Cluster Name

By default, Cassandra’s cluster name is set as  “Test Cluster.” To change the default cluster name, connect to 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 and define your new cluster name:

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 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.3 | 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 Oracle Linux 8. You can now use Apache Cassandra to handle and manage large data sets. Give it a try on VPS hosting from Atlantic.Net!

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