Redis configures self-starting on Linux

Method 2

1. Write a script

[root@localhost ~]# vi /etc/init.d/redis

Copy the following code into the script (note that you need to modify the installation path of redis, take the path /usr/redis/redis-3.2.4 as an example) (this code is the code of the redis root directory /utils/redis_init_script to start the script)

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

REDISPORT=6379
EXEC=/usr/redis/redis-3.2.4/src/redis-server
CLIEXEC=/usr/redis/redis-3.2.4/src/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF ="/usr/redis/redis-3.2.4/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 &
        be
        ;;
    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"
        be
        ;;
    restart)
        "$0" stop
        sleep 3
        "$0" start
        ;;
    *)
        echo "Please use start or stop or restart as first argument"
        ;;
esac
copy code

3. Save and exit, set permissions

[root@localhost ~]# chmod 777 /etc/init.d/redis

4. Set up automatic
 
[root@localhost ~]#

4. Start redis

[root@localhost ~]# service redis start

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326343275&siteId=291194637