1.安装tcl支持
yum install tcl
2、安装redis2.8.9
$ wget http://download.redis.io/releases/redis-2.8.9.tar.gz
$ tar xzf redis-2.8.9.tar.gz
$ cd redis-2.8.9
$ make
$ make test
$ make install
其中make test用来进行测试。
3、配置redis.conf
vi /usr/loacl/redis-2.8.9/redis.conf
只修改如下两项:
daemonize yes #redis将以守护进程的方式运行,默认为no会暂用你的终端
timeout 300 #当 客户端闲置多长时间后关闭连接,如果指定为0,表示关闭该功能
cd /etc
mkdir redis
cp /usr/lcoal/redis-2.8.9/redis.conf /etc/redis/
4、设置redis服务自启动
vim /etc/init.d/redis
redis内容如下:
#!/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/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
BIN="/usr/local/redis-2.8.9/src"
CONFIG="/usr/local/redis-2.8.9/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
启动或者关闭服务:
service redis start
service redis stop
5、使用redis
cd /usr/local/redis-2.8.9/src
./redis-cli
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"
参考:
http://redis.io/download
http://www.jb51.net/article/62507.htm
http://www.cnblogs.com/xsi640/p/3756130.html