【源码获取】
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
|
[root@Betty WGET_DIR]
# wget http://download.redis.io/releases/redis-2.8.3.tar.gz
--2013-12-16 16:28:50-- http:
//download
.redis.io
/releases/redis-2
.8.3.
tar
.gz
正在解析主机 download.redis.io... 109.74.203.151
Connecting to download.redis.io|109.74.203.151|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:http:
//211
.167.105.115:83
/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/download
.redis.io
/releases/redis-2
.8.3.
tar
.gz [跟随至新的 URL]
--2013-12-16 16:28:51-- http:
//211
.167.105.115:83
/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/download
.redis.io
/releases/redis-2
.8.3.
tar
.gz
Connecting to 211.167.105.115:83... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1046106 (1022K) [application
/x-gzip
]
Saving to: `redis-2.8.3.
tar
.gz'
100%[===================================================================================================================>] 1,046,106 1.11M
/s
in
0.9s
2013-12-16 16:28:52 (1.11 MB
/s
) - `redis-2.8.3.
tar
.gz' saved [1046106
/1046106
]
[root@Betty WGET_DIR]
#
[root@Betty WGET_DIR]
# tar zxvf redis-2.8.3.tar.gz
...
[root@Betty WGET_DIR]
# cd redis-2.8.3/
[root@Betty redis-2.8.3]
# ll
总计 108
-rw-rw-r-- 1 root root 8627 12-11 22:31 00-RELEASENOTES
-rw-rw-r-- 1 root root 52 12-11 22:31 BUGS
-rw-rw-r-- 1 root root 1439 12-11 22:31 CONTRIBUTING
-rw-rw-r-- 1 root root 1487 12-11 22:31 COPYING
drwxrwxr-x 6 root root 4096 12-11 22:31 deps
-rw-rw-r-- 1 root root 11 12-11 22:31 INSTALL
-rw-rw-r-- 1 root root 151 12-11 22:31 Makefile
-rw-rw-r-- 1 root root 4223 12-11 22:31 MANIFESTO
-rw-rw-r-- 1 root root 4401 12-11 22:31 README
-rw-rw-r-- 1 root root 29593 12-11 22:31 redis.conf
-rwxrwxr-x 1 root root 271 12-11 22:31 runtest
-rw-rw-r-- 1 root root 5661 12-11 22:31 sentinel.conf
drwxrwxr-x 2 root root 4096 12-11 22:31 src
drwxrwxr-x 8 root root 4096 12-11 22:31 tests
drwxrwxr-x 2 root root 4096 12-11 22:31 utils
[root@Betty redis-2.8.3]
#
|
【README】
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
Building Redis
--------------
Redis can be compiled and used on Linux, OSX, OpenBSD, NetBSD, FreeBSD.
We support big endian and little endian architectures.
支持 Unix-like 平台;支持大端和小端架构
It is as simple as:
直接
make
%
make
You can run a 32 bit Redis binary using:
编译 32-bit 版本的 Redis
%
make
32bit
After building Redis is a good idea to
test
it, using:
回归测试
%
make
test
Fixing problems building 32 bit binaries
给出了 32-bit 编译时可能遇到的问题和解决办法
---------
略
Allocator
---------
Selecting a non-default memory allocator when building Redis is
done
by setting
the `MALLOC` environment variable. Redis is compiled and linked against libc
malloc by default, with the exception of jemalloc being the default on Linux
systems. This default was picked because jemalloc has proven to have fewer
fragmentation problems than libc malloc.
允许通过设置环境变量 MALLOC 定制使用的内存分配机制。默认使用 libc 中提供的 malloc 相关函数,除非当前
linux 系统将 jemalloc 作为默然内存分配机制。
这种策略是因为,jemalloc 已经被证明与 libc 的 malloc 内存配置机制相比可以产生更少的内存碎片。
To force compiling against libc malloc, use:
强制使用 libc 中的 malloc 机制,可以执行
%
make
MALLOC=libc
To compile against jemalloc on Mac OS X systems, use:
强制使用 jemalloc 机制,可以执行
%
make
MALLOC=jemalloc
Verbose build
如何产生更多的输出
-------------
Redis will build with a user friendly colorized output by default.
If you want to see a
more
verbose output use the following:
%
make
V=1
Running Redis
运行 Redis
-------------
To run Redis with the default configuration just
type
:
使用默认配置信息运行
%
cd
src
% .
/redis-server
If you want to provide your redis.conf, you have to run it using an additional
parameter (the path of the configuration
file
):
如果打算使用 redis.conf 配置文件,则如下执行
%
cd
src
% .
/redis-server
/path/to/redis
.conf
It is possible to alter the Redis configuration passing parameters directly
as options using the
command
line. Examples:
可以通过在直接在命令行上执行选项来覆盖配置文件中的相应配置
% .
/redis-server
--port 9999 --slaveof 127.0.0.1 6379
% .
/redis-server
/etc/redis/6379
.conf --loglevel debug
All the options
in
redis.conf are also supported as options using the
command
line, with exactly the same name.
所有存在于配置文件 redis.conf 中的选项同样可以在命令行上进行执行。
Playing with Redis
如何“玩转”Redis
------------------
You can use redis-cli to play with Redis. Start a redis-server instance,
then
in
another terminal try the following:
可以使用 redis-cli 命令行客户端进行测试。
%
cd
src
% .
/redis-cli
redis>
ping
PONG
redis>
set
foo bar
OK
redis> get foo
"bar"
redis> incr mycounter
(integer) 1
redis> incr mycounter
(integer) 2
redis>
Installing Redis
如何安装 Redis
-----------------
In order to
install
Redis binaries into
/usr/local/bin
just use:
安装到默认路径
%
make
install
You can use
"make PREFIX=/some/other/directory install"
if
you wish to use a
different destination.
安装到自定义路径
Make
install
will just
install
binaries
in
your system, but will not configure
init scripts and configuration files
in
the appropriate place. This is not
needed
if
you want just to play a bit with Redis, but
if
you are installing
it the proper way
for
a production system, we have a script doing this
for
Ubuntu and Debian systems:
make
install
命令仅仅安装二进制文件到你的系统目录中,不会进行 init 脚本的配置,也不会在
某个适当的位置生成配置文件。如果你需要一个用于生产环境的系统配置,可以执行如下命令
%
cd
utils
% .
/install_server
The script will ask you a few questions and will setup everything you need
to run Redis properly as a background daemon that will start again on
system reboots.
这个脚本会对通过向你提问的方式,引导你对系统进行配置,从而实现相应的功能。
You'll be able to stop and start Redis using the script named
/etc/init
.d
/redis_
<portnumber>,
for
instance
/etc/init
.d
/redis_6379
.
结束上面的操作后,你将可以通过
/etc/init
.d
/redis_
<portnumber> 脚本控制 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
|
[root@Betty redis-2.8.3]
# cd utils/
[root@Betty utils]
# ll
总计 44
-rw-rw-r-- 1 root root 593 12-11 22:31 build-static-symbols.tcl
-rwxrwxr-x 1 root root 2087 12-11 22:31 generate-
command
-help.rb
-rwxrwxr-x 1 root root 6662 12-11 22:31 install_server.sh
-rwxrwxr-x 1 root root 298 12-11 22:31 mkrelease.sh
-rw-rw-r-- 1 root root 1277 12-11 22:31 redis-copy.rb
-rwxrwxr-x 1 root root 1098 12-11 22:31 redis_init_script
-rwxrwxr-x 1 root root 821 12-11 22:31 redis_init_script.tpl
-rw-rw-r-- 1 root root 1762 12-11 22:31 redis-sha1.rb
-rwxrwxr-x 1 root root 3787 12-11 22:31 speed-regression.tcl
-rwxrwxr-x 1 root root 428 12-11 22:31 whatisdoing.sh
[root@Betty utils]
# ./install_server.sh
Welcome to the redis service installer
This script will help you easily
set
up a running redis server
Please
select
the redis port
for
this instance: [6379]
Selecting default: 6379
Please
select
the redis config
file
name [
/etc/redis/6379
.conf]
Selected default -
/etc/redis/6379
.conf
Please
select
the redis log
file
name [
/var/log/redis_6379
.log]
Selected default -
/var/log/redis_6379
.log
Please
select
the data directory
for
this instance [
/var/lib/redis/6379
]
Selected default -
/var/lib/redis/6379
Please
select
the redis executable path [
/usr/local/bin/redis-server
]
s
#^port [0-9]{4}$#port 6379#;s#^logfile .+$#logfile /var/log/redis_6379.log#;s#^dir .+$#dir /var/lib/redis/6379#;s#^pidfile .+$#pidfile /var/run/redis_6379.pid#;s#^daemonize no$#daemonize yes#;
Copied
/tmp/6379
.conf =>
/etc/init
.d
/redis_6379
Installing service...
.
/install_server
.sh: line 178: update-rc.d:
command
not found
exists, process is already running or crashed
Installation successful!
[root@Betty utils]
#
|
【redis_6379 脚本】
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
|
[root@Betty utils]
# vi /etc/init.d/redis_6379
#/bin/sh\n #Configurations injected by install_server below....\n\n EXEC=/usr/local/bin/redis-server\n CLIEXEC=/usr/local/bin/redis-cli\n PIDFILE=/var/run/re
dis_6379.pid\n CONF=
"/etc/redis/6379.conf"
\n\n REDISPORT=
"6379"
\n\n
###############\n\n
case
"$1"
in
start)
if
[ -f $PIDFILE ]
then
echo
"$PIDFILE exists, process is already running or crashed"
else
echo
"Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if
[ ! -f $PIDFILE ]
then
echo
"$PIDFILE does not exist, process is not running"
else
PID=$(
cat
$PIDFILE)
echo
"Stopping ..."
$CLIEXEC -p $REDISPORT
shutdown
while
[ -x
/proc/
${PID} ]
do
echo
"Waiting for Redis to shutdown ..."
sleep
1
done
echo
"Redis stopped"
fi
;;
*)
echo
"Please use start or stop as first argument"
;;
esac
|
上面这个脚本正常情况下是无法正常使用的,需要将最上面的内容进行修改,如下
1
2
3
4
5
6
7
8
9
|
#!/bin/sh
# Configurations injected by install_server below....
EXEC=
/usr/local/bin/redis-server
CLIEXEC=
/usr/local/bin/redis-cli
PIDFILE=
/var/run/redis_6379
.pid
CONF=
"/etc/redis/6379.conf"
REDISPORT=
"6379"
################
...
|
改好后就可以正常使用了
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@Betty ~]
# /etc/init.d/redis_6379 start
Starting Redis server...
[root@Betty ~]
#
[root@Betty ~]
# ps aux|grep redis
root 11495 0.0 0.0 95296 1912 ? Ssl 13:33 0:00
/usr/local/bin/redis-server
*:6379
root 11503 0.0 0.0 61180 752 pts
/1
S+ 13:34 0:00
grep
redis
[root@Betty ~]
#
[root@Betty ~]
# /etc/init.d/redis_6379 stop
Stopping ...
Redis stopped
[root@Betty ~]
# ps aux|grep redis
root 11508 0.0 0.0 61180 752 pts
/1
S+ 13:34 0:00
grep
redis
[root@Betty ~]
#
|