
Cassandra is a distributed, highly available NoSQL database designed for handling large volumes of data across multiple servers. Originally developed at Facebook, it provides linear scalability and fault tolerance with no single point of failure when deployed as a multi-node cluster. Cassandra's columnar data model and tunable consistency make it ideal for storing time-series log data where write performance and horizontal scalability are critical.
In this article, you will deploy Cassandra using Docker Compose and configure persistent storage for database files. You will access Cassandra through its CQL (Cassandra Query Language) shell to create keyspaces, tables, and manage log data.
Before you begin, you need to:
sudo privileges.In this section, you prepare the required directory structure for Cassandra and define environment variables in a .env file.
Create the directory structure for Cassandra.
This directory stores commit logs, data files, and hints for the Cassandra cluster.
Navigate into the cassandra-logging directory.
Set proper ownership for the Cassandra data directory. Cassandra runs as the cassandra user (UID 999) inside the container.
Create a .env file.
Add the following variables:
Modify these values based on your cluster topology requirements.
Save and close the file.
In this section, you create and deploy the Docker Compose stack that runs Cassandra. Docker Compose manages the container and applies the environment variables from your .env file.
Create a new Docker Compose manifest.
Add the following content.
Save and close the file.
This deployment defines:
./cassandra-data) stores all database files including SSTables, commit logs, and saved caches permanently..env file:Create and start the service.
Verify that the service is running.
Output:
The container is running with a healthy status. Cassandra is accepting CQL connections on port 9042.
Monitor Cassandra initialization logs. The database requires 30-60 seconds for initial startup.
Wait until you see messages indicating the node is ready:
Press Ctrl + C to exit the log view.
For more information on managing a Docker Compose stack, see the How To Use Docker Compose article.
This section walks through validating your Cassandra setup using the CQL shell to establish a keyspace, design table structures, and insert test log records.
Access the CQL shell inside the container.
Output:
Check cluster status.
Output displays your cluster name (LogCluster) and the Cassandra version.
Create a keyspace for log storage. Keyspaces in Cassandra are analogous to databases in relational systems.
The SimpleStrategy is appropriate for single-datacenter deployments with a replication factor of 1.
Use the newly created keyspace.
Create a table for application logs.
Insert a sample log entry.
Query the log data.
Output displays your inserted log entry:
Count total log entries.
Output:
Exit the CQL shell.
You have successfully deployed Cassandra for log management with durable data persistence. This single-node deployment uses Docker Compose for reliable container orchestration with local volume storage protecting your data during restarts and upgrades. The Cassandra node operates at full capacity, prepared to receive time-series log entries through CQL drivers, manage write-heavy workloads efficiently, and expand into a multi-node cluster when horizontal scaling becomes necessary for growing log volumes.
0 Comments
Be the first to comment and share your perspective with the community.