一、下载,解压和编译Redis
1
2
3
4
5
|
# cd /tmp
# wget http://download.redis.io/releases/redis-3.0.1.tar.gz
# tar xzf redis-3.0.1.tar.gz
# cd redis-3.0.1
# make
|
二、下载、安装tclsh
测试编译:
1
|
# make test
|
得到如下错误信息:
1
2
3
4
5
6
|
cd src && make test
make[1]: Entering directory `/tmp/redis-3.0.1/src'
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] Error 1
make[1]: Leaving directory `/tmp/redis-3.0.1/src'
make: *** [test] Error 2
|
Redis在make test有使用到tclsh对Redis进行测试,所有需要将tclsh安装好。
tclsh下载可以直接从官网http://www.tcl.tk/software/tcltk/download.html下载其最新版
1
2
3
4
5
6
|
# cd /tmp
# wget http://prdownloads.sourceforge.net/tcl/tcl8.6.4-src.tar.gz
# tar xzvf tcl8.6.4-src.tar.gz
# cd tcl8.6.4/unix #windows进入tcl8.6.4/win
# ./configure --prefix=/usr/local/tcl8.6.4 --enable-64bit #enable-64bit对64系统生效
# make && make install
|
安装完成之后需要将tclsh添加到PATH中,并使其生效
1
|
# vim /etc/profile
|
PATH=/usr/local/tcl8.6.4/bin:$PATH
export PATH
1
|
# source /etc/profile
|
这样tclsh就已经安装完成了。
三、再次测试编译
1
2
|
# cd /tmp/redis-3.0.1
# make test
|
将会收到信息:
All tests passed without errors!
四、简单试用(生产环境略过)
在src目录下,编译后的二进制文件可用。运行Redis服务端:
1
|
# src/redis-server
|
你可以用内置的客户端与Redis交互:
1
|
# src/redis-cli
|
redis> set foo bar
OK
redis> get foo
"bar"
五、安装redis到指定目录
也可以将redis安装到指定的/usr/local/redis目录下:
1
|
# make PREFIX=/usr/local/redis install
|
六、配置redis
为redis配置PATH:
1
|
#vi /etc/profile #添加下行内容
|
PATH=$PATH:/usr/local/redis/bin
export PATH
1
|
#source /etc/profile
|
1
|
#cp redis.conf /etc/
|
1
|
#vi /etc/sysctl.conf #添加vm.overcommit_memory=1,否则出现如下警告
|
1
2
|
# WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then
reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
|
#vi /etc/redis.conf #对应行修改为下面内容
daemonize yes
logfile /var/log/redis.log
七、编写服务管理脚本
1
|
#vi /etc/init.d/redis
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#!/bin/sh
#chkconfig: 345 86 14
#description: Startup and shutdown script for Redis
PROGDIR=
/usr/local/redis
#安装路径
PROGNAME=redis-server
DAEMON=$PROGDIR/$PROGNAME
CONFIG=
/etc/redis
.conf
PIDFILE=
/var/run/redis
.pid
DESC=
"redis daemon"
SCRIPTNAME=
/etc/rc
.d
/init
.d
/redis
start()
{
if
test
-x $DAEMON
then
echo
-e
"Starting $DESC: $PROGNAME"
if
$DAEMON $CONFIG
then
echo
-e
"OK"
else
echo
-e
"failed"
fi
else
echo
-e
"Couldn't find Redis Server ($DAEMON)"
fi
}
stop()
{
if
test
-e $PIDFILE
then
echo
-e
"Stopping $DESC: $PROGNAME"
if
kill
`
cat
$PIDFILE`
then
echo
-e
"OK"
else
echo
-e
"failed"
fi
else
echo
-e
"No Redis Server ($DAEMON) running"
fi
}
restart()
{
echo
-e
"Restarting $DESC: $PROGNAME"
stop
start
}
list()
{
ps
aux |
grep
$PROGNAME
}
case
$1
in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
list)
list
;;
*)
echo
"Usage: $SCRIPTNAME {start|stop|restart|list}"
>&2
exit
1
;;
esac
exit
0
|
1
|
#chmod +x /etc/init.d/redis
|
八、设置开机启动
1
2
3
|
#chkconfig --add redis
#chkconfig --level 35 redis on
#chkconfig --list redis
|
九、启动、关闭服务
前台以配置文件启动:
1
|
# redis-server /etc/redis.conf #默认情况下redis前端运行,并把日志输出到屏幕上
|
生产环境直接以服务启动:
1
2
|
# service redis start
# netstat -tnlp |grep 6379
|
以命令关闭服务:
1
|
# redis-cli shutdown
|
生产环境直接以服务关闭:
1
|
# service redis stop
|
十、测试
# redis-cli
127.0.0.1:6379> info
# Server
redis_version:3.0.1
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:6d627ecdac18555f
redis_mode:standalone
os:Linux 2.6.32-358.el6.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.4.7
process_id:6173
run_id:aedc790ab2d0eb75f3d5afe10c6af937d16955b0
tcp_port:6379
uptime_in_seconds:706
uptime_in_days:0
hz:10
lru_clock:6829896
config_file:/etc/redis.conf
...
...
参见:http://redis.io/download
本文转自UltraSQL51CTO博客,原文链接: http://blog.51cto.com/ultrasql/1656480,如需转载请自行联系原作者