文章出处http://www.ywnds.com/?p=6957&viewuser=39
安装Redis
下载Redis:wget https://github.com/antirez/redis/archive/3.2.0.tar.gz
在安装Redis之前,需要安装Redis的依赖程序tcl,如果不安装tcl在Redis执行make test的时候就会报错的哦。
1
|
$
yum
install
-
y
tcl
|
1
2
3
4
5
6
7
8
9
|
$
tar
xvf
3.2.0.tar.gz
-
C
/
usr
/
local
$
cd
/
usr
/
local
/
$
mv
redis
-
3.2.0
redis
$
cd
redis
$
make
$
make
test
$
make
install
$
mkdir
/
etc
/
redis
$
cp
redis
/
redis
.conf
/
etc
/
|
以redis用户启动redis
1
2
|
$
useradd
-
s
/
bin
/
false
-
M
redis
$
sudo
-
u
redis
`
which
redis
-
server
`
/
etc
/
redis
.conf
|
错误描述
如果在make时,Redis报错:
1
2
|
zmalloc
.h
:
50
:
31
:
error
:
jemalloc
/
jemalloc
.h
:
No
such
file
or
directory
zmalloc
.h
:
55
:
2
:
error
:
#error "Newer version of jemalloc required"
|
原因分析
在README有这个一段话。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
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
.
To
force
compiling
against
libc
malloc
,
use
:
%
make
MALLOC
=
libc
To
compile
against
jemalloc
on
Mac
OS
X
systems
,
use
:
%
make
MALLOC
=
jemalloc
|
Redis在安装时关于内存分配器allocator, 如果指定了MALLOC这个环境变量,那么会用这个环境变量的去建立Redis。如果没有,那么就是用默认的分配器
Redis 2.4版本之后,默认使用jemalloc来做内存管理,因为jemalloc被证明解决fragmentation problems(内存碎片化问题)比libc更好。但是如果你又没有jemalloc而只有libc,当make出错时,你可以加这么一个参数即可。
1
|
make
MALLOC
=
libc
|
如果想用jemalloc,安装jemalloc即可。
如果使用yum安装的话需要安装EPEL源。
1
2
3
4
|
$
yum
install
jemalloc
$
rpm
-
ql
jemalloc
/
usr
/
bin
/
jemalloc
.sh
/
usr
/
lib64
/
libjemalloc
.so
.
1
|
也可以编译安装,先下载jemalloc:
https://github.com/jemalloc/jemalloc/releases/download/4.2.1/jemalloc-4.2.1.tar.bz2
1
2
3
4
|
$
tar
xvf
jemalloc
-
4.2.1.tar.bz2
$
cd
jemalloc
-
4.2.1
$
.
/
configure
--
prefix
=
/
usr
/
local
/
jemalloc
$
make
&&
make
install
|
1
2
3
4
5
6
|
$
ll
/
usr
/
local
/
jemalloc
/
total
16
drwxr
-
xr
-
x
2
root
root
4096
Nov
7
16
:
47
bin
drwxr
-
xr
-
x
3
root
root
4096
Nov
7
16
:
47
include
drwxr
-
xr
-
x
3
root
root
4096
Nov
7
16
:
47
lib
drwxr
-
xr
-
x
4
root
root
4096
Nov
7
16
:
47
share
|
然后再编译redis的时候指定MALLOC,如下:
1
|
make
MALLOC
=
/
usr
/
local
/
jemalloc
/
lib
|
当Redis进程跑起来之后,在你的实例中使用info命令可以查看你所使用的内存管理器。
1
|
mem_allocator
:
jemalloc
-
4.2.1
|
如果你使用的是libc,那么mem_allocator的参数就会是libc。