Linux Redis starts automatically, Redis starts at boot, and Linux Redis is set to start at boot

Linux Redis starts automatically, Redis starts at boot, and Linux Redis is set to start at boot

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

©Copyright Sweet Potato Yao July 21, 2017

http://fanshuyao.iteye.com/

 

Linux Redis installation, see how to install Redis in Linux:

http://fanshuyao.iteye.com/blog/2386231

 

1. Create and write a boot-up self-starting script (redis-auto is a new file)

vi /etc/init.d/redis-auto

 

2. Add the following content to the file redis-auto: (Note the specific installation path of Redis, yours may be different)

2017-07-26 Fixed the problem of inconsistent parameter names.

#!/bin/sh
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
REDISPATH=/home/java/run/redis-3.2.9/bin
EXEC=${REDISPATH}/redis-server
CLIEXEC=${REDISPATH}/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="${REDISPATH}/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
    ;;
  *)
    echo "Please use start or stop as first argument"
    ;;
esac

 

3. Save and exit

:wq

Fourth, set the permissions of the file redis-auto so that Linux can execute

cd /etc/init.d/

chmod 755 redis-auto

 

5. Start the Redis service test, here is the startup script set in the second step

/etc/init.d/redis-auto start

 If you see the small box that Redis starts, it means success.

But you can further open the redis-cli client for testing

 

Sixth, set the boot to start automatically, namely:

chkconfig redis-auto on

 

7. After testing, when the Linux system is restarted, the Redis data will be automatically lost. For the solution, see:

 

Linux Redis restart data loss solution, Redis data loss solution after Linux restart

http://fanshuyao.iteye.com/blog/2386429

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

©Copyright Sweet Potato Yao July 21, 2017

http://fanshuyao.iteye.com/

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327100542&siteId=291194637