Apache Cassandra is a fault-tolerant, highly scalable, very reliable, and performant NoSql database system. It is free open-source, fully developed using java can run on any JVM-based system. Installation of the Cassandra database is very straightforward.
One can just download unzip precompiled binaries and run if they have all the prerequisites to run them. For Cassandra Database you need the latest version of Java 8 (Oracle or Open JDK) and for CQLSH
you need the latest version of python 3 or python 2.
Cassandra Installation Steps on Ubuntu
First, you need to check all the pre-requisites
For java run the following command to check java 8 is installed or not.
~$ java -version
Command 'java' not found, but can be installed with:
sudo apt install openjdk-11-jre-headless # version 11.0.10+9-0ubuntu1~20.04, or
sudo apt install default-jre # version 2:1.11-72
sudo apt install openjdk-8-jre-headless # version 8u282-b08-0ubuntu1~20.04
sudo apt install openjdk-13-jre-headless # version 13.0.4+8-1~20.04
sudo apt install openjdk-14-jre-headless # version 14.0.2+12-1~20.04
If java 8 is not installed then install open using appropriate option
~$ sudo apt-get update
~$ sudo apt install openjdk-8-jre-headless
It will download and install Java 8 (Open JDK) on your system. Now you can check Java 8 installation
~$ java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~20.04-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
Add the Apache repository of Cassandra to the file cassandra.sources.list
~$ sudo apt-get install software-properties-common
~$ curl https://downloads.apache.org/cassandra/KEYS | sudo apt-key add -
~$ sudo apt-get update
~$ sudo apt-get install cassandra
The above commands will configure the Cassandra repository and install using the Debian package. Cassandra will be installed as a service and start running after installation.
You can check status of cassandra using following command
~$ nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 127.0.0.1 68.9 KiB 16 100.0% 0e6d6029-b16f-4b50-9a4b-2c3ba 90d5883 rack1
It will show the status of the node as UP.
You can also check using cqlsh
, it a python based command-line tool to connect Cassandra and perform queries.
You can change Cassandra cluster information by editing cassandra.yaml file
/etc/cassandra/cassandra.yaml
Configuring Cassandra For Remote Access
To accessing Cassandra from removing you needs to change the following in cassandra.yaml and restart the Cassandra service.
rpc_address: localhost to rpc_address: 0.0.0.0
broadcast_rpc_address: [node-ip]
listen_address: [node-ip]
and do not forget to open firewall for Cassandra port
~$ sudo ufw allow 9042