Skip to content

Instantly share code, notes, and snippets.

@diegopacheco
Last active September 22, 2022 19:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save diegopacheco/08dc5b9f94ef3d788c95c924b6d35f40 to your computer and use it in GitHub Desktop.
Save diegopacheco/08dc5b9f94ef3d788c95c924b6d35f40 to your computer and use it in GitHub Desktop.
How to setup a Cassandra 2.x Cluster in AWS EC2 / Amazon Linux

Cassandra 2.x Cluster on AWS EC2

Install java 8

Download and install Java JDK 8
# Remove java 7
sudo yum remove -y java

# Install basic packages
sudo yum install -y git

# Download and install java 8
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.tar.gz"
tar -xzvf jdk-8u161-linux-x64.tar.gz
rm -rf jdk-8u161-linux-x64.tar.gz

# Configure JAVA_HOME
sudo vim ~/.bashrc
ENV Vars $ sudo vim ~/.bashrc
alias cls='clear'

export JAVA_HOME=~/jdk1.8.0_161
export JRE_HOME=~/jdk1.8.0_161/jre
export PATH=$PATH:~/jdk1.8.0_161/bin:/~/jdk1.8.0_161/jre/bin

Cassandra 2.x

wget https://archive.apache.org/dist/cassandra/2.1.19/apache-cassandra-2.1.19-bin.tar.gz
tar -xzvf apache-cassandra-2.1.19-bin.tar.gz
rm -rf apache-cassandra-2.1.19-bin.tar.gz

Configure the Clsuter

# your_server_ip - copy the IP
hostname -i
vim ~/apache-cassandra-2.1.19/conf/cassandra.yaml
cluster_name: 'Test Cluster'
listen_address: your_server_ip
rpc_address: your_server_ip
seed_provider:
  - class_name: org.apache.cassandra.locator.SimpleSeedProvider
    parameters:
         - seeds: "ip1,ip2,...ipN"
endpoint_snitch: GossipingPropertyFileSnitch

Start up the cluster

# on each cass node... 
cd ~/apache-cassandra-2.1.19
bin/cassandra start

Open EC2 Security Group ports

7000
9160
9042

Test data replication with CQLSH

# Connect to any node - you can run: hostname -i to get the IP
apache-cassandra-2.1.19/bin/cqlsh $(hostname -i)
CREATE KEYSPACE CLUSTER_TEST WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 }; 
USE CLUSTER_TEST;
CREATE TABLE TEST ( key text PRIMARY KEY, value text);
INSERT INTO TEST (key,value) VALUES ('1', 'works');
SELECT * from TEST;
# Connect to any other node - you can run: hostname -i to get the IP - check for data replication
apache-cassandra-2.1.19/bin/cqlsh IP
USE CLUSTER_TEST;
SELECT * from TEST;
@diegopacheco
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment