Linux安装Redis 6.0.1编译报错及systemctl配置详解
本次在Linux系统中安装Redis过程中遇到了一些以往未曾出现的编译及运行错误,现将具体现象与解决方案整理记录如下。
一、Redis安装过程及常见报错分析
前往Redis官方下载页面获取安装包:https://redis.io/download。
本例中选择稳定版6.0.1版本进行部署。

标准的安装流程通常包含下载、解压及编译安装等步骤。
[root@localhost ~]# yum install gcc
[root@localhost ~]# cd /usr/local
[root@localhost local]# wget http://download.redis.io/releases/redis-6.0.1.tar.gz
[root@localhost local]# tar -xvf redis-6.0.1.tar.gz
[root@localhost local]# cd /usr/local/redis-6.0.1/
[root@localhost redis-6.0.1]# make PREFIX=/usr/local/redis install
在执行make编译命令时,终端返回了以下错误信息。
make[1]: *** [server.o] 错误 1 make[1]: 离开目录“/usr/redis-6.0.1/src” make: *** [all] 错误 2
编译器详细报错指出结构体定义不匹配,具体包括: server.c:2402:11: 错误:‘struct redisServer'没有名为‘assert_file'的成员 server.assert_file = ""; ^ server.c:2403:11: 错误:‘struct redisServer'没有名为‘assert_line'的成员 server.assert_line = 0; ^ server.c:2404:11: 错误:‘struct redisServer'没有名为‘bug_report_start'的成员 server.bug_report_start = 0; ^ server.c:2405:11: 错误:‘struct redisServer'没有名为‘watchdog_period'的成员 server.watchdog_period = 0; ^ server.c:2411:11: 错误:‘struct redisServer'没有名为‘lua_always_replicate_commands'的成员 server.lua_always_replicate_commands = 1; ^ server.c: 在函数‘restartServer'中: server.c:2464:32: 错误:‘struct redisServer'没有名为‘maxclients'的成员 for (j = 3; j < (int)server.maxclients + 1024; j++) { ^ server.c: 在函数‘adjustOpenFilesLimit'中: server.c:2491:29: 错误:‘struct redisServer'没有名为‘maxclients'的成员 rlim_t maxfiles = server.maxclients+CONFIG_MIN_RESERVED_FDS; ^ server.c:2497:15: 错误:‘struct redisServer'没有名为‘maxclients'的成员 server.maxclients = 1024-CONFIG_MIN_RESERVED_FDS; ^ server.c:2529:53: 错误:‘struct redisServer'没有名为‘maxclients'的成员 unsigned int old_maxclients = server.maxclients; ^ server.c:2530:23: 错误:‘struct redisServer'没有名为‘maxclients'的成员 server.maxclients = bestlimit-CONFIG_MIN_RESERVED_FDS; ^ server.c:2554:59: 错误:‘struct redisServer'没有名为‘maxclients'的成员 (unsigned long long) bestlimit, server.maxclients); ^ server.c: 在函数‘checkTcpBacklogSettings'中: server.c:2574:48: 错误:‘struct redisServer'没有名为‘tcp_backlog'的成员 if (somaxconn > 0 && somaxconn < server.tcp_backlog) { ^ server.c:2575:171: 错误:‘struct redisServer'没有名为‘tcp_backlog'的成员 serverLog(LL_WARNING,"WARNING: The TCP backlog setting of %d cannot be enforced because /proc/sys/net /core/somaxconn is set to the lower value of %d.", server.tcp_backlog, somaxconn);



上述错误根源在于系统默认的GCC版本过低,无法识别Redis 6.0.1所需的C语言特性。解决方法是升级GCC版本。
首先检查当前GCC版本: [root@localhost redis-6.0.1]# gcc -v # 查看gcc版本 接着安装SCL源以获取新版工具链: [root@localhost redis-6.0.1]# yum -y install centos-release-scl # 升级到9.1版本 [root@localhost redis-6.0.1]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils 临时启用GCC 9.1环境: [root@localhost redis-6.0.1]# scl enable devtoolset-9 bash 若需永久生效,可将环境变量写入配置文件: 以上为临时启用,如果要长期使用gcc 9.1的话: [root@localhost redis-6.0.1]# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
完成环境升级后,重新执行编译安装命令。
[root@mmjredis redis-6.0.1]# make PREFIX=/usr/local/redis install
编译成功后,终端会提示建议运行测试:Hint: It's a good idea to run 'make test' 😉

