前言
在redis配置文件里修改一些配置的时候,总会看到一些对配置的解释,每次读到都感觉很有收获,甚至感觉比网上的很多资料都要好,因此下决心自己完整翻译并整理一份。
翻译及介绍
part1 初始介绍
- 原文:
# 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
# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
#
# units are case insensitive so 1GB 1Gb 1gB are all the same.
- 译文
Redis配置文件示例.为了能读取到配置文件,注意Redis服务必须以配置文件的路径作为第一个参数启动
./redis-server /path/to/redis.conf关于单位,当你需要指定内存的大小时,可以使用如下的单位来指定
1k => 1000 bytes
1kb => 1024 bytes
1m => 1000000 bytes
1mb => 1024*1024 bytes
1g => 1000000000 bytes
1gb => 102410241024 bytes单位是大小写不敏感的 所以 1GB 1Gb 1gB 都是一样的
part2 INCLUDES
- 原文
# Include one or more other config files here. This is useful if you
# have a standard template that goes to all Redis servers but also need
# to customize a few per-server settings. Include files can include
# other files, so use this wisely.
#
# Notice option "include" won't be rewritten by command "CONFIG REWRITE"
# from admin or Redis Sentinel. Since Redis always uses the last processed
# line as value of a configuration directive, you'd better put includes
# at the beginning of this file to avoid overwriting config change at runtime.
#
# If instead you are interested in using includes to override configuration
# options, it is better to use include as the last line.
#
# include /path/to/local.conf
# include /path/to/other.conf
- 译文
在这里包含一个或多个配置文件。如果您有一个适用于所有Redis服务器的标准模板,但是还需要自定义每个服务器的一些设置,那么这是非常有用的。引入文件可以包含其他的文件,所以用这种方式是很明智的。
注意选项“include”不会被来自admin或Redis哨兵的命令“CONFIG REWRITE”重写。因为Redis总是使用最后一次处理作为配置指令的值,
所以您最好在此文件的开头放入include,以避免在运行时覆盖配置更改。但反过来如果您感兴趣的是使用include覆盖配置,最好把include配置放在文件的最后。
include /path/to/local.conf
include /path/to/other.conf
part3 MODULES
- 原文
# Load modules at startup. If the server is not able to load modules
# it will abort. It is possible to use multiple loadmodule directives.
#
# loadmodule /path/to/my_module.so
# loadmodule /path/to/other_module.so
- 译文
在启动时加载模块。如果服务无法加载模块它将中止。可以使用多个loadmodule模块加载指令。loadmodule /path/to/my_module.so
loadmodule /path/to/other_module.so
part4 NETWORK
- 原文
# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# 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
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1
# 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
# 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
# TCP listen() backlog.
#
# In high requests-per-second environments you need an high backlog in order
# to avoid slow clients connections issues. Note that the Linux kernel
# will silently truncate it to the value of /proc/sys/net/core/somaxconn so
# make sure to raise both the value of somaxconn and tcp_max_syn_backlog
# in order to get the desired effect.
tcp-backlog 511
# 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)
timeout 0
# TCP keepalive.
#
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
#
# 1) Detect dead peers.
# 2) Take the connection alive from the point of view of network
# equipment in the middle.
#
# On Linux, the specified value (in seconds) is the period used to send ACKs.
# Note that to close the connection the double of the time is needed.
# On other kernels the period depends on the kernel configuration.
#
# A reasonable value for this option is 300 seconds, which is the new
# Redis default starting with Redis 3.2.1.
tcp-keepalive 300
- 译文
默认情况下,如果没有指定“bind”配置指令,则Redis侦听服务器上所有可用网络接口的连接。可以使用“bind”配置指令监听一个或多个选定的接口,然后监听一个或多个IP地址。
例如:
bind 192.168.1.100 10.0.0.1
bind 127.0.0.1 ::1警告:如果运行Redis的计算机直接暴露在internet上,绑定到所有接口是危险的,会将实例暴露给internet上的每个人。因此,在默认情况下,我们取消对以下bind指令的注释,这将迫使Redis只监听IPv4环回接口地址(这意味着Redis将只能接受来自运行在同一台计算机上的客户端的连接)。
如果您确定希望实例侦听所有接口只需注释下面的行。
bind 127.0.0.1protected-mode是一种安全保护层,为了避免在internet上打开的Redis实例被访问和利用。
当保护模式打开时,如果:
1)服务器没有使用“绑定”指令显式绑定到一组地址。
2)未设置密码。服务器只接受来自IPv4和IPv6环回地址127.0.0.1和::1的客户端连接,以及来自Unix域套接字的连接。
默认情况下启用了受保护模式。只有在您确定希望其他主机的客户端连接到Redis(即使没有配置任何身份验证),或者使用“bind”指令显式列出一组特定的接口时,才应该禁用它。
protected-mode yes接受指定端口上的连接,默认是6379 (IANA #815344)。如果端口0被指定,Redis将不会监听TCP套接字。
port 6379TCP监听 backlog 。
在每秒请求数很高的环境中,您需要一个高的backlog,以避免缓慢的客户端连接问题。请注意,Linux内核将静默地将其截断为/proc/sys/net/core/somaxconn的值,因此请确保同时提高somaxconn和tcp_max_syn_backlog的值,以获得所需的效果。
tcp-backlog 511Unix 套接字。
为Unix套接字指定用于监听传入连接的路径。没有默认值,所以在未指定时,Redis不会监听unix套接字。
unixsocket / tmp / redis.sock
unixsocketperm 700在客户端空闲N秒后关闭连接(0表示禁用)
timeout 0TCP keepalive.
如果该值不为0,将使用 SO_KEEPALIVE 这一默认的做法来向客户端连接发送TCP ACKs
这样的好处有以下两个原因
1)检测已经死亡的对端
2)保持连接在网络环境中的存活在Linux上,指定的值(以秒为单位)是用于发送ack的周期。
注意,关闭连接需要双倍的时间。
对于其他内核,周期取决于内核配置。此选项的合理值是300秒,即从Redis 3.2.1开始的新Redis默认值。
tcp-keepalive 300
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。