Skip to content

Instantly share code, notes, and snippets.

@twysto
Last active October 29, 2024 15:07
Show Gist options
  • Save twysto/620aa907630c7c55009ec5f76a5b9d3d to your computer and use it in GitHub Desktop.
Save twysto/620aa907630c7c55009ec5f76a5b9d3d to your computer and use it in GitHub Desktop.
Install Apache Cassandra 5.0.2 as a Tarball binary file + Quickstart

Inspired by: https://cassandra.apache.org/doc/latest/cassandra/getting-started/index.html

Prerequisites

Install Java 17

Note: Stick to Java 17.

Installing a more recent version (Java 17+) will fail when running Cassandra with error:

Exception (java.lang.UnsupportedOperationException) encountered during startup: The Security Manager is deprecated and will be removed in a future release

sudo apt-get install openjdk-17-jre
sudo update-alternatives --config java

Install Python

Note: Install Python v3.8-3.11 or above.

In this example, we will install Python v3.13

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.13

Install Cassandra 5.0.2 as a Tarball binary file

cd $HOME

Download

curl -OL https://archive.apache.org/dist/cassandra/5.0.2/apache-cassandra-5.0.2-bin.tar.gz

Check the Tarball integrity

Compare the signature with the SHA256 file:

curl -L https://archive.apache.org/dist/cassandra/5.0.2/apache-cassandra-5.0.2-bin.
tar.gz.sha256

The result shoud be equal to: d721834207838b9d01919dfc33625ad17b50fea03bf9f76cdd8d3ae3a8fd2947

Untar Cassandra into a folder

tar xzvf apache-cassandra-5.0.2-bin.tar.gz

Quickstart

Create a small test project

mkdir cassandra-store && cd $_

Run the Cassandra server (in a separate shell)

~/apache-cassandra-5.0.2/bin/cassandra

Create a data.cql script

nano data.cql

Paste this content, and then save the data.cql file:

CREATE KEYSPACE IF NOT EXISTS store WITH REPLICATION =
{ 'class' : 'SimpleStrategy',
'replication_factor' : '1'
};

CREATE TABLE IF NOT EXISTS store.shopping_cart (
    userid text PRIMARY KEY,
    item_count int,
    last_update_timestamp timestamp
);

INSERT INTO store.shopping_cart
    (userid, item_count, last_update_timestamp)
    VALUES ('9876', 2, toTimeStamp(now()));
INSERT INTO store.shopping_cart
    (userid, item_count, last_update_timestamp)
    VALUES ('1234', 5, toTimeStamp(now()));

Load data with cqlsh

~/apache-cassandra-5.0.2/bin/cqlsh -f ./data.cql 

Read data with cqlsh

~/apache-cassandra-5.0.2/bin/cqlsh -e "SELECT * FROM store.shopping_cart;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment