1. 程式人生 > >Redis安裝報錯error:jemalloc/jemalloc.h:No such file or directory解決方法

Redis安裝報錯error:jemalloc/jemalloc.h:No such file or directory解決方法

安裝Redis

在安裝Redis之前,需要安裝Redis的依賴程式tcl,如果不安裝tcl在Redis執行make test的時候就會報錯的哦。

$ yum install -y tcl
$ 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

$ useradd -s /bin/false -M redis
$ sudo
-u redis `which redis-server` /etc/redis.conf

錯誤描述

如果在make時,Redis報錯:

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有這個一段話。

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出錯時,你可以加這麼一個引數即可。

make MALLOC=libc

如果想用jemalloc,安裝jemalloc即可。

如果使用yum安裝的話需要安裝EPEL源。

$ yum install jemalloc
$ rpm -ql jemalloc
/usr/bin/jemalloc.sh
/usr/lib64/libjemalloc.so.1

也可以編譯安裝,先下載jemalloc:

$ tar xvf jemalloc-4.2.1.tar.bz2
$ cd jemalloc-4.2.1
$ ./configure --prefix=/usr/local/jemalloc
$ make && make install
$ 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,如下:

make MALLOC=/usr/local/jemalloc/lib

當Redis程序跑起來之後,在你的例項中使用info命令可以檢視你所使用的記憶體管理器。

mem_allocator:jemalloc-4.2.1

如果你使用的是libc,那麼mem_allocator的引數就會是libc。