DEV Community

Cover image for Deploying Cassandra Distributed NoSQL Database on Ubuntu 24.04
Sanskriti Harmukh for Vultr

Posted on with Aashish Chaurasiya • Originally published at docs.vultr.com

Deploying Cassandra Distributed NoSQL Database on Ubuntu 24.04

Apache Cassandra is an open-source distributed NoSQL database designed for high write throughput and linear horizontal scaling across many nodes. This guide deploys a single-node Cassandra instance using Docker Compose with persistent storage, then runs basic CQL operations to verify it. By the end, you'll have Cassandra accepting CQL queries on your server.


Set Up the Directory Structure

1. Create the project directory structure:

$ mkdir -p ~/cassandra-logging/cassandra-data
$ cd ~/cassandra-logging
Enter fullscreen mode Exit fullscreen mode

2. Set ownership for the Cassandra data directory:

$ sudo chown -R 999:999 cassandra-data
Enter fullscreen mode Exit fullscreen mode

3. Create the environment file:

$ nano .env
Enter fullscreen mode Exit fullscreen mode
CASSANDRA_CLUSTER_NAME=LogCluster
CASSANDRA_DC=datacenter1
CASSANDRA_RACK=rack1
Enter fullscreen mode Exit fullscreen mode

Deploy with Docker Compose

1. Create the Docker Compose manifest:

$ nano docker-compose.yaml
Enter fullscreen mode Exit fullscreen mode
services:
  cassandra:
    image: cassandra:latest
    container_name: cassandra
    hostname: cassandra
    ports:
      - "9042:9042"
    volumes:
      - "./cassandra-data:/var/lib/cassandra"
    environment:
      - CASSANDRA_CLUSTER_NAME=${CASSANDRA_CLUSTER_NAME}
      - CASSANDRA_DC=${CASSANDRA_DC}
      - CASSANDRA_RACK=${CASSANDRA_RACK}
      - CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch
    restart: unless-stopped
Enter fullscreen mode Exit fullscreen mode

2. Start the service:

$ docker compose up -d
Enter fullscreen mode Exit fullscreen mode

3. Verify the service is running:

$ docker compose ps
$ docker compose logs
Enter fullscreen mode Exit fullscreen mode

Cassandra takes a minute or two to fully come up. Wait until logs report Starting listening for CQL clients.


Access Cassandra

1. Open a CQL shell inside the container:

$ docker exec -it cassandra cqlsh
Enter fullscreen mode Exit fullscreen mode

2. Inspect the cluster, create a keyspace, and run sample DDL/DML:

DESCRIBE CLUSTER;

CREATE KEYSPACE logs WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};

USE logs;

CREATE TABLE application_logs (
  log_id UUID PRIMARY KEY,
  timestamp TIMESTAMP,
  level TEXT,
  message TEXT,
  service TEXT,
  host TEXT
);

INSERT INTO application_logs (log_id, timestamp, level, message, service, host)
VALUES (uuid(), toTimestamp(now()), 'INFO', 'Application started successfully', 'web-server', 'app-01');

SELECT * FROM application_logs;
SELECT COUNT(*) FROM application_logs;
EXIT;
Enter fullscreen mode Exit fullscreen mode

Next Steps

Cassandra is running and serving CQL queries. From here you can:

  • Add more nodes and switch the replication strategy to NetworkTopologyStrategy
  • Enable authentication and authorization via PasswordAuthenticator
  • Tune concurrent_writes, compaction, and JVM heap for your write workload

For the full guide with additional tips, visit the original article on Vultr Docs.

Top comments (0)