[root@localhost redis-6.2.6]# gcc --version gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2) Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
开始安装
进入到redis-6.2.6的解压目录
[root@localhost program]# ls redis-6.2.6 redis-6.2.6.tar.gz [root@localhost program]# cd redis-6.2.6/
指向make命令
如果出现下面这个错误,说明
[root@localhost redis-6.2.6]# make cd src && make all make[1]: Entering directory `/data/program/redis-6.2.6/src' CC Makefile.dep make[1]: Leaving directory `/data/program/redis-6.2.6/src' make[1]: Entering directory `/data/program/redis-6.2.6/src' CC adlist.o In file included from adlist.c:34: zmalloc.h:50:10: fatal error: jemalloc/jemalloc.h: No such file or directory 50 | #include <jemalloc/jemalloc.h> | ^~~~~~~~~~~~~~~~~~~~~ compilation terminated. make[1]: *** [adlist.o] Error 1 make[1]: Leaving directory `/data/program/redis-6.2.6/src' make: *** [all] Error 2
针对这个错误,可以在Redis的REAdme.MD文档中看到相关说明。
---------
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
Verbose build -------------
针对这个说明,很多人会通过下面这个命令去尝试解决。
make MALLOC=libc
虽然能够解决,但是并不是正确的解决办法,正确方法如下:
分别执行下面两个命令,其中make distclean主要是清理上次编译残留文件重新编译。
错误的本质是我们在开始执行make 时遇到了错误(大部分是由于gcc未安装),然后我们安装好了gcc 后,我们再执行make ,这时就出现了jemalloc/jemalloc.h: No such file or directory。这是因为上次的
[root@localhost redis-6.2.6]# make test cd src && make test make[1]: Entering directory `/data/program/redis-6.2.6/src' CC Makefile.dep make[1]: Leaving directory `/data/program/redis-6.2.6/src' make[1]: Entering directory `/data/program/redis-6.2.6/src' You need tcl 8.5 or newer in order to run the Redis test make[1]: *** [test] Error 1 make[1]: Leaving directory `/data/program/redis-6.2.6/src' make: *** [test] Error 2
从测试结果来看,仍然有错误:You need tcl 8.5 or newer in order to run the Redis test
需要安装tcl,于是执行下面这个指令进行安装。
[root@localhost redis-6.2.6]# yum install tcl
tcl安装结束后,再执行make test(正常情况下,这个过程会持续2分钟左右)
运行结果如下,表示编译全部正常。
\o/ All tests passed without errors!
Cleanup: may take some time... OK make[1]: Leaving directory `/data/program/redis-6.2.6/src'
通过make和make test编译后,开始执行安装。
执行make install安装,并使用PREFIX指定了安装目录。
[root@localhost redis-6.2.6]# make install PREFIX=/data/program/redis cd src && make install make[1]: Entering directory `/data/program/redis-6.2.6/src'
[root@localhost bin]# cd /data/program/redis/bin/ [root@localhost bin]# ls redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server [root@localhost bin]# ./redis-server ../redis.conf 10471:C 16 Nov 2021 21:13:21.319 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 10471:C 16 Nov 2021 21:13:21.319 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=10471, just started 10471:C 16 Nov 2021 21:13:21.319 # Configuration loaded 10471:M 16 Nov 2021 21:13:21.320 * Increased maximum number of open files to 10032 (it was originally set to 1024). 10471:M 16 Nov 2021 21:13:21.320 * monotonic clock: POSIX clock_gettime _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 6.2.6 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 10471 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | https://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-'
10471:M 16 Nov 2021 21:13:21.322 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 10471:M 16 Nov 2021 21:13:21.322 # Server initialized 10471:M 16 Nov 2021 21:13:21.322 # 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. 10471:M 16 Nov 2021 21:13:21.323 * Ready to accept connections ^C10471:signal-handler (1637068403) Received SIGINT scheduling shutdown... 10471:M 16 Nov 2021 21:13:23.931 # User requested shutdown... 10471:M 16 Nov 2021 21:13:23.931 * Saving the final RDB snapshot before exiting. 10471:M 16 Nov 2021 21:13:23.937 * DB saved on disk
修改/data/program/redis/redis.conf文件中下面两个配置。
# 开启后台守护进程方式运行 daemonize yes # 关闭保护模式 protected-mode no
#[root@localhost utils]# cd /data/program/redis-6.2.6/utils/
./install_server.sh
可能会得到如下错误
[root@localhost utils]# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server
This systems seems to use systemd. Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!
解决办法, vim /install_server.sh,将下面代码注释.
#_pid_1_exe="$(readlink -f /proc/1/exe)" #if [ "${_pid_1_exe##*/}" = systemd ] #then #echo"This systems seems to use systemd." #echo"Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!" #exit 1 #fi #unset _pid_1_exe
再次执行./install_server.sh。
下面这个安装过程是交互是的,可以根据自己的实际情况制定相关配置。
[root@localhost utils]# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server # 默认使用的端口 Please select the redis port for this instance: [6379] Selecting default: 6379 # 选择redis.conf文件的路径 Please select the redis config file name [/etc/redis/6379.conf] /data/program/redis/redis.conf # 选择Redis日志存储路径及文件名称(如果指定路径不存在,则需要先创建) Please select the redis log file name [/var/log/redis_6379.log] /data/program/redis/log/redis.log # 选择Redis数据存储路径 Please select the data directory for this instance [/var/lib/redis/6379] /data/program/redis/data # 选择Redis安装目录下的`redis-server`执行文件 Please select the redis executable path [] /data/program/redis/bin/redis-server Selected config: Port : 6379 Config file : /data/program/redis/redis.conf Log file : /data/program/redis/log/redis.log Data dir : /data/program/redis/data Executable : /data/program/redis/bin/redis-server Cli Executable : /data/program/redis/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful! [root@localhost utils]#