How To Install Apache Cassandra On Ubuntu 22.04

How to install Apache Cassandra on Ubuntu 22.04

In this short tutorial, we will discuss how to install Apache Cassandra 4.0 on Ubuntu 22.04 Linux operating system. Apache Cassandra is a NoSQL database that can handle large data in a short time, so it is preferred by several institutions that have applications with large scalability. The use of NoSQL databases in high scalability applications, fail-safe systems for handling large amounts of data on distributed systems (clusters) has been increasing. This is due to the increasing human activity in using or accessing the digital environment, for example, the increasing e-commerce activities compared to offline markets.

Apache Cassandra is an open source NoSQL distributed database trusted by thousands of companies for scalability and high availability without compromising performance. Linear scalability and proven fault-tolerance on commodity hardware or cloud infrastructure make it the perfect platform for mission-critical data.

Apache Cassandra Installation on Ubuntu 22.04

In this tutorial, we will install Cassandra 4.0 using APT official repository. Installing Apache Cassandra will consist of several stages, namely:

1. Update Ubuntu 22.04 System

In this step we will update our local packages repository, this task is to make sure if we are accessing the latest packages versions. This task will cut down the installation time and it also helps prevent zero-day exploits against outdated software. To update our packages software we will use command line :

$ sudo apt update
$ sudo apt upgrade

2. Install OpenJDK

Apache Cassandra is written in Java and RubyGems and only runs on UNIX-like systems, we will ensure if the environment supports Cassandra will be running properly on the system by checking whether the Java runtime is already in the system, if not we will install it first.

$ java --version
$ sudo apt install default-jdk --if not already installed on the system

Output :

ramans@infodiginet:~$ java --version
openjdk 11.0.17 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu222.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu222.04, mixed mode, sharing)

3. Adding Cassandra GPG Key and Repository

In this step, we will add GPG key and Cassandra repository to Ubuntu 22.04 system.

3.1. Add GPG Key

$ gpg --keyserver keyserver.ubuntu.com --recv-keys 7E3E87CB
$ gpg --export --armor 7E3E87CB | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/cassandra-key.gpg

Output :

ramans@infodiginet:~$ gpg --keyserver keyserver.ubuntu.com --recv-keys 7E3E87CB
gpg: key E91335D77E3E87CB: public key "Michael Semb Wever <mick@thelastpickle.com>" imported
ramans@infodiginet:~$ gpg --export --armor 7E3E87CB | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/cassandra-key.gpg
[sudo] password for ramans:

3.2. Add Cassandra Repository

To add Cassandra version 4.0.x we will add the following repository.

$ sudo sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 40x main" > /etc/apt/sources.list.d/cassandra.list'

4. Installing Apache Cassandra 4.0

After all are set, then we will install Apache Cassandra. Cassandra installation will start with a system update first to ensure the latest package repository is read by the system.

$ sudo apt update
$ sudo apt install cassandra

Outptu :

ramans@infodiginet:~$ sudo apt update
Hit:1 http://id.archive.ubuntu.com/ubuntu jammy InRelease                                                            
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]                                            
Hit:4 http://id.archive.ubuntu.com/ubuntu jammy-updates InRelease                                                    
Hit:5 https://repos.influxdata.com/ubuntu jammy InRelease                                                            
Hit:6 http://id.archive.ubuntu.com/ubuntu jammy-backports InRelease                                                  
Ign:7 https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 InRelease                                            
Hit:8 http://apt.postgresql.org/pub/repos/apt jammy-pgdg InRelease                                                   
Ign:9 http://download.webmin.com/download/repository sarge InRelease                                                 
Hit:10 https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 Release                                             
Hit:12 http://download.webmin.com/download/repository sarge Release                                            
Get:3 https://downloads.apache.org/cassandra/debian 40x InRelease [3.902 B]                                          
Get:14 https://downloads.apache.org/cassandra/debian 40x/main amd64 Packages [699 B]                                 
Get:15 https://downloads.apache.org/cassandra/debian 40x/main i386 Packages [699 B]                                  
Fetched 116 kB in 10s (12,0 kB/s)                                                                                    
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
ramans@infodiginet:~$ sudo apt install cassandra
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  cassandra-tools
The following NEW packages will be installed:
  cassandra
