1. Download Redis
http://download.redis.io/releases/redis-4.0.10.tar.gz
2. Unzip package
(e.g. /home/redis)
tar xzvf redis-4.0.10.tar.gz
3. Make file
cd redis-4.0.10
make
cd src
make all
make install
4. Deploy Redis
mkdir -p/usr/local/redis/bin
mkdir -p/usr/local/redis/ect
mv /home/redis-4.0.10/redis.conf /usr/local/redis/etc
cd /home/redis-4.0.10/src
mv mkreleasdhdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server /usr/local/redis/bin
Right now, you should be able to execute ./redis-server under the path "/usr/local/redis/bin"
5. Config Redis
5.1 Background running
cd /usr/local/redis/etc/
Vi redis.conf
Set set "daemonize" to yes.
You can run redis in background via command "redis-server /usr/local/redis/etc/redis.conf"; and you may connect to redis with cli tool by invoke "redis-cli" command.
5.2 Register Service
vim /etc/init.d/redis
Copy following script into file
#!/bin/sh
#
# redis Startup script for Redis Server
#
# chkconfig: - 80 12
# description: Redis is an open source, advanced key-value store.
#
# processname: redis-server
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
BIN="/usr/local/redis/bin"
CONFIG="/usr/local/redis/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
chmod +x /etc/init.d/redis
chkconfig --add redis
Now, you should be able to start/stop redis by the commands:
service redis start
service redis stop
5.3 Config PATH env
#vi /etc/profile
export PATH="$PATH:/usr/local/redis/bin"
#. /etc/profile
5.4 Config kernel parameter
#vim /etc/sysctl.conf
vm.overcommit_memory = 1
#sysctl -p
This configuration is for making sure cache data could be persisted to local disk before redis shutdown.
Copy from: