Cachecloud中Redis的相关配置

一、Redis配置在哪?

CacheCloud将Redis配置定义成枚举类(考虑到对于Java不太了解的朋友,后期会定义成可配置的模板)。

  1. Redis普通节点配置:普通的数据节点配置

    1
    cachecloud-open-web\src\main\java\com\sohu\cache\redis\enums\RedisConfigEnum.java
  2. Redis Sentinel节点配置: Sentinel节点自身的特殊配置

    1
    cachecloud-open-web\src\main\java\com\sohu\cache\redis\enums\RedisSentinelConfigEnum
  3. Redis Cluster节点配置: 在Redis普通节点上添加了一些关于Redis Cluster的配置

    1
    cachecloud-open-web\src\main\java\com\sohu\cache\redis\enums\RedisClusterConfigEnum

二、配置”优化”

1
2
Cachecloud Release1.0 1.1 master
Redis 3.0.7

我们以Redis3.0.7为例子,http://download.redis.io/releases/redis-3.0.7.tar.gz

1. Redis普通节点与标准配置的不同

解压后默认配置是redis.conf文件(去掉注释和空行):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
daemonize no
pidfile /var/run/redis.pid
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 ./
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
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-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-entries 512
list-max-ziplist-value 64
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

对比:

序号 配置名 标准 cachecloud 说明
1 pidfile /var/run/redis.pid none none
2 port 6379 自定义端口 单机多实例
3 三个save 900,300,60 none 不使用自动rdb
4 stop-writes-on-bgsave-error yes none 默认是yes,这个值应该设置成no比较好(cachecloud后期版本会进行修改)
5 rdbcompression yes none 默认就是yes
6 rdbchecksum yes none 默认就是yes
7 dbfilename dump.rdb dump-${端口号}.rdb 单机多实例
8 dir 当前目录 /opt/cachecloud/data 不要当前路径
9 repl-diskless-sync no none 默认就是no
10 repl-diskless-sync-delay 5 none 默认就是5
11 appendonly no yes 开启aof
12 appendfilename appendonly.aof appendonly-${端口号}.aof 单机多实例
13 no-appendfsync-on-rewrite no yes 防止aof重写期间,可能造成aof阻塞,从而阻塞主线程的可能
14 auto-aof-rewrite-percentage 100 做了随机化70~99 none
15 aof-load-truncated yes none 默认是yes
16 latency-monitor-threshold 0 none 默认值是0
17 notify-keyspace-events “” none 默认值是空
18 client-output-buffer-limit slave 256mb 64mb 60 512mb 128mb 60 增大slave client的输出缓冲
19 repl-timeout # repl-timeout 60 60 就是默认值
20 repl-ping-slave-period # repl-ping-slave-period 10 10 就是默认值
21 repl-backlog-size # repl-backlog-size 1mb 10mb 增大复制缓冲区,减少因主从网络不正常,造成频繁全量复制可能
22 repl-backlog-ttl # repl-backlog-ttl 3600 3600 就是默认值
23 maxmemory 0(没有限制最大内存) 自定义 maxmemory一定要设置(建议小分片)
24 maxmemory-policy # maxmemory-policy noeviction volatile-lru 在过期的key中使用lru

这些配置只是建议配置,例如关系到Redis安全可以配置requirepass,rename-command,bind,masterauth等等。要根据自己公司的需求进行配置。

2. Redis Sentinel节点与标准配置的不同

解压后默认配置是sentinel.conf文件(去掉注释和空行):

1
2
3
4
5
6
port 26379
dir /tmp
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000

对比:

序号 配置名 标准 cachecloud 说明
1 port 6379 自定义端口 单机多实例
2 sentinel monitor mymaster 127.0.0.1 6379 2 ip port 1 应该设置为2,cachecloud在公司内部用了三个sentinel
3 sentinel down-after-milliseconds 30000 20000 降低主观判定的时间

有关于sentinel的配置基本和官方配置是一致的,dir应该修改一下

3. Redis Cluster节点与标准配置的不同

解压后默认配置是redis.conf文件(去掉注释和空行),在redis.conf中所有和cluster相关的配置都是注释掉的,也就是使用了默认的配置

对比:

序号 配置名 标准 cachecloud 说明
1 cluster-enabled no yes 开启cluster模式
2 cluster-node-timeout 15000 15000 这个参数很重要
3 cluster-slave-validity-factor 10 10 none
4 cluster-migration-barrier 1 1 none
5 cluster-config-file nodes-6379.conf nodes-${端口}.conf 单机多实例
6 cluster-require-full-coverage yes no 节点部分失败期间,其他节点是否继续工作

有关于cluster的配置比较重要的是cluster-node-timeout、cluster-require-full-coverage

三、总结

Cachecloud给出的Redis配置已经在公司内使用,具有一定的普适性,但是还是需要根据具体的应用场景进行调优配置(可以利用配置修改申请对具体应用的配置进行优化。)

未来的改进:

  • Redis 3.2新增了很多可以config set的配置。
  • Cachecloud的配置模板化,不是写在java代码里。