How to Install Cassandra on Ubuntu 22.04
Choose a different version or distribution
Introduction
Before we begin talking about how to install Cassandra on Ubuntu 22.04 OS, let’s briefly understand – What is Cassandra?
Cassandra is a highly scalable and distributed NoSQL database system. It is designed to handle massive amounts of data across multiple servers, providing high availability and fault tolerance. Developed by Facebook, Cassandra offers a decentralized architecture that ensures no single point of failure.
Its flexible data model allows for dynamic schema changes and efficient data storage and retrieval. With its ability to handle large workloads and impressive performance, Cassandra is widely used in industries such as social media, e-commerce, and IoT applications.
In this tutorial, you will install Cassandra on Ubuntu 22.04. We will also address a few FAQs on how to install Cassandra on Ubuntu 22.04.
Advantages of Cassandra
- Scalability: Cassandra scales horizontally to handle large amounts of data across multiple servers.
- High Availability: It ensures data accessibility even in the event of server failures.
- Fault Tolerance: With a decentralized architecture, it eliminates single points of failure.
- Flexible Data Model: Cassandra allows dynamic schema changes, making it easy to adapt to evolving data requirements.
- Performance: It delivers impressive read and write speeds, making it suitable for demanding workloads.
Prerequisites to Install Cassandra on Ubuntu 22.04
- Ubuntu 22.04 Server
- A non-root user with Sudo privileges
Step 1 – Install the Oracle Java Virtual Machine
Java Runtime Environment (JRE) is essential for using Cassandra. In this step, you will install and verify that it is the default JRE.
1) Firstly, you will update the package database using the following command:
sudo apt-get update
2) Now, install default JRE. This will become your default JRE after installation.
sudo apt install default-jre -y
4) To verify that this is your default JRE, use the following command:
java -version
An output similar to the following should appear:
Output
openjdk version "11.0.19" 2023-04-18
OpenJDK Runtime Environment (build 11.0.19+7-post-Ubuntu-0ubuntu122.04.1)
OpenJDK 64-Bit Server VM (build 11.0.19+7-post-Ubuntu-0ubuntu122.04.1, mixed mode, sharing)
Step 2 – Install Cassandra
1) The next step is to install Cassandra by utilizing packages that are available at Apache Software Foundation repository. To ensure that the packages are available to your system, add the repository by using the following command:
echo "deb https://debian.cassandra.apache.org 41x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
2) Then, you will add public keys from the Apache Software Foundation linked to the package repositories to avoid unwarranted package signature warnings during package updates:
curl https://downloads.apache.org/cassandra/KEYS | sudo apt-key add -
3) After adding the key, again update the package using the following command:
sudo apt-get update
4) Finally, install Cassandra using:
sudo apt-get install cassandra -y
Step 3 – Troubleshooting and Starting Cassandra
1) Usually, by now, Cassandra should be up and running automatically but if you face any bug, it does not start. To inspect if it is running, use the following command:
sudo service cassandra status
This output should appear if it is not running:
Output
...
* could not access pidfile for Cassandra
2) This is a very common problem with the latest version of Apache Cassandra on Ubuntu.
Use the following fixes:
Firstly, edit the init script. The parameter which is to be modified is on line 60 of that script, access it using:
sudo nano +60 /etc/init.d/cassandra
The following should appear:
/etc/init.d/cassandra
CMD_PATT="cassandra.+CassandraDaemon"
3) You must change it to the following path at /etc/init.d/cassandra
.
CMD_PATT="cassandra"
4) Then, reboot using the following command:
sudo reboot
or use this for rebooting:
sudo shutdown -r now
5) After rebooting, Cassandra should be running, which can be verified by this command:
sudo service cassandra status
If it is running, you will see this:
Output
● cassandra.service - LSB: distributed storage system for structured data
Loaded: loaded (/etc/init.d/cassandra; generated)
Active: active (running) since Mon 2023-06-19 07:42:46 UTC; 24s ago
Docs: man:systemd-sysv-generator(8)
Process: 32461 ExecStart=/etc/init.d/cassandra start (code=exited, status=0/SUCCESS)
Tasks: 45 (limit: 2307)
Memory: 1.3G
CPU: 17.480s
CGroup: /system.slice/cassandra.service
└─32613 /usr/bin/java -ea -da:net.openhft... -XX:+UseThreadPriorities -XX:+HeapDumpOnOutOfMemoryError -Xss256k -XX:+AlwaysPreTouch -XX:-UseBiasedLocking -XX:+UseTLAB -XX:+ResizeTL>
Jun 19 07:42:46 ip-172-31-93-56 systemd[1]: Starting LSB: distributed storage system for structured data...
Jun 19 07:42:46 ip-172-31-93-56 systemd[1]: Started LSB: distributed storage system for structured data.
Step 4 – Connecting to the Cluster
1) On successful installation of Cassandra, the status of the cluster can be checked using the following command:
sudo nodetool status
The following output will appear:
Output
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 127.0.0.1 104.37 KiB 16 100.0% 0f71074a-0df7-4596-ae60-4523427f8666 rack1
Here, “UN” means Up and Normal.
2) To connect it using this interactive command-line interface.
cqlsh
The following output will appear:
Output
Connected to Test Cluster at 127.0.0.1:9042
[cqlsh 6.1.0 | Cassandra 4.1.2 | CQL spec 3.4.6 | Native protocol v5]
Use HELP for help.
cqlsh>
3) To exit, use this:
exit
FAQs to Install Cassandra on Ubuntu 22.04
What are the system requirements for installing Cassandra on Ubuntu 22.04?
You'll need a 64-bit Ubuntu 22.04 system with Java Development Kit (JDK) version 8 or higher installed.
How do I add the Cassandra repository to Ubuntu 22.04?
You can add the Cassandra repository by creating a new file in /etc/apt/sources.list.d/
and adding the repository details.
How do I start and stop the Cassandra service on Ubuntu 22.04?
Use the commands sudo service cassandra start
to start and sudo service cassandra stop
to stop the Cassandra service.
Where can I find the Cassandra configuration files on Ubuntu 22.04?
The Cassandra configuration files are located in the /etc/cassandra/
directory on Ubuntu 22.04.
Can I access Cassandra through a web-based interface on Ubuntu 22.04?
Yes, you can access the Cassandra web-based interface, Cassandra Query Language (CQL) shell, by running the command cqlsh
.
How can I verify if Cassandra is running on Ubuntu 22.04?
You can use the command nodetool status
in the Cassandra bin directory to check the status of the Cassandra cluster.
Conclusion
We hope this detailed tutorial helped you understand how to install Cassandra on Ubuntu 22.04. To know more about Cassandra, visit the official documentation.
If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.