Skip to content

Instantly share code, notes, and snippets.

@JamesMenetrey
Forked from stat1x/cassandra_cluster.sh
Last active January 9, 2018 19:06
Show Gist options
  • Save JamesMenetrey/06f8832231ca310b3d63321bb8a6586a to your computer and use it in GitHub Desktop.
Save JamesMenetrey/06f8832231ca310b3d63321bb8a6586a to your computer and use it in GitHub Desktop.
Cassandra cluster
# Remove all running docker container
docker rm -f $(docker ps -a -q)
# Create the cluster
docker run -d -e "CASSANDRA_TOKEN=1" --name cassandra-1 spotify/cassandra:cluster
docker run -d -e "CASSANDRA_TOKEN=10" -e "CASSANDRA_SEEDS=$(docker inspect --format='{{ .NetworkSettings.IPAddress}}' cassandra-1)" --name cassandra-2 spotify/cassandra:cluster
docker run -d -e "CASSANDRA_TOKEN=100" -e "CASSANDRA_SEEDS=$(docker inspect --format='{{ .NetworkSettings.IPAddress}}' cassandra-1)" --name cassandra-3 spotify/cassandra:cluster
docker run -d -e "CASSANDRA_TOKEN=1000" -e "CASSANDRA_SEEDS=$(docker inspect --format='{{ .NetworkSettings.IPAddress}}' cassandra-1)" --name cassandra-4 spotify/cassandra:cluster
docker run -d -e "CASSANDRA_TOKEN=10000" -e "CASSANDRA_SEEDS=$(docker inspect --format='{{ .NetworkSettings.IPAddress}}' cassandra-1)" --name cassandra-5 spotify/cassandra:cluster
docker cp create_keyspace.sql cassandra-1:/tmp
docker exec -it cassandra-1 sh -c "/usr/bin/cqlsh \`nodetool ring | grep -oP \"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\" | head -n1\` < /tmp/create_keyspace.sql"
# OR
docker exec -it cassandra-1 sh -c "curl https://gist.githubusercontent.com/ZenLulz/06f8832231ca310b3d63321bb8a6586a/raw/125cd2ccd6e1619d6c7c4b60520521115bb56d8f/create_keyspace.sql | /usr/bin/cqlsh \`nodetool ring | grep -oP \"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\" | head -n1\`"
-- Drop any existing keyspace resto_NY
DROP KEYSPACE IF EXISTS resto_NY;
-- Create the keyspace (database) if it doesn't exist
CREATE KEYSPACE IF NOT EXISTS resto_NY
WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1};
-- Create the structure of the keyspace
USE resto_NY;
CREATE TABLE Restaurant (
id INT,
Name VARCHAR,
borough VARCHAR,
BuildingNum VARCHAR,
Street VARCHAR,
ZipCode INT,
Phone text,
CuisineType VARCHAR,
PRIMARY KEY(id)
);
CREATE INDEX fk_Restaurant_cuisine
ON Restaurant (CuisineType);
CREATE TABLE Inspection (
idRestaurant INT,
InspectionDate timestamp,
ViolationCode VARCHAR,
ViolationDescription VARCHAR,
CriticalFlag VARCHAR,
Score INT,
Grade VARCHAR,
PRIMARY KEY (idRestaurant, InspectionDate)
);
CREATE INDEX fk_Inspection_Restaurant
ON Inspection (Grade);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment