The redis management script is based on the Ubuntu release. For Ubuntu users, you can refer to this Article. Ubuntu installation and startup of redis are not available on centos Linux. The following script can be used for centos:
Before using this script for management, you must configure the following kernel parameters. Otherwise, an error will be reported when the redis script restarts or stops redis, data cannot be automatically synchronized to the disk before the service is stopped:
# Vi/etc/sysctl. conf
VM. overcommit_memory = 1
Then the application takes effect:
# Sysctl-P
Create a redis STARTUP script:
# Vim/etc/init. d/redis
#! /Bin/bash
#
# Init file for redis
#
# Chkconfig:-80 12
# Description: redis daemon
#
# Processname: redis
# Config:/etc/redis. conf
# Pidfile:/var/run/redis. PID
Source/etc/init. d/functions
# Bin = "/usr/local/bin"
Bin = "/usr/local/bin"
Config = "/etc/redis. conf"
Pidfile = "/var/run/redis. PID"
### Read Configuration
[-R "$ sysconfig"] & source "$ sysconfig"
Retval = 0
Prog = "redis-server"
Desc = "redis server"
Start (){
If [-e $ pidfile]; then
Echo "$ DESC already running ...."
Exit 1
Fi
Echo-N $ "Starting $ Desc :"
Daemon $ bin/$ prog $ config
Retval =$?
Echo
[$ Retval-EQ 0] & Touch/var/lock/subsys/$ prog
Return $ retval
}
Stop (){
Echo-N $ "Stop $ Desc :"
Killproc $ prog
Retval =$?
Echo
[$ Retval-EQ 0] & Rm-F/var/lock/subsys/$ prog $ pidfile
Return $ retval
}
Restart (){
Stop
Start
}
Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Restart)
Restart
;;
Condrestart)
[-E/var/lock/subsys/$ prog] & restart
Retval =$?
;;
Status)
Status $ prog
Retval =$?
;;
*)
Echo $ "Usage: $0 {START | stop | restart | condrestart | status }"
Retval = 1
Esac
Exit $ retval
Then add the service and start it automatically:
# Chmod 755/etc/init. d/redis
# Chkconfig -- add redis
# Chkconfig -- level 345 redis on
# Chkconfig -- list redis