1,下载
从官网https://redis.io/
下载最新stable稳定版本版本
[root@ecs-7bc6-0001 package]# wget http://download.redis.io/releases/redis-5.0.0.tar.gz
--2018-11-14 19:56:30-- http://download.redis.io/releases/redis-5.0.0.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1947721 (1.9M) [application/x-gzip]
Saving to: ‘redis-5.0.0.tar.gz
2,解压安装包
[root@ecs-7bc6-0001 package]# tar -zxvf redis-5.0.0.tar.gz
[root@ecs-7bc6-0001 package]# ls
redis-5.0.0 redis-5.0.0.tar.gz
3,编译
安装gcc
[root@ecs-7bc6-0001 redis-5.0.0]# yum -y install gcc
编译redis,发现错误
[root@ecs-7bc6-0001 redis-5.0.0]# make
cd src && make all
make[1]: Entering directory `/home/work/package/redis-5.0.0/src'
CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
#include <jemalloc/jemalloc.h>
^
compilation terminated.
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/home/work/package/redis-5.0.0/src'
make: *** [all] Error 2
查看redis文档,发现linux下redis默认的内存分配器使用的是jemalloc,因为jemalloc已证明比libc malloc具有更少的碎片问题。
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
这时指定make MALLOC=libc或者安装jemalloc
安装jemalloc
1)配置jemalloc,redis目录下
[root@ecs-7bc6-0001 redis-5.0.0]# cd deps/jemalloc/
[root@ecs-7bc6-0001 jemalloc]# ./configure
2)编译jemalloc
[root@ecs-7bc6-0001 jemalloc]# make
配置lua
[root@ecs-7bc6-0001 redis-5.0.0]# cd deps/lua/
[root@ecs-7bc6-0001 lua]# make linux
lua配置过程中可以需要安装依赖readline-dev
In file included from lua.h:16:0,
from lua.c:15:
luaconf.h:275:31: fatal error: readline/readline.h: No such file or directory
#include <readline/readline.h>
^
compilation terminated.
make[2]: *** [lua.o] Error 1
make[2]: Leaving directory `/home/work/package/redis-5.0.0/deps/lua/src'
make[1]: *** [linux] Error 2
make[1]: Leaving directory `/home/work/package/redis-5.0.0/deps/lua/src'
make: *** [linux] Error 2
这时安装readline-devel
[root@ecs-7bc6-0001 lua]# yum -y install readline-devel
再次编译,成功
编译hiredis
[root@ecs-7bc6-0001 redis-5.0.0]# cd deps/hiredis/
[root@ecs-7bc6-0001 hiredis]# make
再次编译redis,编译成功。
4,测试
[root@ecs-7bc6-0001 redis-5.0.0]# make test
cd src && make test
make[1]: Entering directory `/home/work/package/redis-5.0.0/src'
CC Makefile.dep
make[1]: Leaving directory `/home/work/package/redis-5.0.0/src'
make[1]: Entering directory `/home/work/package/redis-5.0.0/src'
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] Error 1
make[1]: Leaving directory `/home/work/package/redis-5.0.0/src'
make: *** [test] Error 2
测试失败,依赖tcl,安装tcl
[root@ecs-7bc6-0001 redis-5.0.0]# yum -y install tcl
再次测试,成功。
5,安装到/usr/local/bin
[root@ecs-7bc6-0001 redis-5.0.0]# cd utils/
[root@ecs-7bc6-0001 utils]# sh install_server.sh
安装完成后会自动启动redis
登录redis测试
[root@ecs-7bc6-0001 ~]# redis-cli
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set 1 1
OK
127.0.0.1:6379> get 1
"1"
127.0.0.1:6379> del 1
(integer) 1
恭喜你安装完成(^_^)