mac與windows上部署使用Redis

windows下Redis安裝

在Redis的官網下載頁上有各類各樣的版本,因爲redis官網不支持windows,可是咱們偉大的windows家族仍是召喚了一羣小夥伴開發了win版的redis。要在windows上部署的,要去GitHub上下載。html

下載完成你會看到一個Redis-x64.rar,文件解壓文件出現如圖的結構:node

啓動Redis

下面介紹兩種啓動方式:git

第一種、直接運行redis-server.exe文件,你會看到一個彈出命令框:github

這樣redis就啓動了,redis

第二種,在解壓的redis目錄下運行windows

redis-server redis.windows.conf

結果就悲劇了,提示:服務器

QForkMasterInit: system error caught. error code=0x000005af, message=VirtualAllocEx failed.: unknown error

緣由是內存分配的問題。解決方法有兩個,第一:啓動的時候使用--maxmemory 命令限制Redis的內存:app

redis-server redis.windows.conf --maxmemory 200m

第二種方法就是修改配置文件redis.windows.conf :less

maxmemory 209715200

注意單位是字節,改完後以下:tcp

 

 

以後再運行redis-server redis.windows.conf 就能夠啓動了:

可是這種方式關閉cmd窗口就會關閉Redis,難道服務器上要一直開着嗎?這顯然是不科學的,下面看怎麼在服務器上部署。

windows下部署redis

下面咱們來看怎樣把redis部署到windows上的,這樣實現了咱們想要的開機自啓動。

redis-server --service-install redis.windows.conf

安裝完以後,就可看到Redis已經做爲windows服務了:

 

可是安裝好以後,Redis並無啓動,啓動命令以下:

redis-server --service-start

這樣就在windows下部署完成,並啓動了。

中止命令:

redis-server --service-stop

還能夠安裝多個實例並命名這些實例

redis-server --service-install –service-name redisService1 –port 10001
redis-server --service-start –service-name redisService1
redis-server --service-install –service-name redisService2 –port 10002
redis-server --service-start –service-name redisService2
redis-server --service-install –service-name redisService3 –port 10003
redis-server --service-start –service-name redisService3

卸載命令:

redis-server --service-uninstall

最後提示一下:2.8版本的不支持32位系統,32位系統要去下載2.6版本的。2.6版本的沒法像上面同樣方便的部署,它提供一個叫RedisWatcher的程序來運行redis server,Redis中止後會自動重啓。

 

mac下redis安裝

官網

下載 https://redis.io/download

文檔 https://redis.io/documentation

使用homebrew安裝

redis的安裝方法有2種:下載源碼編譯安裝和使用homebrew安裝。本文采用後一種方法,如需下載源碼編譯安裝參考 mac下安裝配置redis。執行如下命令:

brew install redis

終端輸出

==> Downloading http://download.redis.io/releases/redis-3.2.3.tar.gz
######################################################################## 100.0%
==> make install PREFIX=/usr/local/Cellar/redis/3.2.3 CC=clang
==> Caveats
To have launchd start redis now and restart at login:
  brew services start redis
Or, if you don't want/need a background service you can just run:
  redis-server /usr/local/etc/redis.conf
==> Summary
🍺  /usr/local/Cellar/redis/3.2.3: 10 files, 1.7M, built in 21 seconds

從以上日誌輸出能夠看出,若是須要給redis服務端指定配置文件,啓動命令應該是這樣的:

$ redis-server /usr/local/etc/redis.conf

經測試直接使用如下命令也能夠啓動:

$ redis-server

終端打印日誌以下:

 

34743:C 27 Mar 20:11:55.715 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
34743:M 27 Mar 20:11:55.716 * Increased maximum number of open files to 10032 (it was originally set to 256).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.2.3 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 34743
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

34743:M 27 Mar 20:11:55.717 # Server started, Redis version 3.2.3
34743:M 27 Mar 20:11:55.717 * The server is now ready to accept connections on port 6379

能夠看到啓動時不指定配置文件會使用默認配置文件。

關於默認配置文件

默認的配置文件就是使用homebrew安裝時提示的/usr/local/etc/redis.conf,使用cat命令查看:

$ cat /usr/local/etc/redis.conf

終端輸出文件內容(刪掉了大部分註釋):

 

bind 127.0.0.1 ::1
bind 127.0.0.1
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300

################################# GENERAL #####################################

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /usr/local/var/run/redis.pid when daemonized.
daemonize no


supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""


# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1
databases 16

################################ SNAPSHOTTING  ################################

save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb

# The working directory.
dir /usr/local/var/db/redis/

################################# REPLICATION #################################
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100

################################## SECURITY ###################################

################################### LIMITS ####################################

############################## APPEND ONLY MODE ###############################
appendonly no
appendfilename "appendonly.aof" 
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes

################################ LUA SCRIPTING  ###############################
lua-time-limit 5000

################################ REDIS CLUSTER  ###############################


################################## SLOW LOG ##################################

slowlog-max-len 128

################################ LATENCY MONITOR ##############################

latency-monitor-threshold 0

############################# EVENT NOTIFICATION ##############################

notify-keyspace-events ""

############################### ADVANCED CONFIG ###############################
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

官網上對於默認文件的描述:

Redis is able to start without a configuration file using a built-in default configuration, however this setup is only recommended for testing and development purposes.
The proper way to configure Redis is by providing a Redis configuration file, usually called redis.conf.

可見只有在開發和測試階段才考慮使用默認配置文件,正式環境最好仍是提供自定義的配置文件,而且通常命名爲redis.conf

相關文章
相關標籤/搜索