Apache Cassandra is a NoSQL database used for storing large amounts of data. It has a distributed architecture and is designed to manage large volumes of data with dynamic replication. It is used by thousands of companies to save and retrieve thousands of terabytes of data. Apache Cassandra is the best choice for you if you are looking for a database management system with scalability and high availability.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related database queries.
In this context, we shall look into how to install Apache Cassandra on Ubuntu OS.
To begin with this Installation procedure, simply follow the steps given below.
1. Install java
Apache Cassandra requires java to be running on the machine. Use these commands to install java on your system:
$ sudo apt update
$ sudo apt install openjdk-8-jdkTo verify if Java is installed, issue this command in Terminal:
$ java -version2. Install Apache Cassandra
Before proceeding towards the installation of Apache Cassandra, you will first need to install the apt-transport-https package. You can install it using this command:
$ sudo apt install apt-transport-httpsEnter the password for sudo. When prompted for continuation, press y.
Now import and add the GPG key using this command in the Terminal:
$ wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -If the key is added successfully, you will see OK in the output.
Now add the Apache Cassandra repository to apt list of sources using this command in the Terminal:
$ sudo sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 311x main" > /etc/apt/sources.list.d/cassandra.list'Update the apt list of sources using the command below in the Terminal:
$ sudo apt updateNow that the repository has been added, you can install Apache Cassandra using this command in the Terminal:
$ sudo apt install CassandraEnter the password for sudo. When prompted for continuation, press y.
After the installation of Apache Cassandra, its service starts automatically. To verify it, use the command below:
$ sudo systemctl status CassandraAlso, you can verify the status using the below command:
$ sudo nodetool statusNow the Apache Cassandra has been successfully installed. To login to Apache Cassandra, you can use the cqlsh command-line tool as follows:
$ cqlshHow to Rename Apache Cassandra Cluster ?
In the previous output, you can see the cluster name is "Test Cluster".
i. To change the default cluster name, log in to Cassandra using the cqlsh command-line tool as follows:
$ cqlshii. Then issue the command below in the Terminal to rename the Apache Cassandra Cluster to let's say "LinuxApt_cluster":
$ UPDATE system.local SET cluster_name = 'LinuxApt_cluster' WHERE KEY = 'local';Make sure to change the LinuxApt_cluster with your own desired name.
iii. Now to exit the cqlsh tool, type exit, and press Enter:
$ exitiv. Then edit the cassandra.yaml configuration file using the command below in the Terminal:
$ sudo nano /etc/cassandra/cassandra.yamlv. Now in the cassandra.yaml configuration file, search for the cluster_name.
Once you find it, change its name to your desired value.
vi. Then save and exit the file.
vii. Now to verify if the cluster name has been changed successfully, use the command below:
$ cqlshThe output below verifies that the cluster name has been changed successfully to LinuxApt_cluster.
How to Uninstall Apache Cassandra from Ubuntu ?
In case you need to remove Apache Cassandra from your machine, you can do this using the following steps:
i. Stop the service of Cassandra using the command below:
$ sudo service cassandra stopii. Then remove the library and log directories using these commands:
$ sudo rm -r /var/lib/cassandra
$ sudo rm -r /var/log/Cassandraiii. After that, uninstall Apache Cassandra using the command below:
$ sudo apt purge cassandraThis article covers how to install Apache Cassandra on Ubuntu 20.04 LTS. Apache Cassandra is an open-source non-relational database that delivers high performance, linear scalability, and continuous availability. All these features make Cassandra an ideal platform for mission-critical data.
To learn more about Apache Cassandra, visit its official documentation site.
How to install Java on Ubuntu ?
1. To check whether Java is installed, run the command:
$ java -version2. To install OpenJDK, execute the following apt command:
$ sudo apt install openjdk-8-jdk3. Once again, confirm that Java is installed by running the command:
$ java -versionHow to Install Apache Cassandra in Ubuntu ?
1. First, install the apt-transport-https package to allow access of repositories via the https protocol:
$ sudo apt install apt-transport-https2. Next, Import the GPG key using following wget command as shown:
$ wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -3. Then add Apache Cassandra's repository to the system’s sources list file as shown:
$ sudo sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 311x main" > /etc/apt/sources.list.d/cassandra.list'4. Before installing Apache Cassandra, you need to update the package list first:
$ sudo apt update5. Then install the NoSQL database using the command:
$ sudo apt install cassandra6. Usually, Apache Cassandra starts automatically. To confirm its status, run the following command:
$ sudo systemctl status cassandra7. Additionally, you can verify the stats of your node by running the command:
$ sudo nodetool status