Redis (3) Common configuration analysis


提示:Redis 6.2.6版本

Unit of measure

注意:g和gb有区别,不区分大小写,1gb 1GB都是一样的。

insert image description here

Introduce other configuration files

包含一个或多个其他配置文件。
根据从上到下的顺序,读取配置项,对同一个配置项多次设置,总是取最后配置的值

insert image description here

Load modules on startup

启动时加载模块。如果服务器无法加载模块,它将中止。可以使用多个loadmodule指令。
模块是redis4.0以上版本新增的特性,可以编写自己的扩展模块,加载进redis。

insert image description here

Network configuration

  • bind
    insert image description here

  • bind-source-addr

    Use "bind-source-addr" to configure a specific address to bind to, which also affects the routing of the connection.
    insert image description here

  • protected-mode
    protection mode: When the protection mode is turned on and the default user has no password, it can only receive local access to the machine
    insert image description here

  • port
    insert image description here

  • tcp-backlog
    sets the TCP backlog. The total backlog queue = the uncompleted three-way handshake queue + the completed three-way handshake queue.
    In a high-concurrency environment, a high backlog value is needed to avoid the problem of slow client connections.
    insert image description here

  • timeout
    : How many seconds does an idle client last before it is shut down? 0 means turning off this function.
    insert image description here

  • tcp-keepalive
    In the Linux system, the time interval between the last data packet sent by the client and the first keep-alive probe message sent by redis. The unit is seconds.
    insert image description here

GENERAL General configuration

  • Whether daemonize is a background process (default is no)
    insert image description here- pidfile stores the location of the pid file, each instance will generate a different pid file
    insert image description here

  • loglevel log level

     debug:能设置的最高的日志级别,打印所有信息,包括debug信息。
     verbose:打印除了debug日志之外的所有日志。
     notice:打印除了debug和verbose级别的所有日志。
     warning:仅打印非常重要的信息。
    

insert image description here

  • logfile sets the file output path of the log
    insert image description here

  • databases default 16 databases
    insert image description here

  • save

    由于Redis是基于内存的数据库,需要将数据由内存持久化到文件中:
     save  3600  1           意义:3600秒(一个小时),至少一次改变
           300   100               300秒(5分钟),至少100次改变
           60   10000              60秒。至少10000次改变
    

insert image description here

  • stop-writes-on-bgsave-error Persistence error whether to continue to work
    insert image description here
    -rdb file
    insert image description hereinsert image description here

REPLICATION Master-slave replication related configurations

################################# REPLICATION #################################

# Master-Replica replication. Use replicaof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
#   +------------------+      +---------------+
#   |      Master      | ---> |    Replica    |
#   | (receive writes) |      |  (exact copy) |
#   +------------------+      +---------------+
#修改master主机的地址和ip
# replicaof <masterip> <masterport>
#配置从库连接主库master的密码
# masterauth <master-password>
# 当指定 "masteruser" 时,副本将使用新的 AUTH 形式对其主节点进行
# 认证: AUTH <username> <password>.
#在 6.0 以上版本,如果使用了 ACL 安全功能,只配置 masterauth 还不够。因为默认用户不能运行 #PSYNC 命令或者主从复制所需要的其他命令。这时候,最好配置一个专门用于主从复制的特殊用户
# masteruser <username>
#当 slave 节点与 master 失去连接,导致主从同步失败的时候 
#yes,slave 节点可以继续处理客户端请求,但是数据可能是旧的
replica-serve-stale-data yes
# Since Redis 2.6 by default replicas are read-only.
#配置用于控制 slave 实例能否接收写指令,
#在 2.6 版本后默认配置为 yes,表示 slave 节点只处理读请求,如果为 no 则可读可写。
replica-read-only yes
#SYNC服务器对主服务的同步策略
# Replication SYNC strategy: disk or socket.
# 1) Disk-backed: The Redis master creates a new process that writes the RDB
#                 file on disk. Later the file is transferred by the parent
#                 process to the replicas incrementally.
# 2) Diskless: The Redis master creates a new process that directly writes the
#              RDB file to replica sockets, without touching the disk at all.
#
repl-diskless-sync yes

#当启用diskless复制时,可以配置服务器等待的时间
repl-diskless-sync-delay 5
#如果是diskless传输,如果预期的最大副本数已连接,则可以在最大延时之前进行复制
#默认值为 0,意味着没有定义最大值,Redis 将等待整个延迟。
repl-diskless-sync-max-replicas 0

#RDB文件落在Slave磁盘上模式,通常情况下磁盘比网络慢,存储和加载RDB文件会增加复制时间,也会增加Master的复制写内存和Slave的缓冲区
# 无硬盘模式是测试阶段,因为直接从socket获取rdb数据会有一个问题,那就是需要拿到完整的rdb数据才可以进行同步,针对这个问题以下由几种方案
#disable   不使用 无硬盘方案
#on-empty-db 只有在完全安全才使用无硬盘
#swapdb 在解析socket的rdb数据时,将当前数据库的数据放到内存中,这样可以在复制的时候为客户端提供服务,但是可能会造成内存溢出
repl-diskless-load disabled
# 主站以预定的时间间隔向其副本发送 PING。可以用 repl_ping_replica_period 选项来改变这个时间间隔。
# 默认值是10秒
# repl-ping-replica-period 10
#超时时间
# repl-timeout 60
#延时通信
#no: 不禁用,Master的指令无论大小都及时发送给Slave,但是会增加网络带宽,合适主从网络环境良好的场景
#yes: 禁用,主从链接都是TCP链接,所以当网络环境一般的情况下,交给Linux内核对TCP数据包进行优化,也就是合并较小的TCP数据包从而节省带宽,默认发送时间间隔取决于Linux内核,一般40毫秒,适合跨机房部署的场景
repl-disable-tcp-nodelay no

# repl-backlog-size 1mb
# repl-backlog-ttl 3600

# 复制的优先级是一个整数,由 Redis 在 INFO 输出中公布。它被 Redis Sentinel 用来选择一个副本,
# 以便在主副本不再正常工作时将其提升为主副本。
#0 是一个特殊的优先级,Sentinel不会选择数值为0的Slave为Master
#Sentinel会优先选择数值低的Slave提升为Master
replica-priority 100

# propagation-error-behavior ignore
# replica-ignore-disk-write-errors no
# replica-announced yes


# min-replicas-to-write 3
# min-replicas-max-lag 10

# replica-announce-ip 5.5.5.5
# replica-announce-port 1234

security configuration

  • View, set and cancel access passwords.
    At the requirepass foobared location, add a line below requirepass + the password you want to set (note that there is no space in front). You
    insert image description here
    can also change the password through the command line.
    The password modified by this method is a temporary password. It will become invalid after redis is closed and will be started next time. Need to set again
    insert image description here
  • maxclients sets how many clients redis can connect to at the same time
    . If this limit is reached, redis will reject new connection requests and respond with "max number of clients reached" to these connection requesters.
    insert image description here
  • maxmemory sets the amount of memory that redis can use.
    Once the upper limit of memory usage is reached, redis will try to remove internal data, and the removal rules can be specified by MAXMEMORY POLICY
    insert image description here

AOF configuration

appendonly no# 默认是不开启aof模式的,默认是使用rdb方式持久化的
appendfilename "appendonly.aof"指定aof文件名称
appenddirname "appendonlydir"指定aof文件的存储路径
# appendfsync always # 每次修改都会sync 消耗性能
appendfsync everysec# 每秒执行一次 sync 可能会丢失这一秒的数据
# appendfsync no# 不执行 sync ,这时候操作系统自己同步数据,速度最快

Guess you like

Origin blog.csdn.net/qq_45637894/article/details/126722579