在CentOS下安装Redis

时间:2023-02-07 15:43:26

Redis比较傲娇,在windows上还没有很好的安装方式,不得已搞了个虚拟机玩玩。

装Redis十分简单,按照下面的几个命令来就行了。

安装命令

wget http://download.redis.io/redis-stable.tar.gz
tar xzf redis-stable.tar.gz
cd redis-stable
make

在make之前别忘了要装gcc啊!

进入目录redis-stable之后,直接进行make命令会报错的:



zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory

zmalloc.h:55:2: error: #error "Newer version of jemalloc required"

make[1]: *** [adlist.o] Error 1

make[1]: Leaving directory `/data0/src/redis-2.6.2/src'

make: *** [all] Error 2

原因

在README中有一段话是:



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

说关于分配器allocator,如果有MALLOC这个环境变量,会有用这个环境变量的去建立Redis。

而且libc并不是默认的分配器,默认的是jemalloc,因为 jemalloc被证明有更少的fragmentation problems比libc。

但是如果你又没有jemalloc而只有libc当然make出错。所以加这么一个参数。

但是我继续在原来的包里面通过make MALLOC=libc安装,但是还是失败了,后来把之前解压的给删掉了,重新解压了一个,然后在用这个命令就装好了。

Hint: It's a good idea to run 'make test'