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
2. Set ownership for the Cassandra data directory:
$ sudo chown -R 999:999 cassandra-data
3. Create the environment file:
$ nano .env
CASSANDRA_CLUSTER_NAME=LogCluster
CASSANDRA_DC=datacenter1
CASSANDRA_RACK=rack1
Deploy with Docker Compose
1. Create the Docker Compose manifest:
$ nano docker-compose.yaml
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
2. Start the service:
$ docker compose up -d
3. Verify the service is running:
$ docker compose ps
$ docker compose logs
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
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;
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)