Redis 基础:Redis linux 下安装

mac2024-06-18  54

Redis 基础:在Linux 上源码安装 Redis

一、Redis 安装准备二、源码安装1. 源码编译 make2. 测试安装依赖 make test3. 安装命令 make installInstalling Redis4. 运行Redis1. 以默认配置文件方式运行Redis2. 验证Redis


一、Redis 安装准备

软件版本备注gcc gcc-c++直接yum就可以make 使用ncurses-devel直接yum就可以pcre-devel直接yum就可以加密make直接yum就可以tcl直接yum就可以make testRedis源码包直接解压主要安装包

二、源码安装

# 安装依赖包 gcc make tcl [root@localhost redis-5.0.6]# yum install -y gcc make tcl

解压源码包:

[root@localhost ~]# tar -xvf redis-5.0.6.tar.gz [root@localhost ~]# cd redis-5.0.6/ [root@localhost ~]# make

1. 源码编译 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

2. 测试安装依赖 make test

安装第二个坑: 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 tcl

Selecting 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=libc

To compile against jemalloc on Mac OS X systems, use: 在 Mac OS X 系统上强制编译为jemalloc

% make MALLOC=jemalloc

3. 安装命令 make install

实际上到第二步,Redis 已经安装完成可以正常启动,但是为了命令可以直接使用,可以使用 make install 命令

Installing Redis

将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.

4. 运行Redis

1. 以默认配置文件方式运行Redis

方法一:

[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

2. 验证Redis

运行redis-cli 客户端 % cd src % ./redis-cli redis> ping PONG

最新回复(0)