Windows Cygwin Redis 安装(转)
在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
...
$ 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
$ 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
$ 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
/* 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
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
/* 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 ..
$ 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.3 (00000000/0) 64bit
.-`` .-` `. ` `\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 7920
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[7920] 21Dec16:49:07.351 # Server started, Redis version2.8.3
[7920] 21Dec16:49:07.351 * The serverisnow ready to accept connections on port 6379
$ 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.3 (00000000/0) 64bit
.-`` .-` `. ` `\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 7920
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[7920] 21Dec16:49:07.351 # Server started, Redis version2.8.3
[7920] 21Dec16:49:07.351 * The serverisnow ready to accept connections on port 6379
$ redis-server.exe
8172:C 16 May 17:51:01.316 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
8172:M 16 May 17:51:01.322 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
8172:M 16 May 17:51:01.322 # Redis can't set maximum open files to 10032 because of OS error: Too many open files.
8172:M 16 May 17:51:01.322 # Current maximum open files is 3200. maxclients has been reduced to 3168 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.1 (00000000/0) 64 bit
.-`` .-``. ``\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 8172
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'`-._ _.-'
`-.__.-'
8172:M 16 May 17:51:01.404 # Server started, Redis version 3.0.1
8172:M 16 May 17:51:01.410 * DB loaded from disk: 0.006 seconds
8172:M 16 May 17:51:01.410 * The server is now ready to accept connections on port 6379
$ redis-server.exe
8172:C 16 May 17:51:01.316 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
8172:M 16 May 17:51:01.322 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
8172:M 16 May 17:51:01.322 # Redis can't set maximum open files to 10032 because of OS error: Too many open files.
8172:M 16 May 17:51:01.322 # Current maximum open files is 3200. maxclients has been reduced to 3168 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.1 (00000000/0) 64 bit
.-`` .-``. ``\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 8172
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'`-._ _.-'
`-.__.-'
8172:M 16 May 17:51:01.404 # Server started, Redis version 3.0.1
8172:M 16 May 17:51:01.410 * DB loaded from disk: 0.006 seconds
8172:M 16 May 17:51:01.410 * The server is now ready to accept connections on port 6379
成功的话可以看到以上信息,可执行下文件默认安装到/usr/local/bin下。
5. 提取依赖库,使其可以在Cygwin之外运行
最后,若需要在Cygwin之外运行,还需要拷贝/bin下的cygwin1.dll文件,这里提供一个已打包好的版本(64位,对于32位的朋友只能说sorry了) 猛击:redis-2.8.3-win64.7z | redis-3.0.1-win64.7z
http://xxk.b3log.org/articles/2015/08/21/1440141912836.html
转载 http://my.oschina.net/maxid/blog/1
http://hacpai.com/article/144014475291886506
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2014-12-14 java代码中获取进程process id(转)
2014-12-14 javaCore分析示例(转)
2014-12-14 java之Thread.sleep(long)与object.wait()/object.wait(long)的区别及相关概念梳理(good)
2014-12-14 一个load飙高的过程分析,非常有价值(转)