Apache Cassandra is a highly scalable NoSQL database designed to handle large amounts of data across many commodity servers, providing high availability with no single point of failure. In this guide, we will walk you through the steps to install Apache Cassandra on a single-node cluster running Ubuntu 22.04. Whether you are deploying it on a local server or using a Windows VPS UK, this tutorial covers all the necessary steps.
Step 1: Update Your System
Before installing Cassandra, ensure your system is up to date. Run the following commands:
sudo apt update && sudo apt upgrade -y
Keeping your system updated is crucial for security and performance, whether you're setting it up locally or on a VPS Windows Servers platform.
Step 2: Install Java
Apache Cassandra requires Java. Install OpenJDK by running:
sudo apt install openjdk-11-jdk -y
Verify the Java installation:
java -version
Step 3: Add the Cassandra Repository
Add the Apache Cassandra repository to your system:
echo "deb https://apache.claz.org/cassandra/debian/ 40x main" | sudo tee /etc/apt/sources.list.d/cassandra.sources.list
curl -fsSL https://apache.claz.org/cassandra/KEYS | sudo apt-key add -
Step 4: Install Cassandra
Update the package list and install Cassandra:
sudo apt update
sudo apt install cassandra -y
Step 5: Start Cassandra
Start the Cassandra service and enable it to run on boot:
sudo systemctl start cassandra
sudo systemctl enable cassandra
Step 6: Verify Cassandra Installation
You can verify that Cassandra is running by checking its status:
sudo systemctl status cassandra
You should see the service as "active (running)".
Step 7: Access Cassandra Shell
To access the Cassandra Query Language shell (CQLSH), run:
cqlsh
This will connect you to the default keyspace and allow you to run queries.
Step 8: Create a Keyspace
You can create a keyspace by running the following command in CQLSH:
CREATE KEYSPACE my_keyspace WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1};
Replace my_keyspace
with your desired keyspace name.
Step 9: Create a Table
To create a table within your keyspace, use:
USE my_keyspace;
CREATE TABLE users (id UUID PRIMARY KEY, name text, email text);
Step 10: Insert Data into the Table
To insert data into your table, run:
INSERT INTO users (id, name, email) VALUES (uuid(), 'John Doe', 'john@example.com');
Step 11: Query Data from the Table
To query the data you just inserted, use:
SELECT * FROM users;