What is Cassandra and how to install it on Ubuntu 22.04
Cassandra is a powerful NoSQL database known for its scalability and fault-tolerance. It’s a top choice for many businesses running mission-critical applications. Installing Cassandra on Ubuntu 22.04 is a straightforward process that can be done in a few different ways.
You can install Cassandra on Ubuntu 22.04 using either the APT repository method or by using SNAP. Both methods are reliable and allow users to set up a single-node cluster quickly. The APT method involves adding Cassandra’s official repository, while SNAP offers a more containerized approach.
Once installed, users can run Cassandra as a single-node cluster or expand it to a multi-node setup for increased performance and redundancy. This flexibility makes Cassandra an excellent choice for both small projects and large-scale deployments on Ubuntu 22.04. Read about How to Install Cassandra on Ubuntu 22.04.
Preparing Ubuntu for Cassandra Installation
Before installing Cassandra, we need to set up Ubuntu with the necessary components. This involves updating the system, installing Java, and configuring the Cassandra repository.
System Update and Java Installation
Start by updating Ubuntu’s package lists:
sudo apt update
sudo apt upgrade -y
Cassandra requires Java to run. Install OpenJDK 11:
sudo apt install openjdk-11-jdk -y
Verify the Java installation:
java -version
This should display the version information for OpenJDK 11.
Configuring the Repository and GPG Key
Add the Cassandra repository to Ubuntu’s sources:
echo "deb https://debian.cassandra.apache.org 41x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.list
Install the required packages for adding a new repository:
sudo apt install curl gnupg -y
Download and add the GPG key:
curl https://downloads.apache.org/cassandra/KEYS | sudo apt-key add -
Update the package lists again:
sudo apt update
These steps prepare Ubuntu for Cassandra installation by setting up the necessary software and repositories.
Installing and Configuring Cassandra
Installing Cassandra on Ubuntu 22.04 involves several key steps. These include setting up the necessary packages, configuring the database, and verifying the installation.
Cassandra Installation Process
To install Cassandra on Ubuntu 22.04, first update the system’s package list:
sudo apt update
Next, install Cassandra:
sudo apt install cassandra
After installation, Cassandra will start automatically. To check its status:
systemctl status cassandra
If needed, restart Cassandra:
systemctl restart cassandra
For a multi-node setup, configure the firewall to allow Cassandra traffic between nodes.
Initial Configuration and Management
The main Cassandra configuration file is cassandra.yaml. It’s located in /etc/cassandra/. Key settings to adjust include:
- cluster_name: Set a unique name for your cluster
- seeds: List IP addresses of seed nodes
- listen_address: Set to the node’s IP address
- rpc_address: Set to 0.0.0.0 for remote access
After making changes, restart Cassandra:
systemctl restart cassandra
Ensure proper permissions on Cassandra directories:
sudo chown -R cassandra:cassandra /var/lib/cassandra
sudo chown -R cassandra:cassandra /var/log/cassandra
Testing the Cluster and Node Status
To check cluster status, use the nodetool command:
nodetool status
This shows the state of all nodes in the cluster.
To test connectivity, use cqlsh:
cqlsh
If successful, you’ll enter the Cassandra Query Language shell.
For multi-node setups, verify inter-node communication:
nodetool ring
This displays information about the cluster’s ring structure.
To test basic operations, create a keyspace and table in cqlsh:
CREATE KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
USE test;
CREATE TABLE users (id UUID PRIMARY KEY, name TEXT);
INSERT INTO users (id, name) VALUES (uuid(), 'John Doe');
SELECT * FROM users;
These commands create a simple schema and insert data, verifying basic functionality.