#!/bin/bash
redis_path="/usr/local/redis-cluster/"
cd ${redis_path}
ps aux | grep redis | grep cluster | grep -v grep | awk '{print $2}' | xargs kill -9
cluster_num=`ps aux | grep redis | grep cluster | wc -l`
if [ "${cluster_num}" -le 0 ]
then
echo -e "===== Success: Has killed all cluster progress."
else
echo -e "===== Fail: There still are ${cluster_num} is alive.\n"
exit 1
fi
rm -rf ${redis_path}redis*/dump.rdb
rm -rf ${redis_path}redis*/nodes*
data_num=`find ${redis_path} -type f | grep -E "dump.rdb|nodes*" | wc -l`
if [ "${data_num}" -le 0 ]
then
echo -e "===== Success: Has remove all dump.rdb and nodes configure file."
else
echo -e "===== Fail: There still are files is exist,Use command: \n\tfind ${redis_path} -type f | grep -E \"dump.rbd|nodes*\" \nto search, and then remove them manually.\n"
exit 1
fi
cd redis1/
./redis-server /etc/redis/7001.conf
cd ../redis2/
./redis-server /etc/redis/7002.conf
cd ../redis3/
./redis-server /etc/redis/7003.conf
cd ../redis4/
./redis-server /etc/redis/7004.conf
cd ../redis5/
./redis-server /etc/redis/7005.conf
cd ../redis6/
./redis-server /etc/redis/7006.conf
cd ..
./redis-trib.rb create --replicas 1 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 127.0.0.1:7006