redis-cluster 启动shell脚本

redis-cluster 启动shell脚本

 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/caopingtao/article/details/79023928

 

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

 

编辑:vi redis.sh

#!/bin/sh
#chkconfig: 2345 80 90
#description:开机自动启动的脚本程序

#redis_path="/usr/local/redis/"
#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

./usr/local/redis/src/redis-server /usr/local/redis/redis-cluster/nodes-26379/redis.conf
./usr/local/redis/src/redis-server /usr/local/redis/redis-cluster/nodes-26380/redis.conf
./usr/local/redis/src/redis-server /usr/local/redis/redis-cluster/nodes-26381/redis.conf
./usr/local/redis/src/redis-server /usr/local/redis/redis-cluster/nodes-26382/redis.conf
./usr/local/redis/src/redis-server /usr/local/redis/redis-cluster/nodes-26383/redis.conf
./usr/local/redis/src/redis-server /usr/local/redis/redis-cluster/nodes-26384/redis.conf

./usr/local/redis/src/redis-trib.rb create --replicas 1 127.0.0.1:26379 127.0.0.1:26380  127.0.0.1:26381 127.0.0.1:26382  127.0.0.1:26383  127.0.0.1:26384

 

二、chkconfig

1. 编写脚本redis.sh(这里以开机启动redis服务为例),脚本内容如下:

#!/bin/sh
#chkconfig: 2345 80 90
#description:开机自动启动的脚本程序

脚本第一行 “#!/bin/sh” 告诉系统使用的shell; 
脚本第二行 “#chkconfig: 2345 80 90” 表示在2/3/4/5运行级别启动,启动序号(S80),关闭序号(K90); 
脚本第三行 表示的是服务的描述信息

注意: 第二行和第三行必写,负责会出现如“服务 redis.sh 不支持 chkconfig”这样的错误。

2. 将写好的redis.sh脚本移动到/etc/rc.d/init.d/目录下

3. 给脚本赋可执行权限

cd /etc/rc.d/init.d/
chmod +x redis.sh

4. 添加脚本到开机自动启动项目中

chkconfig --add redis.sh
chkconfig redis.sh on

 

你可能感兴趣的:(redis-cluster 启动shell脚本)