Prerequisite: Set daemonize in redis.conf to Yes to ensure the daemon is turned on.
First step: Create a startup script named Redis under the/etc/init.d/directory
Writing the boot-up script (Vi/etc/init.d/redis)
The script (Redis) is as follows:
# chkconfig:2345 90 10
# Description:redis is a persistent key-value database
#PATH =/usr/local/bin:/sbin:/usr/bin:/bin
redisport=6379
Exec=/usr/local/bin/redis-server
Redis_cli=/usr/local/bin/redis-cli
Pidfile=/var/run/redis.pid
conf= "/etc/redis.conf"
Auth= "123456"
Case "$" in
Start
If [-F $PIDFILE]
Then
echo "$PIDFILE exists, process is already running or crashed"
Else
echo "Starting Redis server ..."
$EXEC $CONF
Fi
If ["$?" = "0"]
Then
echo "Redis is running ..."
Fi
;;
Stop
if [!-F $PIDFILE]
Then
echo "$PIDFILE does not exist, process was not running"
Else
pid=$ (Cat $PIDFILE)
echo "Stopping ..."
$REDIS _cli-p $REDISPORT-a $AUTH SHUTDOWN
While [-X ${pidfile}]
Do
echo "Waiting for Redis to shutdown ..."
Sleep 1
Done
echo "Redis stopped"
Fi
;;
Restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage:/etc/init.d/redis {start|stop|restart|force-reload}" >&2
Exit 1
Esac
Step Two: Set this file as an executable file
chmod 755 Redis
Chown Root:root Redis
Step three: Set up the boot execution Redis script
Chkconfig Redis on
Note: The first and second comments in the Redis script must be added, or you will be prompted when the settings start automatically
Service Redis does not support Chkconfig
The error message
Fourth step: Start the Redis service
Service Redis Start
Of course you can also stop and restart the service
#重启redis服务
Service Redis Restart
#关闭redis服务
Service Redis Stop
CentOS Setup opens the way to automatically start Redis