redis配置文件参数讲解

redis配置文件参数讲解

1.文件大小

1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes

2 网络

## 监听两个特定的ipv4地址
#bind 192.168.1.100 10.0.0.1     # listens on two specific IPv4 addresses
## 环回监听ipv4 和 ipv6
# bind 127.0.0.1 ::1              # listens on loopback IPv4 and IPv6
## redis的默认配置
bind 127.0.0.1 ::1
## 是否受保护的模式
protected-mode yes
## 端口号
port 6379
## tcp 发送acks 保活的时间
tcp-keepalive 300

3.TLS/SSL

## 默认TLS/SSL 是禁用的,为了去使用它,就需要配置tls-port,就像
port 0
tls-port 6379 
# By default, TLS/SSL is disabled. To enable it, the "tls-port" configuration
# directive can be used to define TLS-listening ports. To enable TLS on the
# default port, use:
#
# port 0
# tls-port 6379

#配置一个X.509证书和私钥,用于验证
#服务器连接到已连接的客户端、主服务器或集群对等体。这些文件应该是
# PEM格式。
# Configure a X.509 certificate and private key to use for authenticating the
# server to connected clients, masters or cluster peers.  These files should be
# PEM formatted.
#
# tls-cert-file redis.crt
# tls-key-file redis.key

4 SNAPSHOTTING 即redis aof的一些配置

首先我看这段翻译 保存DB到磁盘
保存的格式为 SAVE <时间(以秒单位)>  < redis 时间内key的改变量>
# Save the DB to disk.
#
# save <seconds> <changes>
#
# Redis will save the DB if both the given number of seconds and the given
# number of write operations against the DB occurred.
#
快照可以完全禁用 用一个空的String 参数 
示例如下
save “”
# Snapshotting can be completely disabled with a single empty string argument
# as in following example:
#
# save ""
这个是redis 推荐的配置 默认就用这个就行
# save 3600 1
# save 300 100
# save 60 10000
rdbcompression yes   (启动rdb文件压缩,耗费CPU资源,默认为yes)

rdbchecksum yes        (对rdb数据进行校验,耗费CPU资源,默认为yes)
## DB的文件名 dump.rdb
dbfilename dump.rdb

5.主从复制

## 配置masterip 和maser的端口
slaveof <masterip> <masterport>
## 如果主机有密码 则需要配置主机的密码
masterauth <master-password>
#这是 replicas 节点通过 INFO 接口给出的信息,默认值为 100。 当 master 节点无法正常工作后 Redis Sentinel 通过这个值来决定将哪个 replicas 节点提升为 master 节点。

这个数值越小表示越优先进行提升。如有三个 replicas 节点其 priority 值分别为 10,100,25, Sentinel 会选择 priority 为 10 的节点进行提升。

这个值为 0 表示 replica 节点永远不能被提升为 master 节点。
slave-priority 100
## redis可以配置在主从配置里面,不安全的情况下,主机拒绝写入的策略。
min-slaves-to-write 3
min-slaves-max-lag 10
上面的配置表示:从服务器的数量少于3个,或者三个从服务器的延迟(lag)值都大于或等于10秒时,主服务器将拒绝执行写命令。这里的延迟值就是上面INFO replication命令的lag值。

6.KEYS TRACKING 键跟踪

最大跟踪数
# tracking-table-max-keys 1000000

7.SECURITY 安全配置

##密码配置
# requirepass foobared

8.CLIENTS 客户端

## 最大客户端连接数为 10000
# maxclients 10000

9.MEMORY MANAGEMENT 内存管理 LRU 和 LFU的一些配置 后面写

在这里插入代码片

10.THREADED I/O threaded I/O

默认线程是禁用的,redis建议至少我们的机器有4核,至少留下一个备用核
# By default threading is disabled, we suggest enabling it only in machines
# that have at least 4 or more cores, leaving at least one spare core.
# Using more than 8 threads is unlikely to help much. We also recommend using
# threaded I/O only if you actually have performance problems, with Redis
# instances being able to use a quite big percentage of CPU time, otherwise
# there is no point in using this feature.
## 如果你有4核,需要用到两核和三核 就使用下面的配置
# io-threads 4

11 APPEND ONLY MODE redis 持久策略AOF的配置

## 默认是关闭的
appendonly no
## 追从添加的文件的名字
appendfilename "appendonly.aof"
## 总是同步添加
# appendfsync always
## 每一秒进行一个同步添加 可能损失一秒的数据
appendfsync everysec
如果设置为no,则write后不会有fsync调用,由操作系统自动调度刷磁盘,性能是最好的。那就还不如用rdb
# appendfsync no
## 如果开成是yes 就和appendfsync no 差不多一个意思
no-appendfsync-on-rewrite no
#指定Redis重写aof文件的条件,默认为100,表示与上次rewrite的aof文件大小相比,当前aof文件增长#量超过上次afo文件大小的100%时,就会触发background rewrite。
#若配置为0,则会禁用自动rewrite
auto-aof-rewrite-percentage 100

#指定触发rewrite的aof文件大小。若aof文件小于该值,即使当前文件的增量比例达到auto-aof-#rewrite-percentage的配置值,也不会触发自动rewrite。
#即这两个配置项同时满足时,才会触发rewrite。
auto-aof-rewrite-min-size 64mb
表示是否开启混合持久化
如果开启了混合持久化,aof在重写时,不再是单纯将内存数据转换为RESP命令写入aof文件,而是将重写这一刻之前的内存做rdb快照处理,并且将rdb快照内容和增量的aof修改内存数据的命令存在一起,都写入新的aof文件,新的aof文件一开始不叫appendonly.aof,等到重写完成后,新的aof文件才会进行改名,原子的覆盖原有的aof文件,完成新旧两个aof文件的替换。
于是在redis重启的时候,可以先加载rdb文件,然后再重放增量的aof日志就可以完全替代之前的aof全量文件重放,因此重启效率大幅得到提高。
aof-use-rdb-preamble yes
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值