Windows 7 64位下編譯Redis-2.8.3/Redis-3.2.0

互聯網上也有提供windows版本的Redis,但通常會比官方低兩個版本以上,但這裏,咱們要親自動手進行最新版本的編譯。linux

###在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)模擬環境,爲咱們提供編譯環境。git

###本文將以Cygwin方式進行Redis經常使用版本的編譯,這裏先說明一下編譯環境: Windows 7 64位 + Cygwin 64位(已安裝好gcc 4.8.1 及 make環境)github

###下面進行詳細描述: ####1. 安裝Cygwin(須要4~6G disk space) 其安裝過程時間會較長,你們能夠先去幹一些喜歡作的事情,安裝過程就省略了redis

####2. 運行Cygwin,檢查編輯譯環境windows

$ 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進行適當修改 下載:ui

$ 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進行修改:this

$ vi src/redis.h

在第一個#define前增長如下代碼,解決"debug.c: 790:37: error: 'SA_ONSTACK' undeclared (first use in this function)"錯誤lua

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

若出現 ae_select.c:38:5: 錯誤: 提示未知的類型名'fd_set' fd_set rfds, wfds,則須要在 ae_select.c 的 第一個#include後增長如下內容spa

#include <sys/select.h>
#include <sys/time.h>

注:redis-2.8.3只須要進行上述修改便可順利編譯, redis-3.0.一、redis-3.2.0 須要更新net.c文件,以下:debug

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] 21 Dec 16:49:07.336 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
[7920] 21 Dec 16:49:07.338 # Unable to set the max number of files limit to 10032 (Too many open files), setting the max clients configuration to 3088.
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 2.8.3 (00000000/0) 64 bit
  .-`` .-` `.  ` `\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in stand alone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 7920
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'
[7920] 21 Dec 16:49:07.351 # Server started, Redis version 2.8.3
[7920] 21 Dec 16:49:07.351 * 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 | redis-3.2.0-win64.7z

注:redis-3.2.0 增長了 GEO API

相關文章
相關標籤/搜索