Configuring the Init Script
For CentOS, there is a copy of the https://gist.github.com/1335694
After modification, the following:
- ##########################
- 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"
- 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 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
- ##############################
Save the above code as Redis and put it under/etc/init.d/
chmod +x/etc/init.d/redis
Actually make service start, also call Redis-server, if want to let it run as daemon in the background, then
Need to modify redis.conf, change daemonize No to daemonize Yes
4, set the boot service
sudo chkconfig redis on
5, start, stop Redis
Service Redis start #或者/etc/init.d/redis start
Service Redis stop #或者/etc/init.d/redis stop
6, Test Redis
- Redis-cli
- Redis 127.0.0.1:6379> set foo 123
- Ok
- Redis 127.0.0.1:6379> get foo
- "123"
- Redis 127.0.0.1:6379> Exit
CentOS Redis Auto Restart