How to Install and Configure Apache Cassandra on Ubuntu 20.04

how to install and configure apache cassandra on ubuntu 18.04

Apache Cassandra is a free and open source NoSQL database it helps to maintain large quantity of data. Apache Cassandra is a scalable and it gives high availability without failure. It’s a distributed database system with the best performance.

In this tutorial we are going to learn how to install and setup Apache Cassandra on Ubuntu 20.04. Let’s begin the Apache Cassandra installation.

Install JAVA:

Before Installing Apache Cassandra we need to install java on our Ubuntu 20.04 server. To install the OpenJDK 8 run the command below.

Update the packages, then install OpenJDK

sudo apt update
sudo apt install openjdk-8-jdk

After the java installation now check the java version.

java -version
Output

openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1ubuntu1-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

Install Apache Cassandra:

To install the Apache Cassandra on your Ubuntu 18.04 server add the Apache repository to the Ubuntu 20.04 server.

Import the GPG key from the repository, then add Apache Cassandra repository.

wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
sudo sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 311x main" > /etc/apt/sources.list.d/cassandra.list'

Successfully you have enabled the repository, now update the packages and install Apache Cassandra on Ubuntu 20.04.

sudo apt update
sudo apt install cassandra

After the successful installation Apache Cassandra starts running automatically.

Now open the cassandra-env.sh file, then uncomment the below line and the change <public name> to 127.0.0.1

sudo nano /etc/cassandra/cassandra-env.sh
JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=<127.0.0.1>"

Save and exit.

sudo systemctl restart cassandra

To check the status of Apache Cassandra run the command below.

sudo nodetool status
Output

Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load       Tokens       Owns (effective)  Host ID                               Rack
UN  127.0.0.1  154.2 KiB  256          100.0%            cbfd239e-7001-41b4-9f61-eb16c9980cbf  rack1

All going good will move to the Apache Cassandra configuration process.

Apache Cassandra Configuration:

Apache Cassandra are listening to localhost by default, so we don’t have to change because if the client connecting to the database it also runs on same host.

Apache Cassandra configuration files are in etc/cassandra directory, datas are stored in /var/lib/cassandra file and the java options are configured in etc/default/cassandra

Use CQL (The Cassandra Query Language) for the interaction with Cassandra.

sudo cqlsh
Output

Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.7 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh>

To exit CQL terminal type exit and enter.

Rename Cluster:

Test cluster is the default name of Cassandra cluster. To rename the Cassandra cluster first login to the Cassandra CQL then rename it

To login the Cassandra CQL run the commands below.

sudo cqlsh

To Rename the Cassandra Cluster name whatever you want run the commands below.

UPDATE system.local SET cluster_name = 'Technologytu Cluster' WHERE KEY = 'local';

Type exit to exit the CQL terminal.

To edit the configuration.yaml file run the commands below.

sudo nano /etc/cassandra/cassandra.yaml

In the cluster name field change your cassandra cluster name

cluster_name: 'Technologytu Cluster'

Afterthat clear your system cache then restart.

sudo nodetool flush system
sudo systemcl restart cassandra

Note: If you’re getting any errors while checking status, login to CQL terminal or clearing cache try after 15 seconds.

Conclusion:

Congratulations! We have successfully installed and configured Apache Cassandra on our Ubuntu 20.04 server. Hope this helps.

Next Article: How to Install Apache Web Server on Ubuntu 16.04

1 comment
Leave a Reply

Post your comments here

You May Also Like