Lorem ipsum dolor sit amet, conse ctetur adip elit, pellentesque turpis.

  • No products in the cart.

Image Alt

Apache Cassandra Installation on CentOS 7

Apache Cassandra Installation on CentOS 7

About Apache Cassandra

  • Apache Cassandra is a free and open-source, distributed, wide column store, NoSQL DBMS.
  • Designed to handle large amounts of data across many commodity servers.
  • Provides high availability with no single point of failure. 
  • Cassandra clusters spans across multiple datacenters, with replication.
  • Cassandra was originally developed at Facebook, was open sourced in 2008, and became a top-level Apache project in 2010.

In this, we will be installing Apache Cassandra on CentOS 7 server.


Cassandra requires that the latest version of Java 8, either the Oracle Java Standard Edition 8 or OpenJDK 8 be installed. To verify that you have the correct version of java installed, type java -version. If you don’t have Java installed, you can check out our guide on installing Java on CentOS 7.

  • CentOS 7 x64 server instance with at least 4GB of memory. Insufficient memory will cause Apache Cassandra to exit abnormally.
  • A sudo user.

Configuring Oracle Java

Check the current java version.

$ java -version

We can see that there is no OpenJdk installed

Install OpenJDK 8 JDK.

To install OpenJDK 8 JDK using yum, run this command:

$ sudo yum install java-1.8.0-openjdk-devel -y

At the confirmation prompt, enter y then RETURN to continue with the installation.

Now re-check the Java version.

$ java -version

Installing Cassandra

Now add Apache Cassandra repository into your repository list by creating a new repository file.

sudo vi /etc/yum.repos.d/cassandra.repo

Now add the following content into the file.

name=Apache Cassandra

Once complete, use ‘:wq’ to save the file.
You can now install Apache Cassandra by running the following command.

$ sudo yum -y install cassandra

Reload your system daemons by running:

$ sudo systemctl daemon-reload

You can now start Cassandra by typing:

$ sudo systemctl start cassandra

To enable Cassandra to automatically start at boot time, run:

$ sudo systemctl enable cassandra

Note: If you are facing issue while start cassandra.service

Unit cassandra.service could not be found.

Or  If you are facing below error while starting cassandra.service

systemd[1]: cassandra.service: New main PID 20438 does not belong to service, and PID file is not owned by root. Refusing.

The cause is that when the cassandra starts, the old initialization SysV script is used, in which it is obviously impossible to specify the user and group to start the service.


Check cassandra.service file in /usr/lib/systemd/system/cassandra.service. And see for [Service] tag and check the user and group.

If you are unable to find  cassandra.servicein given Path.

Create cassandra.service file in /usr/lib/systemd/system/ path and add below code in cassandra.service file.


ExecStart=/usr/sbin/cassandra -f -p /var/run/cassandra/cassandra.pid


Once complete, use ‘:wq’ to save the file.

You can now restart Cassandra by typing:

$ sudo systemctl restart cassandra

Note: If you are unable to resolve your issue so try to restart your machine using below command

$ sudo reboot

You can verify that Cassandra is running by typing the following command.

$ nodetool status

You should see a similar output if Cassandra is running.

Cassandra comes with a powerful command line shell cqlsh to run query on Cluster. Query is written in CQL or Cassandra Query language. To access CQL shell, run the following command.

$ cqlsh

You will see the following output.

Validate cqlsh 

Create Sample Keyspace and observe replication strategy :

cqlsh> CREATE KEYSPACE mykeyspace WITH replication = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 1, 'datacenter2' : 1 };

cqlsh> CREATE TABLE mykeyspace.mytable ( id int primary key, name text );
cqlsh> CREATE KEYSPACE patient WITH replication = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 1, 'datacenter2
' : 1 };

cqlsh> CREATE TABLE patient.exam (patient_id int primary key, id int, date timeuuid, details text );
cqlsh> use patient;

cqlsh:patient> INSERT INTO exam (patient_id,id,date,details) values (1,1,now(),'first exam patient 1');

cqlsh:patient> INSERT INTO exam (patient_id,id,date,details) values (2,2,now(),'second exam patient 1');

Returns all column values.

cqlsh:patient> select * from exam;

cqlsh:patient> exit

For now, just type exit and then press ENTER to quit the cqlsh shell.

If you want to stop Apache Cassandra, execute the following command:

sudo systemctl stop cassandra

In this blog, we installed single node Cassandra on CentOS Server. You must have noticed that before we actually install Cassandra, we need to install JDK, setup User etc. Once this is done then we can install and configure Cassandra. Apart from installation and configuration, we are also able to validate if Cassandra is working fine or not through Command Line Interface.

  • Ayush Singh Chandel March 4, 2020 12:52 am

    Great Post on Apache Cassandra Installation

Post a Comment