Linux 下 redis 开机启动配置

2018-06-25 02:54:30   服务器

  redis  

复制启动脚本到/etc/init.d

cp /usr/local/redis/utils/redis_init_script /etc/init.d/redis

修改 /etc/init.d/redis

#!/bin/sh
# chkconfig: 2345 10 90 
# description: Start and Stop redis

#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
EXEC=/usr/local/redis/src/redis-server #redis-server 路径
CLIEXEC=/usr/local/redis/src/redis-cli #redis-cli 路径

PIDFILE=/var/run/redis.pid
CONF="/usr/local/redis/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
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

修改redis.conf

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

开机启动设置

chkconfig --add redis #添加服务器
chkconfig redis on #设置开机启动