Skip to content

Instantly share code, notes, and snippets.

@ulises
Last active October 7, 2016 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ulises/b467ab7686fb65fe58ae to your computer and use it in GitHub Desktop.
Save ulises/b467ab7686fb65fe58ae to your computer and use it in GitHub Desktop.
#!/bin/sh
# This script only sets up a cluster of C* nodes on the same box; its purpose
# is only to show which config files need setting up, and how to set the
# environment variables to pick up the different configs
# It relies on you having downloaded the DSE version you want to install
# PS: This script makes no effort to bind the services to the right
# addresses. It will bind everything to lo aliases just like ccm
# PS2: This script makes no attempt at balancing the token ranges each node
# will be responsible for. This is your responsibility.
# change here for other tarballs
TARBALL="dse.tar.gz"
###
# You shouldn't need to change anything below here
###
CLUSTER_NAME=$1;
shift;
C_NODES=$1
printf "~= cluster: %s, %d nodes =~\n" "$CLUSTER_NAME" "$C_NODES"
if [ -z $DSE_HOME ]; then
printf "* Unpacking %s...\n" $TARBALL
tar zxf $TARBALL
DSE_HOME=`ls | grep dse | grep -v tar | grep -v sh`
fi
printf "Will install from %s\n\n" $DSE_HOME
# create directories for holding the node's data, logs, etc.
create_dirs()
{
node=$1
mkdir -p node$node/data/{dse-data,commitlog,saved_caches}
mkdir -p node$node/logs
}
# copy the relevant sections of the config for a service (includes bin for
# selected services like cassandra or hadoop)
copy_config()
{
node=$1
base_dir=$2
service=$3
src="$base_dir/resources/$service/conf"
dst="node$node/resources/$service"
mkdir -p $dst
cp -r $src $dst
}
# adjust the cassandra config for a node
tweak_cassandra_config()
{
env="node$1/resources/cassandra/conf/cassandra-env.sh"
conf="node$1/resources/cassandra/conf/cassandra.yaml"
logs="node$1/resources/cassandra/conf/logback.xml"
base_data_dir="node$1/data"
# Set the cluster name
printf " - Setting up the cluster name\n"
regexp="s/Test Cluster/$CLUSTER_NAME/g"
sed -i -- "$regexp" $conf
# Set the JMX port
printf " - Setting up JMX port\n"
port="7${1}99"
regexp="s/JMX_PORT=\"7199\"/JMX_PORT=\"$port\"/g"
sed -i -- $regexp $env
# Set the commitlog directory, and various other directories
printf " - Setting up directories\n"
regexp="s|/var/lib/cassandra/commitlog|$base_data_dir/commitlog|g"
sed -i -- "$regexp" $conf
# data_file_directories
regexp="s|/var/lib/cassandra/data|$base_data_dir/dse-data|g"
sed -i -- "$regexp" $conf
# saved_caches_directory
regexp="s|/var/lib/cassandra/saved_caches|$base_data_dir/saved_caches|g"
sed -i -- "$regexp" $conf
# C* logs
regexp="s|<jmxConfigurator />$|<jmxConfigurator /> <property name=\"cassandra.logdir\" value=\"node$1/logs/\" />|g"
sed -i -- "$regexp" $logs
# Bind the various services to their local IP address
# listen_address
printf " - Binding services\n"
regexp="s/listen_address: localhost/listen_address: 127.0.0.$1/g"
sed -i -- "$regexp" $conf
# rpc_address
regexp="s/rpc_address: localhost/rpc_address: 127.0.0.$1/g"
sed -i -- "$regexp" $conf
# seeds
local raw_seeds
for ip in $(seq $1 -1 1); do
raw_seeds="${raw_seeds},127.0.0.$ip,"
done
seeds=`echo $raw_seeds | sed -e s/,$//`
regexp="s/seeds: \"127.0.0.1\"/seeds: \"$seeds\"/g"
sed -i -- "$regexp" $conf
}
setup_resources()
{
printf " - Copying configs\n"
copy_config $1 $2 "cassandra"
copy_config $1 $2 "dse"
copy_config $1 $2 "hadoop"
copy_config $1 $2 "pig"
copy_config $1 $2 "hive"
copy_config $1 $2 "sqoop"
copy_config $1 $2 "mahout"
copy_config $1 $2 "spark"
copy_config $1 $2 "tomcat"
}
setup_node()
{
printf " + Setting up node %d...\n" $1
create_dirs $1
setup_resources $1 $DSE_HOME
tweak_cassandra_config $1
}
printf "* Setting up C* nodes...\n"
for i in $(seq 1 $C_NODES); do
setup_node $i
done
printf "Done.\n"
#!/bin/sh
# export JVM_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8881"
# export JVM_OPTS="-Djavax.net.debug=ssl:trustmanager:handshake:sslctx:session"
NODE="`pwd`/$1"
if [ -z $DSE_HOME ]; then
export DSE_HOME="`pwd`/`ls | grep dse | grep -v tar | grep -v sh`"
fi
if [ -z $DSE_ENV ]; then
export DSE_ENV=$DSE_HOME/bin/dse-env.sh
fi
export DSE_CONF=$NODE/resources/dse/conf
export CASSANDRA_HOME=$DSE_HOME/resources/cassandra
export CASSANDRA_CONF=$NODE/resources/cassandra/conf
DSE_BIN=$DSE_HOME/$2
export TOMCAT_HOME=$DSE_HOME/resources/tomcat
export TOMCAT_CONF_DIR=$NODE/resources/tomcat/conf
export HADOOP_HOME=$DSE_HOME/resources/hadoop
export HADOOP_CONF_DIR=$NODE/resources/hadoop/conf
export HIVE_HOME=$DSE_HOME/resources/hive
export HIVE_CONF_DIR=$NODE/resources/hive/conf
export SPARK_HOME=$DSE_HOME/resources/spark
export SPARK_CONF_DIR=$NODE/resources/spark/conf
# set up the DSE environment
. $DSE_ENV
shift; shift;
exec $DSE_BIN "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment