1、设置redis.conf中daemonize为yes,确保守护进程开启。
2、编写开机自启动脚本
vi /etc/init.d/redis
脚本内容如下:
@H_403_21@
- #!/bin/bash
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
# description: Start and Stop redis - PATH=/usr/local/bin:/sbin:/usr/bin:/bin
- #redis端口号
- REDISPORT=6379
- #redis-server所在目录的绝对路径
- EXEC=/usr/apk/redis-2.8.17/redis-server
- #redis-cli所在目录的绝对路径
- REDIS_CLI=/usr/apk/redis-2.8.17/redis-cli
- PIDFILE=/var/run/redis.pid
- #redis.conf所在目录的绝对路径
- CONF="/usr/apk/redis-2.8.17/redis.conf"
- AUTH="Nginx"
- case"$1"in
- start)
- if[-f$PIDFILE]
- then
- echo"$PIDFILEexists,processisalreadyrunningorcrashed."
- else
- echo"StartingRedisserver..."
- $EXEC$CONF
- fi
- if["$?"="0"]
- then
- echo"Redisisrunning..."
- ;;
- stop)
- if[!-f$PIDFILE]
- echo"$PIDFILEexists,processisnotrunning."
- else
- PID=$(cat$PIDFILE)
- echo"Stopping..."
- $REDIS_CLI-p$REDISPORTSHUTDOWN
- sleep2
- while[-x$PIDFILE]
- do
- echo"WaitingforRedistoshutdown..."
- sleep1
- done
- echo"Redisstopped"
- fi
- ;;
- restart|force-reload)
- ${0}stop
- ${0}start
- *)
- echo"Usage:/etc/init.d/redis{start|stop|restart|force-reload}">&2
- exit1
- esac