This tutorial is to guide the steps used for the installation of Apache Cassandra database on Ubuntu 22.04 LTS Jammy JellyFish Linux.
Cassandra is, along with MongoDB, one of the most popular NoSQL databases at the moment. Cassandra is designed as a scalable, fail-safe system for handling large amounts of data on distributed systems (clusters). Unlike CouchDB and MongoDB(C++), this one is written in Java like Apache HBase. Since version 0.8, the Cassandra Query Language has been introduced, a SQL-like query language that can serve as a simple interface.
Cassandra is written in Java and RubyGems and only runs on UNIX-like systems, such as Mac OS X and Linux. Especially with relational databases, familiar developers should take a closer look at the structure and the data model of Cassandra, as there are certain similarities in the data model in addition to fundamentally new terms also some familiar ones appear, which, however, have a completely different meaning with Cassandra.
In addition, scaling out by adding additional DB nodes would also distribute transactions to the individual nodes, which by definition complicates the ACID properties of a database transaction.
Cassandra is mainly administered via the command line, although there are now some graphical tools provided by DataStax. The freely available OpsCenter, for example, is a management and monitoring tool for Cassandra clusters.
Steps to install Apache Cassandra on Ubuntu 22.04 LTS
The steps given here to set up Cassandra can be used for other Ubuntu versions such as 20.04/18.04 including POP_OS and Debian. Your system should have at least 2 cores, and 8GB of RAM. We also need Java 8 or Java 11 on our system to set up this NoSQL database and Python 3.6+ to use its command-line tool called cqlsh.
#1st Method using SNAP:
1. Install Cassandra using SNAP
The first and simplest way to install the Apache Cassandra on Ubuntu 22.04 is using the SNAP. It is an universal and APT alternative package manager on Ubuntu systems, enabled by default. It helps the users to install the applications in an isolated environment yet accessiable like any other application.
sudo snap install cassandra
#2nd method using Cassandra Official repository
2. Update Ubuntu 22.04
Before using any further commands let’s first run the system update and upgrade command to ensure our system is up to date. It also important because in this method we are about to use APT package manager to install Cassandra database.
sudo apt update && sudo apt upgrade
sudo apt install apt-transport-https
3. Install OpenJDK
We don’t need to add any repository for getting Java on our Linux system. We can use the APT package manager to set it up.
sudo apt install default-jdk
To check the version after the installation use:
4. Add GPG Key
First import the key from the Ubuntu Keyserver for Cassandra.
gpg --keyserver keyserver.ubuntu.com --recv-keys 7E3E87CB
Now, export it to GPG fromat and readable by our system to use for the repository we are going to add for Cassandra.
gpg --export --armor 7E3E87CB | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/cassandra-key.gpg
5. Add Cassandra Repository on Ubuntu 22.04
We cannot install the Cassandra Database directly using the official repository of Ububntu 22.04. Hence, we need to add the one made available by its developers:
Note: Add only one repository from the given ones.
For Cassandra version 4.0.x add the following repo
sudo sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 40x main" > /etc/apt/sources.list.d/cassandra.list'
Whereas, the users who want to try out version 4.1.x add this one (optional)
sudo sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 41x main" > /etc/apt/sources.list.d/cassandra.list'
After adding repository it is necessary to run the system update command to refresh the APT package index cache.
sudo apt update
6. Install Apache Cassandra
Now, we can use the APT package manager to install the Cassandra database on Ubuntu using the command terminal. The benefit of using this method is we can easily update this Database system in future with the usage of system update command.
sudo apt install cassandra
7. Check Apache Cassandra Status
Once the installation is completed, to check the status of Cassandra server and node to know weather it is running without any error use:
systemctl status cassandra --no-pager -l
The green colour active status means it is running fine.
The UN in the output means it is running fine.
8. Command to enable, stop, start and restart
Well, the installation of this Database system will also create a system service to easily manage it and run in the backround.
To Enable the service, so that Cassandra service can start with system boot use:
sudo systemctl enable cassandra
To start the service:
sudo systemctl start cassandra
To restart it:
sudo systemctl restart cassandra
To stop the service use:
sudo systemctl stop cassandra
9. How to check Cassandra version on Ubuntu 22.04
To check the version of Cassandra on Ubuntu, we can use its command tool known as cqlsh.
First type the given command on your terminal to access the tool:
Now to check the version, simply use:
To exit the command line of the tool, we can use:
10. How to update
Here we have used two ways to install Cassandra on Ubuntu 22.04, hence as per your method, use the given command to update your database instance:
For SNAP users:
sudo snap refresh cassandra
For APT repository method:
sudo apt update && sudo apt upgrade
11. Uninstall or Remove
In case you don’t require the Cassandra Database instance anymore on your Ubuntu 22.04 server, then use the appropriate command to uninstall it, depending upon the method your have used to set it up.
sudo snap remove cassandra
For APT users:
sudo apt autoremove --purge cassandra
To remove GPG and repo as well:
sudo rm /etc/apt/sources.list.d/cassandra.list
sudo rm /etc/apt/trusted.gpg.d/cassandra-key.gpg
A special feature of Cassandra is the simple horizontal scalability. To add more nodes, the user only has to distribute the complete Cassandra package including the configuration files to the other nodes after the Cassandra installation on the first node, for which various tools, such as Capistrano, can be used.
If you are facing any problem while using the above given commands then do leave comments and will try to solve that.
⇒ How To Install Apache Cassandra on AlmaLinux 8 | Rocky Linux 8
⇒ How to install Linux kernal 5.19 on Ubuntu 22.04/20.04
⇒ How to Edit Files as Root in Ubuntu GUI File Manager
⇒ 3 Ways to install MySQL Workbench on Ubuntu 22.04