Skip to content

Instantly share code, notes, and snippets.

@Glamdring
Last active July 26, 2020 09:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Glamdring/ee5f24dbef3795a860ac91c9c14255a2 to your computer and use it in GitHub Desktop.
Save Glamdring/ee5f24dbef3795a860ac91c9c14255a2 to your computer and use it in GitHub Desktop.
#!/bin/sh
# No sudo, as init scripts run as root
BUCKET_NAME=$1
STACK_NAME=$2
EC2_AVAIL_ZONE=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone`
EC2_REGION="`echo \"$EC2_AVAIL_ZONE\" | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'`"
REGION_PREFIX="`echo ${EC2_REGION: : -2}`"
BIND_IP=`curl -s http://169.254.169.254/latest/meta-data/local-ipv4`
echo "Bucket name for fetching configuration is $BUCKET_NAME"
echo "Current region is $REGION"
# First we need Java8 (Cassandra is not yet well tested with Java 9)
yum -y update
yum -y remove java
yum -y install java-1.8.0-openjdk
# Install cassandra
cat <<EOT >> /etc/yum.repos.d/cassandra.repo
[cassandra]
name=Apache Cassandra
baseurl=https://www.apache.org/dist/cassandra/redhat/311x/
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://www.apache.org/dist/cassandra/KEYS
EOT
yum -y install cassandra
#TODO configure cassandra, e.g. memory in /etc/cassandra/conf/jvm.options
# Copy configuration from S3
aws s3 cp s3://$BUCKET_NAME/cassandra.yaml.template /etc/cassandra/conf/cassandra.yaml
python /tmp/install/update-cassandra-cluster-config.py $STACK_NAME
service cassandra start
chkconfig cassandra on
while ! echo exit | nc $BIND_IP 9042; do sleep 10; done
cqlsh -e "CREATE KEYSPACE IF NOT EXISTS logsentinel WITH REPLICATION = { 'class': 'NetworkTopologyStrategy', '$REGION_PREFIX': 3 } AND DURABLE_WRITES = true;" $BIND_IP 9042
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment