How to Install Apache Cassandra NoSQL Database on CentOS 8

Apache Cassandra is an open-source high-performance NoSQL database management system with no single point of failure. Apache Cassandra uses a cluster model instead uses the table model seen in MySQL/PostgreSQL. Cassandra is suitable for applications that can't afford to lose data. Data is automatically replicated to multiple nodes for fault-tolerance. Failed nodes can be replaced automatically with no downtime.

Apache Cassandra is the best choice for you if you are looking for scalability, high availability, and high-performance.

In this tutorial, we will show you how to install Apache Cassandra on CentOS 8.

Requirements

  • A server running CentOS 8 with a minimum of 2 GB of RAM.
  • A root password is set up on your system.

Getting Started

Before starting, it is recommended to update your server to the latest stable version. You can update your server with the following command:

dnf update

Once your server is updated, restart it to apply the changes.

Install Java

Apache Cassandra requires OpenJDK 8 and Python2 to be installed on the system. You can install OpenJDK 8 and Python2 using the following command:

dnf install java-1.8.0-openjdk-devel python2

Once both packages are installed, you can verify the Java version using the following command:

java -version

You should see the following output:

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

Install Apache Cassandra

By default, Apache Cassandra is not available in the CentOS 8 default repository. So you will need to create a repo for that. You can create a new repo file /etc/yum.repos.d/cassandra.repo as shown below:

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

Add the following lines:

[cassandra]
name = DataStax Repo for Apache Cassandra
baseurl = http://rpm.datastax.com/community
enabled = 1
gpgcheck = 0

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

dnf install dsc20

Once you are finished with the installation, you can proceed to the next step

Create a Systemd Unit File for Cassandra

By default, Apache Cassandra package is not able to generate a service file for itself. So you will need to create a systemd service file to manage the 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 with the following command:

systemctl daemon-reload

Next, start the Cassandra service and enable it to start after system reboot with the following command:

systemctl start cassandra
systemctl enable cassandra

You can also check the status of the Cassandra service with the following command:

systemctl status cassandra

You should see the following output:

? cassandra.service - Apache
   Loaded: loaded (/etc/systemd/system/cassandra.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-12-07 01:25:26 EST; 1min 51s ago
 Main PID: 1888 (java)
    Tasks: 53 (limit: 25044)
   Memory: 272.7M
   CGroup: /system.slice/cassandra.service
           ??1888 java -ea -javaagent:/usr/share/cassandra/lib/jamm-0.2.5.jar -XX:+CMSClassUnloadingEnabled -XX:+UseThreadPriorities -XX:Threa>

Dec 07 01:25:29 centos8 cassandra[1888]:  INFO 01:25:29,054 Writing Memtable-local@1642973315(10104/101040 serialized/live bytes, 259 ops)
Dec 07 01:25:29 centos8 cassandra[1888]:  INFO 01:25:29,118 Completed flushing /var/lib/cassandra/data/system/local/system-local-jb-4-Data.db >
Dec 07 01:25:29 centos8 cassandra[1888]:  INFO 01:25:29,124 Compacting [SSTableReader(path='/var/lib/cassandra/data/system/local/system-local->
Dec 07 01:25:29 centos8 cassandra[1888]:  INFO 01:25:29,169 Node localhost/127.0.0.1 state jump to normal
Dec 07 01:25:29 centos8 cassandra[1888]:  INFO 01:25:29,294 Compacted 4 sstables to [/var/lib/cassandra/data/system/local/system-local-jb-5,].>
Dec 07 01:25:29 centos8 cassandra[1888]:  INFO 01:25:29,322 Starting listening for CQL clients on localhost/127.0.0.1:9042...
Dec 07 01:25:29 centos8 cassandra[1888]:  INFO 01:25:29,376 Using TFramedTransport with a max frame size of 15728640 bytes.
Dec 07 01:25:29 centos8 cassandra[1888]:  INFO 01:25:29,378 Binding thrift service to localhost/127.0.0.1:9160
Dec 07 01:25:29 centos8 cassandra[1888]:  INFO 01:25:29,391 Using synchronous/threadpool thrift server on localhost : 9160
Dec 07 01:25:29 centos8 cassandra[1888]:  INFO 01:25:29,422 Listening for thrift clients...

Test Apache Cassandra Installation

Apache Cassandra is now installed and running on your server. You can verify it whether it is running or not with the following command:

nodetool status

You should see the following command:

Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load       Tokens  Owns (effective)  Host ID                               Rack
UN  127.0.0.1  46.11 KB   256     100.0%            2a680007-8c30-4bde-9a3f-9fa212b96d11  rack1

Configure Apache Cassandra

By default, Cassandra is configured to accept the connection from the localhost only.

You can also login to Cassandra through the Cassandra Query Language. To access CQL shell, run the following command:

cqlsh

You should see the following output:

Connected to Test Cluster at localhost:9160.
[cqlsh 4.1.1 | Cassandra 2.0.17 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh> 

In the above output, you should see that the Cassandra cluster is named “Test Cluster”. You can also change this default cluster name.

To do so, log in to CQL shell with the following command:

cqlsh

Next, run the following command to change the cluster name to "HowtoForge Cluster" as shown below:

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

Next, exit from the shell with the following command:

cqlsh>exit;

Next, you will also need to edit the cassandra.yaml configuration file and define your new cluster name:

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

Change the following line:

cluster_name: 'HowtoForge Cluster'

Save and close the file when you are finished. Then, clear the system cache with the following command:

nodetool flush system

Finally, restart the Apache Cassandra service to apply the new configuration:

systemctl restart cassandra

Now, log in to CQL shell with the following command:

cqlsh

You should see that the cluster name is now changed to "HowtoForge Cluster":

Connected to HowtoForge Cluster at localhost:9160.
[cqlsh 4.1.1 | Cassandra 2.0.17 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh> 

Conclusion

Congratulations! you have successfully installed and configured Apache Cassandra on CentOS 8. Feel free to ask me if you have any questions.

Share this page:

0 Comment(s)