0 upgraded, 1 newly installed, 0 to remove and 15 not upgraded.
Need to get 47,5 MB of archives.
After this operation, 58,8 MB of additional disk space will be used.
Get:1 https://downloads.apache.org/cassandra/debian 40x/main amd64 cassandra all 4.0.5 [47,5 MB]
Ign:1 https://downloads.apache.org/cassandra/debian 40x/main amd64 cassandra all 4.0.5                               
Get:1 https://downloads.apache.org/cassandra/debian 40x/main amd64 cassandra all 4.0.5 [47,5 MB]                     
Fetched 128 kB in 7min 35s (280 B/s)                                                                                 
Selecting previously unselected package cassandra.
(Reading database ... 224656 files and directories currently installed.)
Preparing to unpack .../cassandra_4.0.5_all.deb ...
Unpacking cassandra (4.0.5) ...
Setting up cassandra (4.0.5) ...
Adding group `cassandra' (GID 138) ...
Done.
vm.max_map_count = 1048575
net.ipv4.tcp_keepalive_time = 300
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults

5. Checking Apache Cassandra Status

5.1. Checking Apache Cassandra Status

After the installation is completed, then we will check the status of Cassandra server and node to know weather it is running without any error use, by issuing following command lines:

$ systemctl status cassandra
$ nodetool status

Output :

● cassandra.service - LSB: distributed storage system for structured data
     Loaded: loaded (/etc/init.d/cassandra; generated)
     Active: active (running) since Fri 2022-12-09 21:46:10 WIB; 1h 15min ago
       Docs: man:systemd-sysv-generator(8)
    Process: 1209 ExecStart=/etc/init.d/cassandra start (code=exited, status=0/SUCCESS)
      Tasks: 48 (limit: 4577)
     Memory: 1.3G
        CPU: 2min 29.969s
     CGroup: /system.slice/cassandra.service
             └─1664 /usr/bin/java -ea -da:net.openhft... -XX:+UseThreadPriorities -XX:+HeapDumpOnOutOfM>

Des 09 21:46:09 infodiginet systemd[1]: Starting LSB: distributed storage system for structured data...
Des 09 21:46:10 infodiginet systemd[1]: Started LSB: distributed storage system for structured data.
Apache Cassandra Service
ramans@infodiginet:~$ 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  242.49 KiB  16      100.0%            b86413cf-dbfd-4b81-89cc-e46bcd361159  rack1

5.2. Checking Apache Cassandra Version

To check the Apache Cassandra version, we can use the command line in command tools, csql.

ramans@infodiginet:~$ cqlsh
Connected to Test Cluster at 127.0.0.1:9042
[cqlsh 6.0.0 | Cassandra 4.0.5 | CQL spec 3.4.5 | Native protocol v5]
Use HELP for help.
cqlsh> show VERSION
[cqlsh 6.0.0 | Cassandra 4.0.5 | CQL spec 3.4.5 | Native protocol v5]
Apache Cassandra csql

6. Apache Cassandra Service Management : to enable, stop, start and restart

To make it easier in managing Apache Cassandra, we are provided with a mechanism that has been prepared by the operating system layer, systemd which allows us to intervene with Cassandra services, such as: start, stop, enable and restart.

  1. Starting Cassandra service :
    sudo systemctl enable cassandra
  2. Stoping Cassandra service :
    sudo systemctl stop cassandra
  3. Restarting Cassandra service :
    sudo systemctl enable cassandra
  4. Enabling Cassandra service :
    sudo systemctl enable cassandra

Conclusion

In this short tutorial, we have learned how to install Apache Cassandra on the Ubuntu 22.04 operating system. Hopefully this tutorial can help those who are looking for references to install Apache Cassandra.

(Visited 269 times, 1 visits today)

You may also like