-
-
Save arsonus/3b592d833f08c59cde1992068be39c68 to your computer and use it in GitHub Desktop.
Redis Create Cluster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Settings | |
PORT=30000 | |
TIMEOUT=2000 | |
NODES=3 | |
REPLICAS=2 | |
# You may want to put the above config parameters into config.sh in order to | |
# override the defaults without modifying this script. | |
if [ -a config.sh ] | |
then | |
source "config.sh" | |
fi | |
# Computed vars | |
ENDPORT=$((PORT+NODES)) | |
NODE_IP=$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}') | |
if [ "$1" == "add-start" ] | |
then | |
PORT=$2 | |
echo "Starting $PORT" | |
../../src/redis-server --port $PORT --cluster-enabled yes --cluster-config-file nodes-${PORT}.conf --cluster-node-timeout $TIMEOUT --appendonly yes --appendfilename appendonly-${PORT}.aof --dbfilename dump-${PORT}.rdb --logfile ${PORT}.log --daemonize yes | |
exit 0 | |
fi | |
if [ "$1" == "add-create" ] | |
then | |
HOSTS="" | |
while [ $((PORT < ENDPORT)) != "0" ]; do | |
PORT=$((PORT+1)) | |
HOSTS="$HOSTS $NODE_IP:$PORT" | |
done | |
PORT=$2 | |
NODE_IP=$3 | |
HOSTS="$HOSTS $NODE_IP:$PORT" | |
PORT=$4 | |
NODE_IP=$5 | |
HOSTS="$HOSTS $NODE_IP:$PORT" | |
PORT=$6 | |
NODE_IP=$7 | |
HOSTS="$HOSTS $NODE_IP:$PORT" | |
../../src/redis-trib.rb create --replicas $REPLICAS $HOSTS | |
exit 0 | |
fi | |
if [ "$1" == "start" ] | |
then | |
while [ $((PORT < ENDPORT)) != "0" ]; do | |
PORT=$((PORT+1)) | |
echo "Starting $PORT" | |
../../src/redis-server --port $PORT --cluster-enabled yes --cluster-config-file nodes-${PORT}.conf --cluster-node-timeout $TIMEOUT --appendonly yes --appendfilename appendonly-${PORT}.aof --dbfilename dump-${PORT}.rdb --logfile ${PORT}.log --daemonize yes | |
done | |
exit 0 | |
fi | |
if [ "$1" == "create" ] | |
then | |
HOSTS="" | |
while [ $((PORT < ENDPORT)) != "0" ]; do | |
PORT=$((PORT+1)) | |
HOSTS="$HOSTS $NODE_IP:$PORT" | |
done | |
../../src/redis-trib.rb create --replicas $REPLICAS $HOSTS | |
exit 0 | |
fi | |
if [ "$1" == "stop" ] | |
then | |
while [ $((PORT < ENDPORT)) != "0" ]; do | |
PORT=$((PORT+1)) | |
echo "Stopping $PORT" | |
../../src/redis-cli -p $PORT shutdown nosave | |
done | |
exit 0 | |
fi | |
if [ "$1" == "watch" ] | |
then | |
PORT=$((PORT+1)) | |
while [ 1 ]; do | |
clear | |
date | |
../../src/redis-cli -p $PORT cluster nodes | head -30 | |
sleep 1 | |
done | |
exit 0 | |
fi | |
if [ "$1" == "tail" ] | |
then | |
INSTANCE=$2 | |
PORT=$((PORT+INSTANCE)) | |
tail -f ${PORT}.log | |
exit 0 | |
fi | |
if [ "$1" == "call" ] | |
then | |
while [ $((PORT < ENDPORT)) != "0" ]; do | |
PORT=$((PORT+1)) | |
../../src/redis-cli -p $PORT $2 $3 $4 $5 $6 $7 $8 $9 | |
done | |
exit 0 | |
fi | |
if [ "$1" == "clean" ] | |
then | |
rm -rf *.log | |
rm -rf appendonly*.aof | |
rm -rf dump*.rdb | |
rm -rf nodes*.conf | |
exit 0 | |
fi | |
echo "Usage: $0 [start|create|stop|watch|tail|clean]" | |
echo "start -- Launch Redis Cluster instances." | |
echo "create -- Create a cluster using redis-trib create." | |
echo "stop -- Stop Redis Cluster instances." | |
echo "watch -- Show CLUSTER NODES output (first 30 lines) of first node." | |
echo "tail <id> -- Run tail -f of instance at base port + ID." | |
echo "clean -- Remove all instances data, logs, configs." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment