解压源码包:
[root@localhost ~]# tar -xvf redis-5.0.6.tar.gz [root@localhost ~]# cd redis-5.0.6/ [root@localhost ~]# 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原因是jemalloc重载了Linux下的ANSI C的malloc和free函数。解决办法:make时添加参数。
[root@localhost ~]# make MALLOC=libc安装第二个坑: make之后,会出现一句提示
Hint: To run 'make test' is a good idea ;)如果不测试,通常是可以使用的。测试仅是检查一下依赖,运行make test ,会有如下提示
[root@localhost ~]# make test You need tcl 8.5 or newer in order to run the Redis test make: ***[test] Error_1 ==解决办法是用 ==
[root@localhost ~]# yum install -y tclSelecting a non-default memory allocator when building Redis is done by setting theMALLOCenvironment 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.
在构建Redis时,通过设置环境变量“ MALLOC”来选择非默认的内存分配器。 默认情况下,Redis是针对libc malloc编译和链接的,但jemalloc是Linux系统上的默认值。 选择该默认值是因为事实证明,与libc malloc相比,jemalloc的碎片问题更少。
To force compiling against libc malloc, use: 在linux 下强制编译为 libc
% make MALLOC=libcTo compile against jemalloc on Mac OS X systems, use: 在 Mac OS X 系统上强制编译为jemalloc
% make MALLOC=jemalloc实际上到第二步,Redis 已经安装完成可以正常启动,但是为了命令可以直接使用,可以使用 make install 命令
将Redis 命令安装到 /usr/local/bin目录下,运行如下命令: In order to install Redis binaries into /usr/local/bin just use:
% make install你也可以使用 make PREFIX=/some/other/directory install 安装到自定义目录下 You can use make PREFIX=/some/other/directory install if you wish to use a different destination.
方法一:
[root@localhost ~]# redis-server & [1] 24324 ....... 4324:M 31 Oct 2019 18:34:25.740 * DB loaded from disk: 0.000 seconds 24324:M 31 Oct 2019 18:34:25.740 * `Ready to accept connections`方法二:
[root@localhost ~]# cd src [root@localhost ~]# ./redis-server运行redis-cli 客户端 % cd src % ./redis-cli redis> ping PONG