1. 程式人生 > >Windows 下的 Redis 叢集搭建

Windows 下的 Redis 叢集搭建

本文第一篇主要介紹redis在windows平臺下的編譯。   

  • 一、下載cygwin

cygwin是windows平臺上的posix系統模擬環境,具體的版本,請根據自己當前系統的版本來,我的系統是windows7 64位。

  • 二、下載最新版redis

redis的版本根據自己的需求來,因為我們要搭建叢集,所以下載 3.0.0beta版

  • 三、安裝cygwin

cygwin的安裝網上有不少圖解(猛擊: 圖解教程 ),直接下一步就好,需要主要的一點是注意選擇好自己需要的包,如下圖:


你會看到Dvel下有許多入庫,其中只需要安裝5個就夠:

gcc: C complier upgrade helper 
  gcc-core:C 編譯器 gcc-g++:
  C++ 編譯器 gdb:GNU 偵錯程式 
  make:"make"
實用程式的 GNU 版本

具體如何安裝,自己百度腦補,不多說了,這個安裝時間較長,可以乾點其他的了。

  • 四、檢查編譯環境  

$ gcc -v
使用內建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/lto-wrapper.exe
目標:x86_64-pc-cygwin
執行緒模型:posix
gcc 版本 4.8.3 (GCC)

$ make -v
GNU Make 4.0
Built for x86_64-pc-cygwin

在cygwin的控制端上,看到gcc和make都安裝成功。

redis原始碼的處理,編譯前,進入到redis的src目錄, 在第一個#define前增加以下程式碼。

/* Cygwin Fix */   
#ifdef __CYGWIN__   
#ifndef SA_ONSTACK   
#define SA_ONSTACK 0x08000000   
#endif   
#endif
  • 五、編譯

我們先看下redis原始碼的目錄:


來,先編譯依賴包:

$ cd deps
$ make lua hiredis linenoise

編譯原始碼:

cd ..
make && make install
...此處省略一萬字(祈禱吧)

佛祖保佑成功的話,你就就編譯成功了,開啟redis服務試下

$ redis-server.exe
[3232] 30 Dec 15:40:05.171 # Warning: no config file specified, using the defaul						   t config. In order to specify a config file use redis-server /path/to/redis.conf
[3232] 30 Dec 15:40:05.202 # Unable to set the max number of files limit to 1003						   2 (Too many open files), setting the max clients configuration to 3088.
				_._
		   _.-``__ ''-._
	  _.-``	`.  `_.  ''-._		   Redis 2.9.50 (00000000/0) 64 bit
  .-`` .-```.  ```\/	_.,_ ''-._
 (	'	  ,	   .-`  | `,	)	 Running in stand alone mode
 |`-._`-...-` __...-.``-._|'` _.-'|	 Port: 6379
 |	`-._   `._	/	 _.-'	|	 PID: 3232
  `-._	`-._  `-./  _.-'	_.-'
 |`-._`-._	`-.__.-'	_.-'_.-'|
 |	`-._`-._		_.-'_.-'	|		   http://redis.io
  `-._	`-._`-.__.-'_.-'	_.-'
 |`-._`-._	`-.__.-'	_.-'_.-'|
 |	`-._`-._		_.-'_.-'	|
  `-._	`-._`-.__.-'_.-'	_.-'
	  `-._	`-.__.-'	_.-'
		  `-._		_.-'
			  `-.__.-'
[3232] 30 Dec 15:40:05.222 # Server started, Redis version 2.9.50
[3232] 30 Dec 15:40:05.222 * The server is now ready to accept connections on po						   rt 6379

以上就ok了,預設埠:6379

執行檔案的位置:

$ cd /usr/local/bin

[email protected] /usr/local/bin
$ ls -al
總用量 3380
drwxr-xr-x+ 1 wier None       0 十二 30 15:37 .
drwxr-xr-x+ 1 wier None       0 十二 26 18:39 ..
-rwxr-xr-x  1 wier None  350267 十二 30 15:37 redis-benchmark.exe
-rwxr-xr-x  1 wier None   88725 十二 30 15:37 redis-check-aof.exe
-rwxr-xr-x  1 wier None  118232 十二 30 15:37 redis-check-dump.exe
-rwxr-xr-x  1 wier None  441669 十二 30 15:37 redis-cli.exe
-rwxr-xr-x  1 wier None 2449805 十二 30 15:37 redis-server.exe

cygwin1.dll檔案的位置:

$ cd /bin
$ find . -maxdepth 1 -name "cygwin1.dll"
./cygwin1.dll
  • 六、提取,使其在window下執行

目前是在cygwin下執行,我們要把他弄出來,在windows下執行

進入cygwin控制埠.

$ cd e:
$ mkdir redis3.0
$ cp -r /usr/local/bin/* e:/redis3.0
$  cp -r /bin/cygwin1.dll e:/redis3.0

上面依次是進入e盤,建立redis3.0目錄,拷貝編譯後文件到redis3.0目錄。

在windows下可以看到


如此就可以在windows下執行了,現在可以把原始碼下面的配置檔案 redis.conf 拷貝到當前資料夾下,如此,可以隨意搭建自己的配置了。


redis命令:

#啟動
redis-server.exe redis.conf
#本地客戶端進入
redis-cli.exe -h 127.0.0.1 -p 6379


喜歡我的文章的,可以關注微信公眾號“測試專案開發”,需要什麼內容可以在裡面提,我看到後會給大家解答。