1:首先下載redis。
從下面地址下:https://github.com/MSOpenTech/redis/releases
2:建立redis.conf文件:
這是一個配置文件,指定了redis的監聽端口,timeout等。以下面有:port 6379。php
配置:html
遇到問題:git
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[18892] 05 Jan 16:02:28.584 #
The Windows version of Redis allocates a memory mapped heap
for
sharing with
the forked process used
for
persistence operations. In order to share
this
memory, Windows allocates
from
the system paging file a portion equal to the
size of the Redis heap. At
this
time there
is
insufficient contiguous free
space available
in
the system paging file
for
this
operation (Windows error
0x5AF). To work around
this
you may either increase the size of the system
paging file, or decrease the size of the Redis heap with the --maxheap flag.
Sometimes a reboot will defragment the system paging file sufficiently
for
this
operation to complete successfully.
Please see the documentation included with the binary distributions
for
more
details
on
the --maxheap flag.
Redis can not
continue
. Exiting.
|
處理方法:github
1
2
3
4
5
|
windows硬盤須要配置虛擬內存,若是還有問題,清理磁盤碎片
redis.windows.conf
<span style=
"color: #ff0000;"
><strong>maxheap 1024000000
daemonize no
</strong></span>
|
更改redis的配置須要修改redis.conf文件,如下是它一些主要的配置註釋:redis
#是否做爲守護進程運行
daemonize no
#Redis 默認監聽端口
port 6379
#客戶端閒置多少秒後,斷開鏈接
timeout 300
#日誌顯示級別
loglevel verbose
#指定日誌輸出的文件名,也可指定到標準輸出端口
logfile redis.log
#設置數據庫的數量,默認最大是16,默認鏈接的數據庫是0,能夠經過select N 來鏈接不一樣的數據庫 databases 32 #Dump持久化策略 #當有一條Keys 數據被改變是,900 秒刷新到disk 一次 #save 900 1 #當有10 條Keys 數據被改變時,300 秒刷新到disk 一次 save 300 100 #當有1w 條keys 數據被改變時,60 秒刷新到disk 一次 save 6000 10000 #當dump .rdb 數據庫的時候是否壓縮數據對象 rdbcompression yes #dump 持久化數據保存的文件名 dbfilename dump.rdb ########### Replication ##################### #Redis的主從配置,配置slaveof則實例做爲從服務器 #slaveof 192.168.0.105 6379 #主服務器鏈接密碼 # masterauth <master-password> ############## 安全性 ########### #設置鏈接密碼 #requirepass <password> ############### LIMITS ############## #最大客戶端鏈接數 # maxclients 128 #最大內存使用率 # maxmemory <bytes> ########## APPEND ONLY MODE ######### #是否開啓日誌功能 appendonly no # AOF持久化策略 #appendfsync always #appendfsync everysec #appendfsync no ################ VIRTUAL MEMORY ########### #是否開啓VM 功能 #vm-enabled no # vm-enabled yes #vm-swap-file logs/redis.swap #vm-max-memory 0 #vm-page-size 32 #vm-pages 134217728 #vm-max-threads 4
主從複製數據庫
在從服務器配置文件中配置slaveof ,填寫服務器IP及端口便可,若是主服務器設置了鏈接密碼,在masterauth後指定密碼就好了。windows
持久化安全
3.命令行操做服務器
使用CMD命令提示符,打開redis-cli鏈接redis服務器 ,也能夠使用telnet客戶端app
# redis-cli -h 服務器 –p 端口 –a 密碼
redis-cli.exe -h 127.0.0.1 -p 6379
鏈接成功後,就可對redis數據增刪改查了,如字符串操做:
如下是一些服務器管理經常使用命令:
info #查看服務器信息
select <dbsize> #選擇數據庫索引 select 1 flushall #清空所有數據 flushdb #清空當前索引的數據庫 slaveof <服務器> <端口> #設置爲從服務器 slaveof no one #設置爲主服務器 shutdown #關閉服務
附加幾個 bat 批處理腳本,請根據須要靈活配置
1
2
3
4
5
6
7
8
|
service-install.bat
redis-server.exe --service-install redis.windows.conf --loglevel verbose
uninstall-service.bat
redis-server --service-uninstall
startup.bat
redis-server.exe redis.windows.conf
|