Windows Cygwin Redis 安装(转)

本文介绍如何在Windows环境下利用Cygwin环境编译Redis 2.8.3版本,包括安装Cygwin、检查编译环境、下载并修改Redis源代码、编译依赖包和主项目的过程,以及解决编译中遇到的特定问题,如针对Cygwin的修改。

在win平台下编译Redis一般有两种方式:

1. 基于MS VC进行编译,生成原生可执行文件

该方式需要创建MSVC项目文件以及对Redis源码进行适当调整。 这里提供一个可行版本,由微软开放团队进行维护,目前版本是Redis 2.6, 有MS VC的朋友可以尝试一下: 猛击:https://github.com/MSOpenTech/redis

2. 基于Cygwin进行编译

Cygwin是运行在windows平台上的POSIX系统(例如unix,linux,bsd)模拟环境,为我们提供编译环境。

本文将以Cygwin方式进行Redis最新版本的编译,即2.8.3版,这里先说明一下编译环境:

Windows 7 64位 + Cygwin 64位(已安装好gcc 4.8.1 及 make环境)

下面进行详细描述:

1. 安装Cygwin(需要4~6G disk space)

其安装过程时间会较长,大家可以先去干一些喜欢做的事情,安装过程就省略了

2. 运行Cygwin,检查编辑译环境
$ gcc -v
...
Target: x86_64-pc-cygwin ... Thread model: posix gcc version 4.8.1 (GCC) $ make -v GNU Make 4.0 Built for x86_64-pc-cygwin ... 
3. 下载Redis,对Redis进行适当修改

下载:

$ wget http://download.redis.io/releases/redis-2.8.3.tar.gz
$ tar -zxvf redis-2.8.3.tar.gz $ cd redis-2.8.3 

若要顺利编译,需要对redis.h进行修改:

$ vi src/redis.h

在第一个#define前增加以下代码,解决"debug.c: 790:37: error: 'SA_ONSTACK' undeclared (first use in this function)"错误

/* Cygwin Fix */   
#ifdef __CYGWIN__ #ifndef SA_ONSTACK #define SA_ONSTACK 0x08000000 #endif #endif 

注:redis-2.8.3只需要进行上述修改即可顺利编译, redis-3.0.1 需要更新net.c文件,如下:

vi /deps/hiredis/net.c

在 #include "sds.h"后增加以下代码

/* Cygwin Fix */   
#ifdef __CYGWIN__ #define TCP_KEEPCNT 8 #define TCP_KEEPINTVL 150 #define TCP_KEEPIDLE 14400 #endif 
4. 编译与运行

先编译依赖包

$ cd deps
$ make lua hiredis linenoise $ cd .. 

然后编译主项目

$ make && make install ... $ redis-server [7920] 21Dec16:49:07.336 # Warning: no config file specified, using the default config. Inorderto specify a config file use redis-server /path/to/redis.conf [7920] 21Dec16:49:07.338 # Unable toset the maxnumberof files limitto10032 (Too many open files), setting the max clients configuration to3088. _._ _.-``__ ''-._ _.-```. `_. ''-._ Redis 2.8

转载于:https://www.cnblogs.com/softidea/p/5044058.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值