redis最原始版redis.conf配置文件关键信息详细说明


redis的最原始版redis.conf配置文件关键信息详细说明

1.位置在redis解压包的目录下的redis.conf文件

下载redis包:官网地址:https://redis.io/
在这里插入图片描述

2.头文件说明

原始文档:主要是说明一下redis启动方式,参数说明

# Redis configuration file example.
#
# Note that in order to read the configuration file, Redis must be
# started with the file path as first argument:
#
# ./redis-server /path/to/redis.conf

### 1)启动方式
注意,为了读取配置文件,Redis必须是以文件路径作为第一个参数开头

#样例:
./redis-server /path/to/redis.conf

3.NETWORK 网络配置

1)bind 绑定

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all available network interfaces on the host machine.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1

默认情况下,如果未指定“ bind”配置指令,则Redis侦听用于来自主机上所有可用网络接口的连接。使用以下命令可以仅收听一个或多个选定的接口
简单理解:bind是绑定本机的ip地址,不是redis允许其他连接计算机的IP
例如本机有两个网卡,192.168.56.111,和192.168.56.112,如果bind配置是192.168.56.111,就只能通过192.168.56.111来连接redis服务
例子:

# 这意味着Redis将接受来网卡192.168.1.100和10.0.0.1来连接服务
# bind 192.168.1.100 10.0.0.1
# 默认情况下,我们取消注释遵循bind指令,这将强制Redis仅在IPv4环回接口地址(这意味着Redis将只能接受来自运行该主机的同一主机的客户端连接)
bind 127.0.0.1
# 开放所有网卡
bind 0.0.0.0

2)protected-mode 保护模式

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode yes

是否允许远程客户端连接,yes是不允许,no是开放,默认值:protected-mode yes

3)port 端口

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379

接受指定端口上的连接,默认为6379。如果指定了端口0,则Redis将不会在TCP套接字上侦听。#默认值:port 6379

4)timeout 超时设置

# Unix socket.
#
# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
# unixsocket /tmp/redis.sock
# unixsocketperm 700

# Close the connection after a client is idle for N seconds (0 to disable)
# 客户端闲置N秒后关闭连接(0禁用,就是永不过时)
timeout 0

4.GENERAL 一般设置

1)daemonize 后台运行

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no

daemonize默认是不开启,一般运行都是把它改成yes,在后台运行redis
注意,如果是docker容器运行redis,daemonize要改成no,docker -d的后台运行和redis的后台运行冲突了,导致redis容器启动不了

2)supervised 守护进程

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#                        requires "expect stop" in your upstart job config
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous pings back to your supervisor.
supervised no
# 如果指定了pid文件,则Redis会在启动时将其写入指定位置
pidfile /var/run/redis_6379.pid

说明:

  • supervised no - 无监督互动
  • supervised upstart - 通过将Redis置于SIGSTOP模式来启动信息
  • supervised systemd - 通过将READY = 1写入$ NOTIFY_SOCKET来发出信号systemd
  • supervised auto - 检测upstart or systemd根据UPSTART_JOB或NOTIFY_SOCKET环境变量

2)loglevel 日志等级

# Specify the server verbosity level.
# This can be one of:
# debug (a lot of information, useful for development/testing)调试(很多信息,对于开发/测试很有用)
# verbose (many rarely useful info, but not a mess like the debug level)详细(很多很少有用的信息,但不会像调试级别那样混乱)
# notice (moderately verbose, what you want in production probably)通知(适度冗长,可能是您想要的产品)
# warning (only very important / critical messages are logged)警告(仅记录非常重要/重要的消息)

loglevel notice

3)logfile 日志生成路径

# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile ""

4)databases 数据库数量

# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1
databases 16

5.SNAPSHOTTING 快照

1)触发机制:

