
How To Install Cassandra and Run a Single-Node Cluster On Ubuntu 24.04
Welcome back to the Greenhost.cloud blog! Today, we’re going to dive into the world of distributed databases by walking you through the installation of Apache Cassandra on Ubuntu 24.04. We’ll set up a single-node cluster, perfect for development and testing. Let’s get started!
What is Apache Cassandra?
Apache Cassandra is a highly scalable, distributed NoSQL database that is designed to handle large amounts of data across many servers while providing high availability with no single point of failure. Its unique architecture allows it to handle massive workloads across multiple nodes, making it a popular choice for applications that require reliability and scalability.
Prerequisites
Before we begin, make sure you have the following:
- An Ubuntu 24.04 server (or desktop) with superuser privileges.
- Java Development Kit (JDK) 8 or above installed.
- Basic knowledge of terminal commands.
Step 1: Update Your System
First, let’s make sure your system is up-to-date. Open your terminal and run the following commands:
sudo apt update
sudo apt upgrade -y
Step 2: Install Java
Cassandra runs on Java, so we need to install the Java Development Kit (JDK). We’ll use OpenJDK 11 for this guide:
sudo apt install openjdk-11-jdk -y
To verify the installation, run:
java -version
You should see output indicating that Java is installed.
Step 3: Add the Cassandra Repository
Next, we need to add the Apache Cassandra repository to your system. First, import the public key:
wget -qO - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
Now, add the repository to your sources list:
echo "deb http://apache.mirrors.spacedump.net/cassandra/debian/ 311x main" | sudo tee /etc/apt/sources.list.d/cassandra.sources.list
Make sure to replace 311x
with the appropriate version if you want a different version of Cassandra. You can check the Apache Cassandra download page for available versions.
Step 4: Install Cassandra
Now that we have the repository set up, let’s install Cassandra:
sudo apt update
sudo apt install cassandra -y
Step 5: Start and Enable Cassandra
After the installation, start the Cassandra service and enable it to start on boot:
sudo systemctl start cassandra
sudo systemctl enable cassandra
To check if Cassandra is running correctly, use the following command:
sudo systemctl status cassandra
You should see an active (running) status.
Step 6: Configure Cassandra
Cassandra’s configuration file is located at /etc/cassandra/cassandra.yaml
. For a single-node cluster, we need to ensure that the following settings are appropriate for your environment:
- Listen Address: This should be set to the IP address of your server or
localhost
for local testing. - RPC Address: This should also be set to the IP address of your server or
localhost
. - Seed Provider: For a single-node cluster, you can leave the default settings.
To edit the configuration file, run:
sudo nano /etc/cassandra/cassandra.yaml
Make the necessary changes, then save and exit the file.
Step 7: Restart Cassandra
After making changes to the configuration file, restart the Cassandra service:
sudo systemctl restart cassandra
Step 8: Verify Cassandra Installation
To verify that Cassandra is running correctly, you can use the cqlsh
command-line interface. Run the following command:
cqlsh
If everything is set up correctly, you should see the CQL shell prompt indicating that you are connected to your Cassandra cluster.
Step 9: Basic Commands in CQL
Now that you’re in the CQL shell, you can run some basic commands. For example, create a keyspace:
CREATE KEYSPACE test_keyspace WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1};
You can then use this keyspace:
USE test_keyspace;
And create a table:
CREATE TABLE users (user_id UUID PRIMARY KEY, name text, age int);
Conclusion
Congratulations! You have successfully installed Apache Cassandra and set up a single-node cluster on Ubuntu 24.04. You can now explore the capabilities of Cassandra and start developing your applications with confidence.
For more tutorials and articles on cloud technology, database management, and more, stay tuned to the Greenhost.cloud blog.