Hamsa K
Editor
7 min read | 4 years ago

How to Install Apache Cassandra on Ubuntu 20 04

Install Apache cassandra on ubuntu 20.04

Cassandra is one of the most popular distributed NoSQL databases from Apache which is known for its scalability, performance and its high availability with no single point of failure.The NoSQL database Cassandra is cross-platform application written in Java. Apache Cassandra handles huge volumes of data with dynamo-style replication.

Step 1:Install Java

To install Cassandra on Ubuntu, we must install Java first. Java might not be installed by default. We can verify it by using this command.

root@ubuntu20:~# java --version

If Java is not installed in your system, output will display like below

root@ubuntu20:~# java --version
Command 'java' not found, but can be installed with:
apt install default-jre              # version 2:1.11-72, or
apt install openjdk-11-jre-headless  # version 11.0.8+10-0ubuntu1~20.04
apt install openjdk-13-jre-headless  # version 13.0.3+3-1ubuntu2
apt install openjdk-14-jre-headless  # version 14.0.1+7-1ubuntu1
apt install openjdk-8-jre-headless   # version 8u265-b01-0ubuntu2~20.04

Here we will install java 8 with below command.

root@ubuntu20:~# apt install openjdk-8-jdk

once java is installed,verfiy its version with following command.

root@ubuntu20:~# java -version
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~20.04-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)

Step 2: Install Apache cassandra

First we will install apt-transport-https package to add new repository over https as shown below.

root@ubuntu20:~# apt install apt-transport-https

Next import GPG Key.

root@ubuntu20:~# wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -

Now add Apache cassandrarepository to the system’s sources list file.

root@ubuntu20:~# sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 311x main" > /etc/apt/sources.list.d/cassandra.list'

once it is added, update package list and install nosql database.

apt update
apt install cassandra

sample output:

root@ubuntu20:~# apt install cassandra
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib python-is-python2 python2 python2-minimal python2.7 python2.7-minimal
Suggested packages:
  cassandra-tools python2-doc python-tk python2.7-doc binutils binfmt-support
The following NEW packages will be installed:
  cassandra libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib python-is-python2 python2 python2-minimal python2.7 python2.7-minimal
0 upgraded, 9 newly installed, 0 to remove and 37 not upgraded.
Need to get 34.5 MB of archives.
After this operation, 57.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Step 3: Verify cassandra

once it is installed, cassandra service will start automatically.

root@ubuntu20:~# systemctl status cassandra
● cassandra.service - LSB: distributed storage system for structured data
     Loaded: loaded (/etc/init.d/cassandra; generated)
     Active: active (running) since Mon 2020-09-07 12:45:31 UTC; 8min ago
       Docs: man:systemd-sysv-generator(8)
      Tasks: 43 (limit: 1685)
     Memory: 996.0M
     CGroup: /system.slice/cassandra.service
             └─7475 java -Xloggc:/var/log/cassandra/gc.log -ea -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42 -XX:+HeapDumpOnOutOfMemoryError -Xss256k -XX:String>
Sep 07 12:45:30 ubuntu20 systemd[1]: Starting LSB: distributed storage system for structured data...
Sep 07 12:45:31 ubuntu20 systemd[1]: Started LSB: distributed storage system for structured data.

and also make sure that Cassandra installation process completed properly, check cluster status with below command.

root@ubuntu20:~# nodetool status

sample output:

root@ubuntu20:~# 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  70 KiB     256          100.0%            c3ced02d-0d9a-4d45-972f-4db3253e3d73  rack1

Now Apache Cassandra is successfully  installed on Ubuntu server.

Step 4: Configure Apache cassandra

There is a command-line tool written in Python for executing the Cassandra Query Language (CQL) command.you can use command-line tool named cqlsh.

root@ubuntu20:~# cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.8 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.

The default Cassandra cluster is named “Test Cluster”. If you want to change the cluster name follow below steps.

root@ubuntu20:~# cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.8 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> UPDATE system.local SET cluster_name = 'Lampblogs Cluster' WHERE KEY = 'local';
cqlsh> exit

Next edit cluster name  /etc/cassandra/cassandra.yaml file.

root@ubuntu20:~# nano /etc/cassandra/cassandra.yaml

change below line as your cluster name

cluster_name: 'Lampblogs Cluster'

save and exit file and and restart the Cassandra service. 

root@ubuntu20:~# systemctl restart cassandra

you can verify cluster name by using cqlsh as shown below.

root@ubuntu20:~# cqlsh
Connected to Lampblogs Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.8 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.

Thats'it.you have successfully learned how to install Apache Cassandra on ubuntu 20.04



Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy