基于centos7.7编译Redis6.0

本文涉及的产品
云原生多模数据库 Lindorm,多引擎 多规格 0-4节点
云数据库 Redis 版,社区版 2GB
推荐场景:
搭建游戏排行榜
云数据库 MongoDB,通用型 2核4GB
简介: 基于centos7.7 源码编译redis-6.0.6记录

背景:
OS:CentOs 7.7
Redis: 6.0.6

  1. 编译构建报错如下:
    ```javascript
    In file included from server.c:30:0:
    server.h:1044:5: error: expected specifier-qualifier-list before ‘_Atomic’
    _Atomic unsigned int lruclock; / Clock for LRU eviction /
    ^
    server.c: In function ‘serverLogRaw’:
    server.c:1028:31: error: ‘struct redisServer’ has no member named ‘logfile’
    int log_to_stdout = server.logfile[0] == '\0';
                            ^
    
    server.c:1031:23: error: ‘struct redisServer’ has no member named ‘verbosity’
    if (level < server.verbosity) return;
                    ^
    
    server.c:1033:47: error: ‘struct redisServer’ has no member named ‘logfile’
    fp = log_to_stdout ? stdout : fopen(server.logfile,"a");
                                            ^
    
    server.c:1046:47: error: ‘struct redisServer’ has no member named ‘timezone’
      nolocks_localtime(&tm,tv.tv_sec,server.timezone,server.daylight_active);
                                            ^
    
    server.c:1046:63: error: ‘struct redisServer’ has no member named ‘daylight_active’
      nolocks_localtime(&tm,tv.tv_sec,server.timezone,server.daylight_active);
                                                            ^
    
    server.c:1049:19: error: ‘struct redisServer’ has no member named ‘sentinel_mode’

...

server.c:5103:19: error: ‘struct redisServer’ has no member named ‘supervised_mode’
if (server.supervised_mode == SUPERVISED_SYSTEMD) {
^
server.c:5104:24: error: ‘struct redisServer’ has no member named ‘masterhost’
if (!server.masterhost) {
^
server.c:5117:15: error: ‘struct redisServer’ has no member named ‘maxmemory’
if (server.maxmemory > 0 && server.maxmemory < 10241024) {
^
server.c:5117:39: error: ‘struct redisServer’ has no member named ‘maxmemory’
if (server.maxmemory > 0 && server.maxmemory < 1024
1024) {
^
server.c:5118:176: error: ‘struct redisServer’ has no member named ‘maxmemory’
serverLog(LL_WARNING,"WARNING: You specified a maxmemory value that is less than 1MB (current value is %llu bytes). Are you sure this is what you really want?", server.maxmemory);

                             ^

server.c: In function ‘hasActiveChildProcess’:
server.c:1476:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
server.c: In function ‘allPersistenceDisabled’:
server.c:1482:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
server.c: In function ‘writeCommandsDeniedByDiskError’:
server.c:3747:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
server.c: In function ‘iAmMaster’:
server.c:4914:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
make[1]: [server.o] Error 1
make[1]: Leaving directory `/root/redis-6.0.1/src'
make:
[all] Error 2


编译文件报错,查看编译文件



[查看redis6.0 源码的makefile文件](https://github.com/redis/redis/blob/6.0/src/Makefile)

```c
/*Default settings 这里标明了需要用到C11的特性*/

STD=-std=c11 -pedantic -DREDIS_STATIC=''
ifneq (,$(findstring clang,$(CC)))
ifneq (,$(findstring FreeBSD,$(uname_S)))
  STD+=-Wno-c11-extensions
endif
endif
WARN=-Wall -W -Wno-missing-field-initializers
OPT=$(OPTIMIZATION)

PREFIX?=/usr/local
INSTALL_BIN=$(PREFIX)/bin
INSTALL=install
PKG_CONFIG?=pkg-config

# Default allocator defaults to Jemalloc if it's not an ARM
MALLOC=libc
ifneq ($(uname_M),armv6l)
ifneq ($(uname_M),armv7l)
ifeq ($(uname_S),Linux)
    MALLOC=jemalloc
endif
endif
endif

我们再去查看5.0

/* Default settings  这里版本5.0 支持的是c99特性
继续查看低版本,发现低于版本6.0 需要的是都是c99特性
*/

STD=-std=c99 -pedantic -DREDIS_STATIC=''
ifneq (,$(findstring clang,$(CC)))
ifneq (,$(findstring FreeBSD,$(uname_S)))
  STD+=-Wno-c11-extensions
endif
endif
WARN=-Wall -W -Wno-missing-field-initializers
OPT=$(OPTIMIZATION)

PREFIX?=/usr/local
INSTALL_BIN=$(PREFIX)/bin
INSTALL=install

/*Default allocator defaults to Jemalloc if it's not an ARM
这里也值得注意 架构不是arm 的 默认内存分配器是jemalloc
*/
MALLOC=libc
ifneq ($(uname_M),armv6l)
ifneq ($(uname_M),armv7l)
ifeq ($(uname_S),Linux)
    MALLOC=jemalloc
endif
endif
endif

C11特性

C11 参考链接

引用wiki的解释如下

GCC 4.9 Changes: “ISO C11 support is now at a similar level of completeness to ISO C99 support: substantially complete modulo bugs, extended identifiers (supported except for corner cases when -fextended-identifiers is used), floating-point issues (mainly but not entirely relating to optional C99 features from Annexes F and G) and the optional Annexes K (Bounds-checking interfaces) and L (Analyzability).

gcc版本在4.9 以上才有C11特性,我们的centos 7.7 默认gcc版本是4.8

C99特性

C99 参考链接

官方解释如下:

C99 is substantially completely supported as of GCC 4.5 (with -std=c99 -pedantic-errors used; -fextended-identifiers also needed to enable extended identifiers before GCC 5), modulo bugs and floating-point issues (mainly but not entirely relating to optional C99 features from Annexes F and G). The following table gives more details of the C99 support in different GCC versions.

c99特性是版本gcc 4.5有的

解决办法

  • 降低redis版本

  • 升级gcc版本 使其支持c11特性

    显然我们采用第二种 升级gcc版本

升级gcc

yum -y install gcc gcc-c++ make tcl centos-release-scl devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils && scl enable devtoolset-9 bash
系统版本 gcc版本
centos 6 4.4.7
centos 7 4.8.5
centos 8 8.3.1
相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
15天前
|
应用服务中间件 Linux 网络安全
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
14 0
|
2月前
|
存储 NoSQL Linux
centos7部署redis以及多实例
centos7部署redis以及多实例
55 0
|
3月前
|
关系型数据库 MySQL Linux
centos7 编译报错 cannot find -lmysqlclient
centos7 编译报错 cannot find -lmysqlclient
|
2月前
|
关系型数据库 MySQL Linux
Azkaban【部署 02】CentOS release 7.5安装配置azkaban-3.70.0安装阶段(含已编译的10个安装文件:可直接进行安装)
【2月更文挑战第5天】CentOS release 7.5安装配置azkaban-3.70.0安装阶段(含已编译的10个安装文件:可直接进行安装)
48 7
|
2月前
|
Java Linux 开发工具
Azkaban【部署 01】Linux环境 CentOS Linux release 7.5.1804安装配置azkaban-3.70.0编译阶段(附安装包及gradle-4.6资源)
【2月更文挑战第4天】Linux环境 CentOS Linux release 7.5.1804安装配置azkaban-3.70.0编译阶段(附安装包及gradle-4.6资源)
34 1
|
2月前
|
NoSQL 应用服务中间件 Linux
CentOS7搭建MySQL+Redis+MongoDB+FastDF
CentOS7搭建MySQL+Redis+MongoDB+FastDF
138 0
|
3月前
|
消息中间件 NoSQL Linux
什么是Redis数据库,如何在 CentOS 7 上安装 Redis,看完你就懂了
【1月更文挑战第1天】Redis ,是一个高性能(NOSQL)的key-value数据库,Redis是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。Redis是完全开源免费的,遵守BSD协议。
什么是Redis数据库,如何在 CentOS 7 上安装 Redis,看完你就懂了
|
4月前
|
SQL 关系型数据库 MySQL
centos编译安装mariadb
一般我不太愿意用mysql,那个玩意,有的时候不太友好。 我还是比较喜欢mariadb。
132 0
|
4月前
|
关系型数据库 MySQL Shell
centos编译安装mysql
centos编译安装mysql
137 0
|
4月前
|
应用服务中间件 Linux Shell
centos编译安装nginx(2)
安装成功之后,nginx的配置文件,在安装目录(/usr/local/nginx)下的conf目录下的nginx.conf中。 Php-fpm在安装的时候已经配置过了,这里不再赘述
56 0
centos编译安装nginx(2)

相关产品

  • 云数据库 Redis 版