接下来执行make test命令对Redis功能进行测试验证。
测试过程中出现了新的依赖缺失错误。
[root@localhost redis-6.0.1]# make test cd src && make test make[1]: 进入目录“/usr/redis-6.0.1/src” CC Makefile.dep make[1]: 离开目录“/usr/redis-6.0.1/src” make[1]: 进入目录“/usr/redis-6.0.1/src” You need tcl 8.5 or newer in order to run the Redis test make[1]: *** [test] 错误 1 make[1]: 离开目录“/usr/redis-6.0.1/src” make: *** [test] 错误 2

该错误表明系统缺少运行测试脚本所需的TCL解释器。
通过yum安装tcl包即可解决: [root@localhost redis-6.0.1]# yum install tcl[root@localhost redis-6.0.1]# make test
安装tcl后再次运行测试,所有用例均通过,显示测试成功。

确认编译无误后,先尝试手动启动Redis服务以验证基本功能。
[root@localhost redis-6.0.1]# /usr/local/redis-6.0.1/src/redis-server /usr/local/redis-6.0.1/redis.conf
32101:C 13 May 2026 17:01:48.248 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
32101:C 13 May 2026 17:01:48.248 # Redis version=6.0.1, bits=64, commit=00000000, modified=0, pid=32101, just started
32101:C 13 May 2026 17:01:48.248 # Configuration loaded
32101:M 13 May 2026 17:01:48.249 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.0.1 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 32101
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'

二、配置Redis后台启动模式
默认情况下Redis前台运行,需修改配置文件以实现后台守护进程模式。
编辑Redis主配置文件: [root@localhost redis-6.0.1]# vim redis.conf
找到daemonize配置项,将其值由no修改为yes: daemonize no 改成 daemonize yes
保存配置后,再次启动Redis服务。
[root@localhost redis-6.0.1]# /usr/redis-6.0.1/src/redis-server /usr/redis-6.0.1/redis.conf 30385:C 13 May 2026 16:57:58.918 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 30385:C 13 May 2026 16:57:58.918 # Redis version=6.0.1, bits=64, commit=00000000, modified=0, pid=30385, just started 30385:C 13 May 2026 16:57:58.918 # Configuration loaded
服务已成功转入后台运行,可通过进程列表查看并测试终止操作。
[root@localhost redis-6.0.1]# ps -aux|grep redis| grep -v grep root 29836 0.0 0.0 162416 7912 ? Ssl 16:56 0:00 /usr/redis-6.0.1/src/redis-server 127.0.0.1:6379 [root@localhost redis-6.0.1]# kill -9 29836
为了便于系统级管理,推荐使用systemctl方式启动和监控Redis。
首先需要创建systemd服务单元文件,将Redis注册为系统服务。
新建服务配置文件: vim /lib/systemd/system/redis.service
在文件中写入以下服务定义内容:
[Unit] Description=redis After=network.target
[Service] Type=forking PIDFile=/var/run/redis_6379.pid ExecStart=/usr/local/redis-6.0.1/src/redis-server /usr/local/redis-6.0.1/etc/redis.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true
[Install] WantedBy=multi-user.target
注意路径问题,以及PIDFile的路径对应的是redis-6.0.1/src/redis-server里面的PIDFile
确认无误后,按wq保存并退出编辑器。
配置完成后,执行以下命令启用并启动服务。
[root@localhost redis-6.0.1]# systemctl enable redis.service # 加入开机启动
验证开机自启状态: [root@localhost redis-6.0.1]# systemctl is-enabled redis.service # 查看开机是否启动成功 enabled
启动Redis服务: [root@localhost redis-6.0.1]# systemctl start redis #开启redis服务
检查服务当前运行状态: [root@localhost redis-6.0.1]# systemctl status redis //查看redis运行状态
若启动失败,可通过systemctl status redis命令查看详细日志以排查问题。

如图所示,服务状态显示active (running),表示启动成功。
以上内容涵盖了从编译报错处理到系统服务配置的完整流程,希望对读者有所帮助。