Skip to content

Instantly share code, notes, and snippets.

@dgnorton
Created January 19, 2016 20:25
Show Gist options
  • Save dgnorton/a85f1209065388f9a134 to your computer and use it in GitHub Desktop.
Save dgnorton/a85f1209065388f9a134 to your computer and use it in GitHub Desktop.
#!/bin/sh
# base directory where cluster configs will be created
BASEDIR="/tmp/influxdb-cluster"
# delete the base dir if it exists
if [ -d "$BASEDIR" ]; then
rm -rf $BASEDIR
fi
# create the base dir for cluster configs
mkdir -p $BASEDIR
# copy influxd and influx executables to cluster base dir
# note: you need to set the IFLX environment variable to the root
# of the influxdb source tree or modify these two lines.
cp $IFLX/cmd/influxd/influxd $BASEDIR
cp $IFLX/cmd/influx/influx $BASEDIR
# change to the base dir
cd $BASEDIR
# addNode takes a node number and creates a sub directory for the node's
# config and data files
addNode () {
# node's base directory
NODEDIR="$BASEDIR/n$1"
# node's config file
NODECFG="$NODEDIR/influxdb.conf"
# make the node's base directory
mkdir -p $NODEDIR
# tell influxd to generate a default config for the node
./influxd config > $NODECFG
# replace the port numbers in the config based on the node number passed in
sed -i.bak s/:80/:8$1/g $NODECFG
# replace the default InfluxDB data dir with this node's dir
sed -i.bak s@$HOME@$NODEDIR@g $NODECFG
}
# call addNode to generate node configurations
addNode "1"
addNode "2"
addNode "3"
# bring up the nodes and join them as a cluster
./influxd -config n1/influxdb.conf &
sleep 5
./influxd -config n2/influxdb.conf -join ":8191" &
./influxd -config n3/influxdb.conf -join ":8191" &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment