redis sentinel配置(windows环境)

redis sentinel配置(windows环境)


环境介绍

1.操作系统windows7
2.redis版本3.2

安装redis

1.redis官方暂不支持windows版本,所以需要在github下载。

    https://github.com/MicrosoftArchive/redis/releases

2.解压至本地。

redis sentinel配置(windows环境)_第1张图片

集群配置

master ip:127.0.0.1 port:6379  
slave1 ip:127.0.0.1 port:6380  
slave2 ip:127.0.0.1 port:6381  
sentinel1 ip:127.0.0.1 port:16379
sentinel2 ip:127.0.0.1 port:16380
sentinel3 ip:127.0.0.1 port:16381

修改配置文件

1.复制并新建三份redis.conf文件,分别命名为redis6379.conf、redis6380.conf、redis6381.conf。

其中,redis6379.conf为master的conf,redis6380.conf和redis6381.conf为slave1和slave2的conf。

2.redis6379.conf配置信息如下:

bind 127.0.0.1
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile “”
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./redis-6379
masterauth 15144
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
repl-backlog-size 1mb
slave-priority 100
requirepass 15144
appendonly yes
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-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events “”
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.conf各配置项具体作用可参照redis.conf原文件的注释。

3.redis6380.conf和redis6381.conf的配置信息大部分与redis6379.conf相同,需改动配置项如下:

redis6380.conf
bind 127.0.0.1
slaveof 127.0.0.1 6379
port 6380
dir ./redis-6380

redis6381.conf
bind 127.0.0.1
slaveof 127.0.0.1 6379
port 6381
dir ./redis-6381

4.新建三份 sentinel.conf 配置文件,分别命名为sentinel16379.conf、sentinel16380.conf、sentinel16381.conf。配置信息如下:

port 16379
sentinel monitor mymaster 127.0.0.1 6379 2   
sentinel down-after-milliseconds mymaster 5000  
sentinel parallel-syncs mymaster 1  
sentinel failover-timeout mymaster 15000  
sentinel auth-pass mymaster 15144

除端口号外,其他信息一样。

5.启动master、slave1、slave2、sentinel。

启动命令如下:

redis-server.exe redis6379.conf
redis-server.exe redis6380.conf
redis-server.exe redis6381.conf
redis-server.exe sentinel16379.conf --sentinel
redis-server.exe sentinel16380.conf --sentinel
redis-server.exe sentinel16381.conf --sentinel

启动成功界面如下:

master:

redis sentinel配置(windows环境)_第2张图片

slave1:

redis sentinel配置(windows环境)_第3张图片

slave2:与slave1基本相同

sentinel:

redis sentinel配置(windows环境)_第4张图片

5.查看redis服务器状态

master:

redis sentinel配置(windows环境)_第5张图片

slave1:

redis sentinel配置(windows环境)_第6张图片

slave2:与slave1基本相同

sentinel:

redis sentinel配置(windows环境)_第7张图片

6.测试

a.关闭master
b.查看其他服务器状态

redis sentinel配置(windows环境)_第8张图片
c.查看sentinel信息,master切换成功
redis sentinel配置(windows环境)_第9张图片

7.搭建过程中遇到的问题

a.第一次启动slave服务的时候,遇到如下问题:

redis sentinel配置(windows环境)_第10张图片

[7256] 06 Dec 11:38:05.158 * Background append only file rewriting started by pi
d 10344
[7256] 06 Dec 11:38:05.232 * AOF rewrite child asks to stop sending diffs.
[7256] 06 Dec 11:38:05.332 # fork operation complete
[7256] 06 Dec 11:38:05.332 * Background AOF rewrite terminated with success
[7256] 06 Dec 11:38:05.332 * Residual parent diff successfully flushed to the re
written AOF (0.00 MB)
[7256] 06 Dec 11:38:05.333 # Error trying to rename the existing AOF to old temp
file: Broken pipe
[7256] 06 Dec 11:38:05.433 * Background append only file rewriting started by pi
d 3284
[7256] 06 Dec 11:38:05.533 * AOF rewrite child asks to stop sending diffs.
[3284] 06 Dec 11:38:06.025 # Error moving temp append only file on the final des
tination: Input/output error
[3284] 06 Dec 11:38:06.025 # rewriteAppendOnlyFile failed in qfork: Input/output
 error
[7256] 06 Dec 11:38:06.033 # fork operation complete
[7256] 06 Dec 11:38:06.033 # Background AOF rewrite terminated with error
[7256] 06 Dec 11:38:06.133 * Background append only file rewriting started by pi
d 7728
[7256] 06 Dec 11:38:06.233 * AOF rewrite child asks to stop sending diffs.
[7728] 06 Dec 11:38:06.724 # Error moving temp append only file on the final des
tination: Input/output error
[7728] 06 Dec 11:38:06.724 # rewriteAppendOnlyFile failed in qfork: Input/output
 error
[7256] 06 Dec 11:38:06.733 # fork operation complete
[7256] 06 Dec 11:38:06.733 # Background AOF rewrite terminated with error 
    网上找了一些资料,自己尝试了一些方法,最后通过更改redis6379.conf、redis6380.conf、redis6381.conf三个配置文件中的 dir 配置项来解决,dir配置的文件地址不能一样。应该是master和slave的dir配置项如果一样的话,slave和master同步的时候异常了。


  b.启动sentinel服务后,查看sentinel信息,发现master status=sdown,slaves=0。

redis sentinel配置(windows环境)_第11张图片

    但是在master服务上显示两个slave已经连接成功了。

redis sentinel配置(windows环境)_第12张图片

    原因是因为master和slave设置了验证密码,但是sentinel的配置里面没有设置sentinel auth-pass mymaster 15144,在sentinel.conf里面添加一下就好了。

本人小白一枚,初写博客,如有不对的地方恳请各位大神批评指正。

你可能感兴趣的:(redis)