redis-cluster 启动shell脚本

  1. 下面是自己写的一个redis集群启动脚本,就是先杀掉原来的进程,然后开起来,主要是方便自己在虚拟机上调试。正常生产环境肯定不会像自己的虚拟机那样每天早上开晚上关,一般应该都是开着的,都会使用哨兵模式或者类似策略来保障平时的正常工作运行。
  2. 为了方便开机启动,顺便注释掉redis-trib.rb里面的以下几行,避免开机启动时停留在等待获取终端输入那里:
#if !(STDIN.gets.chomp.downcase == "yes") //818行起
#    xputs "*** Aborting..."
#    exit 1
#end

#!/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


你可能感兴趣的:(php)