1. 程式人生 > >redis-cluster 啟動shell指令碼

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