# Save the DB on disk:
#
#   save <seconds> <changes>
#
#   Will save the DB if both the given number of seconds and the given
#   number of write operations against the DB occurred.
#
#   In the example below the behavior will be to save:
#   after 900 sec (15 min) if at least 1 key changed
#   after 300 sec (5 min) if at least 10 keys changed
#   after 60 sec if at least 10000 keys changed
#
#   Note: you can disable saving completely by commenting out all "save" lines.
#
#   It is also possible to remove all the previously configured save
#   points by adding a save directive with a single empty string argument
#   like in the following example:
#
#   save ""
save 900 1
save 300 10
save 60 10000

规则:

  • 在900秒(15分钟)后,如果至少更改了1个键
  • 300秒(5分钟)后,如果至少更改了10个按键
  • 60秒后,如果至少更改了10000个键

2)快照文件名称

# The filename where to dump the DB
dbfilename dump.rdb

文件生产触发机制:

  • save的规则满足的情况下,会自动触发rdb规则,生成rdb文件
  • 执行flushall命令,会自动触发rdb规则,生成rdb文件
  • 退出redis,生成rdb文件

3)快照文件路径

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir ./

6.REPLICATION 复制(主从部署配置)

1)主机配置

# 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) |
#   +------------------+      +---------------+
#
# 1) Redis replication is asynchronous, but you can configure a master to
#    stop accepting writes if it appears to be not connected with at least
#    a given number of replicas.
# 2) Redis replicas are able to perform a partial resynchronization with the
#    master if the replication link is lost for a relatively small amount of
#    time. You may want to configure the replication backlog size (see the next
#    sections of this file) with a sensible value depending on your needs.
# 3) Replication is automatic and does not need user intervention. After a
#    network partition replicas automatically try to reconnect to masters
#    and resynchronize with them.
#
replicaof <masterip> <masterport>
masterauth <master-password>
masteruser <username>
replica-serve-stale-data yes
replica-read-only yes
  • 配置:replicaof <主机IP> <主机端口>注意:redis每个启动实例都是认为自己是master,当配置了这个之后,这台服务就是从机
  • 配置:masterauth <主机密码>
  • 配置:replica-serve-stale-data复制服务过时数据 <yes/no>
  • 配置:replica-read-only从机只读 <yes/no>

7.SECURITY 安全

1)认证密码设置

# IMPORTANT NOTE: starting with Redis 6 "requirepass" is just a compatibility
# layer on top of the new ACL system. The option effect will be just setting
# the password for the default user. Clients will still authenticate using
# AUTH <password> as usually, or more explicitly with AUTH default <password>
# if they follow the new protocol: both will work.
#
requirepass 123456

8.CLIENTS 客户端

1) 客户端连接数设置

# Set the max number of connected clients at the same time. By default
# this limit is set to 10000 clients, however if the Redis server is not
# able to configure the process file limit to allow for the specified limit
# the max number of allowed clients is set to the current file limit
# minus 32 (as Redis reserves a few file descriptors for internal uses).
#
# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.
#
# IMPORTANT: When Redis Cluster is used, the max number of connections is also
# shared with the cluster bus: every node in the cluster will use two
# connections, one incoming and another outgoing. It is important to size the
# limit accordingly in case of very large clusters.
#
maxclients 10000

重要提示:使用Redis群集时,最大连接数也是与集群总线共享:集群中的每个节点将使用两个连接,一个传入,另一个传出。重要的是如果群集很大,则相应地限制。

9.MEMORY MANAGEMENT 内存管理

1)缓存内存设置


# Set a memory usage limit to the specified amount of bytes.
# When the memory limit is reached Redis will try to remove keys
# according to the eviction policy selected (see maxmemory-policy).
# maxmemory <bytes>
maxmemory 1Gb

设置内存使用限制为指定的字节数。当达到内存限制时,Redis将尝试删除密钥,根据选择的驱逐策略(请参阅maxmemory-policy)。

2)内存超出设置的驱逐策略

# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select one from the following behaviors:
#
# volatile-lru -> Evict using approximated LRU, only keys with an expire set.
# allkeys-lru -> Evict any key using approximated LRU.
# volatile-lfu -> Evict using approximated LFU, only keys with an expire set.
# allkeys-lfu -> Evict any key using approximated LFU.
# volatile-random -> Remove a random key having an expire set.
# allkeys-random -> Remove a random key, any key.
# volatile-ttl -> Remove the key with the nearest expire time (minor TTL)
# noeviction -> Don't evict anything, just return an error on write operations.
#
# LRU means Least Recently Used
# LFU means Least Frequently Used
#
# Both LRU, LFU and volatile-ttl are implemented using approximated
# randomized algorithms.
#
# Note: with any of the above policies, Redis will return an error on write
#       operations, when there are no suitable keys for eviction.
#
#       At the date of writing these commands are: set setnx setex append
#       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
#       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
#       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
#       getset mset msetnx exec sort
#
# The default is:
#
maxmemory-policy noeviction

驱逐策略:

  • volatile-lru->使用近似的LRU驱逐,只有具有过期集的密钥。
  • allkeys-lru->使用近似的LRU退出任何密??钥。
  • volatile-lfu->使用近似的LFU驱逐,只有具有过期集的键。
  • allkeys-lfu->使用近似的LFU退出任何密??钥。
  • volatile-random->删除具有过期集的随机密钥。
  • allkeys-random->删除随机密钥,任何密钥。
  • volatile-ttl->删除最接近到期??时间(较小的TTL)的密钥
  • noeviction->不要逐出任何东西,只需在写操作中返回错误。

10.APPEND ONLY MODE 追加模式(开启AOF)

1)开启AOF

# By default Redis asynchronously dumps the dataset on disk. This mode is
# good enough in many applications, but an issue with the Redis process or
# a power outage may result into a few minutes of writes lost (depending on
# the configured save points).
#
# The Append Only File is an alternative persistence mode that provides
# much better durability. For instance using the default data fsync policy
# (see later in the config file) Redis can lose just one second of writes in a
# dramatic event like a server power outage, or a single write if something
# wrong with the Redis process itself happens, but the operating system is
# still running correctly.
#
# AOF and RDB persistence can be enabled at the same time without problems.
# If the AOF is enabled on startup Redis will load the AOF, that is the file
# with the better durability guarantees.
#
# Please check http://redis.io/topics/persistence for more information.

appendonly no

默认情况下,Redis异步将数据集转储到磁盘上。此模式是在许多应用程序中都足够好,但是Redis进程或停电可能会导致几分钟的写入丢失(取决于配置的保存点,就是快照保存规则)。
仅附加文件是一种替代的持久性模式,可提供更好的耐久性。例如使用默认数据fsync策略,Redis可能仅丢失一秒钟的写操作。

2)AOF文件名称

# The name of the append only file (default: "appendonly.aof")

appendfilename "appendonly.aof"

3)AOF写入规则配置

# The fsync() call tells the Operating System to actually write data on disk
# instead of waiting for more data in the output buffer. Some OS will really flush
# data on disk, some other OS will just try to do it ASAP.
#
# Redis supports three different modes:
#
# no: don't fsync, just let the OS flush the data when it wants. Faster.
# always: fsync after every write to the append only log. Slow, Safest.
# everysec: fsync only one time every second. Compromise.
#
# The default is "everysec", as that's usually the right compromise between
# speed and data safety. It's up to you to understand if you can relax this to
# "no" that will let the operating system flush the output buffer when
# it wants, for better performances (but if you can live with the idea of
# some data loss consider the default persistence mode that's snapshotting),
# or on the contrary, use "always" that's very slow but a bit safer than
# everysec.
#
# More details please check the following article:
# http://antirez.com/post/redis-persistence-demystified.html
#
# If unsure, use "everysec".

# appendfsync always
appendfsync everysec
# appendfsync no
  • appendfsync always 每次仅写入追加日志后的fsync,特性:慢,最安全。
  • appendfsync everysec 每秒仅同步一次fsync。特性:稳定,完整。
  • appendfsync no 不要fsync,只要让OS在需要时刷新数据即可,特性:快
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

binggoling

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值