redis-5.0.3 Windows下编译

本文详细介绍了在Cygwin环境下编译安装Redis 3.0.x版本的步骤,包括配置宏定义、注释Makefile文件、编译依赖库等,并提供了处理常见错误的方法,如解决unknown typename ‘u_short’及hyperloglog.c文件中llroundl调用错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第 0 步,给 Cygwin 环境安装 gcc、make。

第 1 步,修改/usr/include/netinet/tcp.h文件,在后边添加这几个宏定义:

#ifndef TCP_KEEPIDLE?
#define TCP_KEEPIDLE 4 /* Start keeplives after this period */?
#endif?

#ifndef TCP_KEEPINTVL?
#define TCP_KEEPINTVL 5 /* Interval between keepalives */?
#endif?

#ifndef TCP_KEEPCNT
#define TCP_KEEPCNT 6 /* Number of keepalives before death */?
#endif

第 2 步,修改 redis-3.0.x/src/fmacros.h 文件,在前面加入这一个宏定义:
/* Cygwin Fix */
#ifdef __CYGWIN__
#ifndef SA_ONSTACK
#define SA_ONSTACK 0x08000000
#endif
#endif

第 3 步,修改 redis-3.0.x/src/Makefile 文件,转到第 73 行,(用 # 号)注释掉:
# FINAL_LDFLAGS+= -rdynamic // <-- 添加 # 把这行注释掉

第 4 步,到 redis-3.0.x/deps 目录下运行 make 命令:
$ cd redis-3.0.x/deps
$ make lua hiredis linenoise

第 5 步,回到 redis-3.0.x 目录运行 make 命令:
$ make && make install

第 6 步,启动 redis 服务器和客户端:
$ redis-server.exe
$ redis-cli.exe

 

#错误处理

遇到 error: unknown type name ‘u_short’,

修改 fmacros.h 文件,把判断 linux 的地方,增加判断 CYGWIN。例如:

#if defined(__linux__)
#define _GNU_SOURCE
#define _DEFAULT_SOURCE
#endif
改成:

#if defined(__linux__) || defined(__CYGWIN__) // <-- 在这里增加判断 CYGWIN
#define _GNU_SOURCE
#define _DEFAULT_SOURCE
#endif
另外,还需要修改 deps/hiredis/fmacros.h,也要增加判断 CYGWIN:

#if defined(__linux__) || defined(__CYGWIN__)
#define _GNU_SOURCE
#define _DEFAULT_SOURCE
#endif

 

遇到 hyperloglog.c文件 llroundl调用报错,就把llroundl改为round

# redis 安装 ## 安装gcc依赖 由于 redis 是用 C 语言开发,安装之前必先确认是否安装 gcc 环境(gcc -v),如果没有安装,执行以下命令进行安装 ``` yum install -y gcc ``` ## 下载并解压安装包 ``` #下载 wget http://download.redis.io/releases/redis-5.0.3.tar.gz `#解压` tar -zxvf redis-5.0.3.tar.gz ``` ## 编译 ``` cd redis-5.0.3 `#编译` make ``` ## 安装并指定安装目录 ``` #方法一:安装指定目录(安装完成后会在目录下面生成一个bin目录)` #make install PREFIX=/usr/local/redis #方法二:默认安装到/usr/local/bin redis-5.0.0>make install ``` ## 启动服务 ### 前台启动 ``` #指定目录安装执行 cd /usr/local/redis/bin/ ./redis-server #默认目录安装执行 redis-server /usr/local/bin/redis.conf ``` ### 后台启动 从 redis 的源码目录中复制 redis.conf 到 redis 的安装目录 ``` cp /usr/local/redis-5.0.3/redis.conf /usr/local/redis/bin/ ``` 修改 redis.conf 文件,把 daemonize no 改为 daemonize yes ``` vi redis.conf “/”加关键词就可以搜索 将其改为 yes ``` ![img](redis5_files\1.png) 后台启动 ```shell ./redis-server redis.conf netstat -ntlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 5963/./redis-server tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1013/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1187/master tcp6 0 0 :::3306 :::* LISTEN 1499/mysqld tcp6 0 0 :::22 :::* LISTEN 1013/sshd tcp6 0 0 ::1:25 :::* LISTEN 1187/master 关闭 kill -9 67859 ``` ![img](redis5_files\2.png) ## 使用密码 修改redis.conf文件,将requirepass前的#去掉,并修改密码 ![image-20210929133526898](redis5_files\4.png) ## 日志文件 * 如果不修改logfile配置,默认不产生配置文件 * 如果不另外修改dir配置,默认在当前目录 ``` logfile "redis.log" ``` ## 充许远程连接 默认只充许本机连接,将bind 127.0.0.1改为0.0.0.0 ![image-20210929133722275](redis5_files\5.png) 开放对应的端口 ## 客户端连接 redis-cli连接 ``` redis-cli [-h <host>] [-p <port>] [-a <password>] host:redis服务器host port:redis
03-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值