Skip to content

Instantly share code, notes, and snippets.

@pkazi
Created October 16, 2018 06:50
Show Gist options
  • Save pkazi/8f8c849e2f499b1d7b4b988db9afd1b0 to your computer and use it in GitHub Desktop.
Save pkazi/8f8c849e2f499b1d7b4b988db9afd1b0 to your computer and use it in GitHub Desktop.
Setup Local redis cluster with 6 nodes (3 master and 3 slaves)
#!/bin/bash
CLUSTER_HOME=$HOME/redis-cluster
echo "Cluster Home is set to : $CLUSTER_HOME"
rm -rf $CLUSTER_HOME
mkdir -p $CLUSTER_HOME
cd $CLUSTER_HOME
wget http://download.redis.io/redis-stable/src/redis-trib.rb
chmod +x redis-trib.rb
mkdir 7000 7001 7002 7003 7004 7005
pgrep redis-server | xargs kill -9
cat <<EOF > redis.conf.template
port PORT
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
EOF
ls -la
for i in `ls -d1 700*`; do
cd $i
echo "Starting redis node with port - $i";
cp ../redis.conf.template redis.conf;
sed -i "s/PORT/$i/" redis.conf;
nohup redis-server ./redis.conf &
cd ..
done
./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment