Cassandra
Installation Guide
Brew Package Manager
Apache Cassandra
Database Setup

Brew Cassandra Installation

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Apache Cassandra is a highly scalable, distributed, and fault-tolerant NoSQL database system designed to handle large data across many commodity servers without any single point of failure. It offers robust support for clusters spanning across multiple data centers, with asynchronous replication for low latency. In this guide, we'll walk through the process of installing Apache Cassandra on a macOS system using Homebrew, a popular package manager.

Prerequisites

Before diving into the Cassandra installation using Homebrew, make sure that you have Homebrew installed on your macOS system. To verify whether Homebrew is installed, type the following command in the terminal:

bash
brew --version

If Homebrew is not installed, you can install it using the command:

bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Make sure your system has Java Development Kit (JDK) since Cassandra runs on the Java platform. You can install OpenJDK via Homebrew:

bash
brew install openjdk@11

After installation, ensure that your JAVA_HOME is set correctly:

bash
export JAVA_HOME=$(/usr/libexec/java_home -v 11)

Installing Apache Cassandra

  1. Adding the DataStax repository:
    Homebrew does not include Apache Cassandra by default. We need to tap into the DataStax repository to access Cassandra binaries. Use the following command:
bash
   brew tap datastax/ds-{project_name}

Replace {project_name} with the version-specific repository you want to tap into.

  1. Installing Cassandra:
    Once the repository is tapped, you can install Cassandra by executing:
bash
   brew install cassandra
  1. Verifying Installation:
    Confirm that Cassandra is installed successfully by checking its version:
bash
   cassandra -v

This should output the installed version of Cassandra.

Configuring Cassandra

After installation, Cassandra needs to be configured for optimal performance and to match the system's architecture.

  1. Configuration Files:
    Cassandra's primary configuration file is cassandra.yaml. You can find it in:
bash
   /usr/local/etc/cassandra/cassandra.yaml

Key configuration settings to consider editing:

  • Cluster Name: Ensure the cluster name is set correctly to join nodes.
  • Listen Address: Set the listen_address to the IP address that other nodes will use to communicate.
  • Seeds: Modify the seeds section under seeds_provider to list the IP addresses of the seed nodes in the cluster.
  • Logging Configurations: The log properties can be found in logback.xml and logging levels can be modified as per requirements.
  1. Java Options:
    Edit the file cassandra-env.sh to adjust JVM options based on system resources.

Starting and Stopping Cassandra

To start Cassandra as a background process:

bash
brew services start cassandra

To stop the service:

bash
brew services stop cassandra

For manual start without using Homebrew services:

bash
cassandra

To stop it manually, you may need to find the PID of the process and kill it:

bash
pkill -f CassandraDaemon

Testing and Using Cassandra

Once Cassandra is up and running, you can interact with it using cqlsh, the command line shell for interacting with Cassandra using CQL (Cassandra Query Language).

  1. Launching cqlsh:
    To start cqlsh, enter the command:
bash
   cqlsh
  1. Basic Commands:
    Here are basic CQL commands to create a keyspace and a table:
sql
1   CREATE KEYSPACE testkeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 };
2
3   USE testkeyspace;
4
5   CREATE TABLE users (user_id UUID PRIMARY KEY, name TEXT, age INT);
6
7   INSERT INTO users (user_id, name, age) VALUES (uuid(), 'John Doe', 30);
8
9   SELECT * FROM users;

Summary Table

ComponentCommandNotes
Homebrew Install/bin/bash -c "$(curl -fsSL ...)Check Homebrew site for updates.
Java Installbrew install openjdk@11Ensure JAVA_HOME is set.
Add DataStax Repobrew tap datastax/ds-{project_name}Necessary before Cassandra install.
Install Cassandrabrew install cassandraInstalls the latest stable version.
Start Cassandrabrew services start cassandraRuns Cassandra as a service.
Stop Cassandrabrew services stop cassandraStops Cassandra running as a service.
Start cqlshcqlshCommand line interface for Cassandra queries.

Conclusion

Installing Apache Cassandra on macOS using Homebrew simplifies the process greatly due to the streamlined package management that Homebrew offers. With Cassandra set up, you can start utilizing its data distribution capabilities to manage large volumes of data efficiently. Make sure to continuously monitor and fine-tune configuration files for achieving optimal performance.


Course illustration
Course illustration

All Rights Reserved.