shell脚本启动redis集群

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

以下内容为shell脚本内容:

>/dev/null 2>&1  执行了这条命令之后,该条shell命令将不会输出任何信息到控制台,也不会有任何信息输出到文件中。

#!/bin/bash


start(){


REDIS_HOME=/usr/local
APP_NAME=redis
WAIT_TIME=5
echo "REDIS_HOME:"${REDIS_HOME}


for i in {7000..7005}
do
    REDIS_ID=$(ps -ef | grep ${APP_NAME} |grep ${i}| grep -v 'grep' | head -1 | awk '{print $2}')
    
    if [ -z "$REDIS_ID" ]; then
   
echo "[${APP_NAME}] will be start"
        cd $REDIS_HOME/$i
        redis-server redis.conf & >/dev/null 2>&1
    else
echo "[${APP_NAME}] has bean start"
    fi   
done


}
stop(){
REDIS_HOME=/usr/local
APP_NAME=redis
WAIT_TIME=5
echo "REDIS_HOME:"${REDIS_HOME}


for i in {7000..7005}
do
    REDIS_ID=$(ps -ef | grep ${APP_NAME} |grep ${i}| grep -v 'grep' | head -1 | awk '{print $2}')
    if [ -z "$REDIS_ID" ]; then
   
        echo "[$i] has bean stop"
    else
        echo "[$i] will be stop"
        kill -9 $REDIS_ID
        sleep ${WAIT_TIME}
    fi   
done


}



status(){
REDIS_HOME=/usr/local
APP_NAME=redis
WAIT_TIME=5
echo "REDIS_HOME:"${REDIS_HOME}


for i in {7000..7005}
do
    REDIS_ID=$(ps -ef | grep ${APP_NAME} |grep ${i}| grep -v 'grep' | head -1 | awk '{print $2}')
    if [ -z "$REDIS_ID" ]; then


        echo "[$i] has bean stop"
    else
        echo "[$i] has bean start"


    fi
done


}
case "$1" in
start)
echo "start redis"
start
;;
stop)
echo "stop redis"
stop
;;
status)
status
;;
restart)
echo "restart redis"
$0 stop
sleep 2
$0 start
;;
*)
printf 'Usage: %s {start|stop|status|restart}\n' "$prog"
exit 1
;;

esac







展开阅读全文

没有更多推荐了,返回首页