Linux下安装Redis基本步骤
文章目录
- 1. 安装步骤
- 1.1 下载解压:
- 1.2 编译安装:
- 1 make:
- 2 启动:
- 1.3 编译常见问题:
- 问题1: 缺少gcc依赖
- 问题2: 缺少jemalloc依赖
- 问题3: 安装jemalloc 继续make出现问题(未解决!!)
1. 安装步骤
下载,解压,make
1.1 下载解压:
wget http://download.redis.io/releases/redis-4.0.9.tar.gz
tar xzf redis-4.0.9.tar.gz
1.2 编译安装:
1 make:
cd redis-4.0.9/
make
或者(详见问题2说明)
make MALLOC=libc
执行结果:
LINK redis-server
INSTALL redis-sentinel
CC redis-cli.o
LINK redis-cli
CC redis-benchmark.o
LINK redis-benchmark
INSTALL redis-check-rdb
INSTALL redis-check-aof
Hint: It's a good idea to run 'make test' ;)
make[1]: 离开目录“/data/redis-4.0.9/src”
执行make test 检测安装
make test
会得到如下结果提示“All tests passed without errors!”,表示make成功
93 seconds - integration/replication
94 seconds - unit/aofrw
105 seconds - integration/replication-3
57 seconds - unit/hyperloglog
60 seconds - unit/geo
116 seconds - unit/type/list-3
72 seconds - unit/obuf-limits
107 seconds - integration/replication-psync
\o/ All tests passed without errors!
Cleanup: may take some time... OK
make[1]: 离开目录“/data/redis-4.0.9/src”
2 启动:
安装完成后在src目录下会出现服务程序redis-server,按默认方式启动redis
[root@node02 redis-4.0.9]# src/redis-server
执行结果
[root@node02 redis-4.0.9]# src/redis-server
39918:C 29 Oct 11:09:01.387 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
39918:C 29 Oct 11:09:01.387 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=39918, just started
39918:C 29 Oct 11:09:01.387 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
39918:M 29 Oct 11:09:01.388 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.9 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 39918
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
39918:M 29 Oct 11:09:01.396 # Server initialized
39918:M 29 Oct 11:09:01.397 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
39918:M 29 Oct 11:09:01.397 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
39918:M 29 Oct 11:09:01.397 * Ready to accept connections
1.3 编译常见问题:
问题1: 缺少gcc依赖
/bin/sh:行1: cc:未找到命令
解决:
安装gcc依赖包
yum install gcc-c++ -y
问题2: 缺少jemalloc依赖
> In file included from adlist.c:34:
zmalloc.h:50:10: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
50 | #include <jemalloc/jemalloc.h>
| ^~~~~~~~~~~~~~~~~~~~~
错误原因:
redis默认要使用jemalloc作为内存分配器,单系统不具备,只有默认的libc;
解决方案有两种:
1. make命令指定libc:
make MALLOC=libc
2. 在系统中安装 jemalloc;
2.1 jemalloc 相对libc的好处:
① 减少内存碎片,提升内存使用效率;
② 多线程环境表现优异,有较高的并发性能;
③ 支持多种内存分配算法,可根据场景优化;
④ 对发内存分配表现较好;
2.2 jemalloc 安装:
1. 安装epel仓库
sudo yum install epel-release
2. 安装jemalloc
sudo yum install jemalloc-devel
问题3: 安装jemalloc 继续make出现问题(未解决!!)
注: 问题2 jemalloc 问题采用方案1:make MALLOC=libc 解决,可以避免这个问题;
/usr/bin/ld: 找不到 ../deps/hiredis/libhiredis.a: 没有那个文件或目录
/usr/bin/ld: 找不到 ../deps/lua/src/liblua.a: 没有那个文件或目录
collect2: 错误:ld 返回 1
make[1]: *** [Makefile:199:redis-server] 错误 1
make[1]: 离开目录“/data/redis-4.0.9/src”
make: *** [Makefile:6:all] 错误 2