author:徐振东
createTime:2022-05-16
updateTime:2022-06-10
2022-06-10: 培训结束
# Redis 安装
最新版本redis下载地址:https://redis.io/download
# 下载源码并编译
下面以5.0.3版本为例演示从源码下载到安装启动的全过程
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
tar -xzvf redis-5.0.3.tar.gz
cd redis-5.0.3
make # 编译
make 编译过后进入src目录就能看见编译后的 redis 服务程序 redis-server、用于测试的客户端程序 redis-cli
# 启动 redis 服务
下面启动 redis 服务
[root@105 redis-5.0.3]# src/redis-server redis.conf
68053:C 18 Mar 2021 16:35:05.328 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
68053:C 18 Mar 2021 16:35:05.328 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=68053, just started
68053:C 18 Mar 2021 16:35:05.328 # Configuration loaded
68053:M 18 Mar 2021 16:35:05.330 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.3 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 68053
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
68053:M 18 Mar 2021 16:35:05.332 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
68053:M 18 Mar 2021 16:35:05.332 # Server initialized
68053:M 18 Mar 2021 16:35:05.332 # 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.
68053:M 18 Mar 2021 16:35:05.332 # 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.
68053:M 18 Mar 2021 16:35:05.332 * Ready to accept connections
redis启动成功
# 安装过程中可能碰到的坑
未安装 gcc 服务,导致redis源码编译失败
解决方案:
缺啥补啥,通过yum安装 gcc 的服务
yum install gcc
安装完以后再次执行 make 命令
源码编译失败,解决完提示的报错问题后,仍无法编译,报错某某目录或文件不存在
报错信息如下
[root@106 redis-5.0.3]# make cd src && make all make[1]: Entering directory `/data/tools/redis/redis-5.0.3/src' CC Makefile.dep make[1]: Leaving directory `/data/tools/redis/redis-5.0.3/src' make[1]: Entering directory `/data/tools/redis/redis-5.0.3/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 `/data/tools/redis/redis-5.0.3/src' make: *** [all] Error 2
改文件或目录可能是上次编译过程中产生的中间文件,执行编译清除命令即可继续向下执行
- make distclean
- make clean
[root@106 redis-5.0.3]# make distclean cd src && make distclean make[1]: Entering directory `/data/tools/redis/redis-5.0.3/src' rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark (cd ../deps && make distclean) make[2]: Entering directory `/data/tools/redis/redis-5.0.3/deps' (cd hiredis && make clean) > /dev/null || true (cd linenoise && make clean) > /dev/null || true (cd lua && make clean) > /dev/null || true (cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true (rm -f .make-*) make[2]: Leaving directory `/data/tools/redis/redis-5.0.3/deps' (rm -f .make-*) make[1]: Leaving directory `/data/tools/redis/redis-5.0.3/src' [root@106 redis-5.0.3]# make clean cd src && make clean make[1]: Entering directory `/data/tools/redis/redis-5.0.3/src' rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark make[1]: Leaving directory `/data/tools/redis/redis-5.0.3/src'