1. Download and install
wget http://redis.googlecode.com/files/redis-2.2.13.tar.gz
tar-zxf redis-2.2.13.tar.gz
cd redis-2.2.13
make
sudo make install
CP redis.conf/etc
When install, Redis's orders will be copied under/usr/local/bin.
2, create user and log directory
Before starting Redis for the first time, it is recommended that you create a separate user for Redis and create a new data and log folder
sudo useradd redis
sudo mkdir-p/var/lib/redis
sudo mkdir-p/var/log/redis
sudo chown redis.redis/var/lib/ Redis #db file here, to modify redis.conf
sudo chown redis.redis/var/log/redis
3, configuring the init script
In fact GitHub many foreigners write good startup script, but most of them are Ubuntu, for CentOS, also have a
https://gist.github.com/1335694
After modification, as follows:
########################### 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 crash Ed "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 isn't running" Else pid=$ (cat $PIDFILE) echo "Stopping ..." $REDIS _cli-p $REDISPORT SHUTDOWN while [-X ${pidfile}] do echo waiting for Redis to Shutdow N ... "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 it in backstage as Daemon run, then
Need to modify redis.conf, change daemonize No to daemonize Yes 4, set up 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