Redis starts automatically at boot

1. Create a new redis file

   vi /etc/init.d/redis

2. Modify the /tec/init.d/redis file, to modify the Redis installation directory and configuration file path

EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
CONF="/usr/local/redis/redis.conf"

 

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

REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.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 &
        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

 #!/bin/sh

   # chkconfig: 2345 10 90

   # description: Start and Stop redis

   This part of the header must be included, otherwise the chkconfig command will not be executed successfully

3. Startup settings

  3.1 Add Redis service

  chkconfig --add redis

   3.2 Device startup

  chkconfig redis on

    3.3 Start Redis

  service redis start

     3.4 Close Redis

  service redis stop

 4. View the process after restarting the system

   ps aux|grep redis

   

 

      

Guess you like

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