CenterOS中安装Redis及开机启动设置

进入这个目录:
cd /etc/init.d/
在此目录下创建redis脚本
vim redis
把下边的内容拷贝到redis文件中,然后保存

###########################
PATH=/usr/local/bin
REDISPORT=6379
#注意下边是你的路径,可能需要修改
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
#Redis密码
PASSWORD=xxxx
PIDFILE=/var/run/redis.pid
#注意下边是你的路径,可能需要修改
CONF="/usr/local/bin/redis.conf"

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        if [ "$?"="0" ] 
        then
              echo "Redis is running..."
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $REDIS_CLI -p $REDISPORT -a $PASSWORD SHUTDOWN
                while [ -x ${PIDFILE} ]
               do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
   restart|force-reload)
        ${0} stop
        ${0} start
        ;;
  *)
    echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
        exit 1
esac
##############################

设置脚本权限
chmod +x /etc/init.d/redis
设置开机启动
sudo chkconfig redis on
启动服务

service redis start

参考文章:
http://www.cnblogs.com/piscesLoveCc/p/5757477.html

posted @ 2017-05-15 11:31  陆陆通通  阅读(130)  评论(0编辑  收藏  举报