当前位置: 首页 > 工具软件 > jemalloc > 使用案例 >

linux yum jemalloc,Redis安装报错error:jemalloc/jemalloc.h:No such file or directory解决方法

鲁乐
2023-12-01

安装Redis

下载Redis:

$ wget https://github.com/antirez/redis/archive/3.2.0.tar.gz

1

$wgethttps://github.com/antirez/redis/archive/3.2.0.tar.gz

在安装Redis之前,需要安装Redis的依赖程序tcl,如果不安装tcl在Redis执行make test的时候就会报错的哦。

$ yum install -y tcl

1

$yuminstall-ytcl

$ 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/

1

2

3

4

5

6

7

8

9

$tarxvf3.2.0.tar.gz-C/usr/local

$cd/usr/local/

$mvredis-3.2.0redis

$cdredis

$make

$maketest

$makeinstall

$mkdir/etc/redis

$cpredis/redis.conf/etc/

以redis用户启动redis

$ useradd -s /bin/false -M redis

$ sudo -u redis `which redis-server` /etc/redis.conf

1

2

$useradd-s/bin/false-Mredis

$sudo-uredis`whichredis-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"

1

2

zmalloc.h:50:31:error:jemalloc/jemalloc.h:Nosuchfileordirectory

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

Allocator

---------

Selectinganon-defaultmemoryallocatorwhenbuildingRedisisdonebysetting

the`MALLOC`environmentvariable.Redisiscompiledandlinkedagainstlibc

mallocbydefault,withtheexceptionofjemallocbeingthedefaultonLinux

systems.Thisdefaultwaspickedbecausejemallochasproventohavefewer

fragmentationproblemsthanlibcmalloc.

Toforcecompilingagainstlibcmalloc,use:

%makeMALLOC=libc

TocompileagainstjemalloconMacOSXsystems,use:

%makeMALLOC=jemalloc

Redis在安装时关于内存分配器allocator, 如果指定了MALLOC这个环境变量,那么会用这个环境变量的去建立Redis。如果没有,那么就是用默认的分配器

Redis 2.4版本之后,默认使用jemalloc来做内存管理,因为jemalloc被证明解决fragmentation problems(内存碎片化问题)比libc更好。但是如果你又没有jemalloc而只有libc,当make出错时,你可以加这么一个参数即可。

make MALLOC=libc

1

makeMALLOC=libc

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

如果使用yum安装的话需要安装EPEL源。

$ yum install jemalloc

$ rpm -ql jemalloc

/usr/bin/jemalloc.sh

/usr/lib64/libjemalloc.so.1

1

2

3

4

$yuminstalljemalloc

$rpm-qljemalloc

/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

1

2

3

4

$tarxvfjemalloc-4.2.1.tar.bz2

$cdjemalloc-4.2.1

$./configure--prefix=/usr/local/jemalloc

$make&&makeinstall

$ 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

1

2

3

4

5

6

$ll/usr/local/jemalloc/

total16

drwxr-xr-x2rootroot4096Nov716:47bin

drwxr-xr-x3rootroot4096Nov716:47include

drwxr-xr-x3rootroot4096Nov716:47lib

drwxr-xr-x4rootroot4096Nov716:47share

然后再编译redis的时候指定MALLOC,如下:

make MALLOC=/usr/local/jemalloc/lib

1

makeMALLOC=/usr/local/jemalloc/lib

当Redis进程跑起来之后,在你的实例中使用info命令可以查看你所使用的内存管理器。

mem_allocator:jemalloc-4.2.1

1

mem_allocator:jemalloc-4.2.1

如果你使用的是libc,那么mem_allocator的参数就会是libc。

如果您觉得本站对你有帮助,那么可以支付宝扫码捐助以帮助本站更好地发展,在此谢过。

 类似资料: