学习redis的途中,碰上了redis.conf,突发奇想,想着来进行一波翻译输出。
源码之前,了无秘密。
# 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 //redis.conf绝对路径
注意(单位制):当需要动态分配内存时,内存转换形式如下:
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
单位不区分大小写。
################################## 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 server 的标准配置模板,但针对某些 server 又需要一些个性化的设置。你可以使用 include 来包含一些其他的配置文件,这对你来说是非常有用的。
但是要注意哦,include 是不能被 config rewrite 命令改写的。由于 redis 总是以最后的加工线作为一个配置指令值,所以你最好把include 放在这个文件的最前面,以避免在运行时覆盖配置的改变,相反,你就把它放在后面。
################################## 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
在启动时加载模块。如果服务器无法加载模块,它就挂机了。
可以使用多个模块加载指令。
################################## 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
默认情况下,如果没有指定“绑定”配置指令,Redis监听服务器上所有可用网络接口的连接。
可以使用“bind”配置指令监听一个或多个选择的接口,后面跟着一个或多个IP地址。
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
~~~~~~~~ 警告~~~~~~~~
如果你的redis服务器直接暴露在公网上,允许任意接口绑定,这是很危险的,因为这将暴露实例给互联网上的每个人。
因此,默认情况下我们取消了以下bind指令的注释(默认bind127.0.0.1),这将迫使Redis只监听IPv4环回接口地址(这意味着Redis将只能接受来自运行在同一台计算机上的客户端的连接)。
如果你不知道哪儿来的迷之自信,那可以把下面那一行注释掉了。
保护模式是一层安全保护,用于避免Redis实例在互联网上开放被访问和利用。
当保护模式打开时,且
1) 服务器未显式绑定网络地址
2) 未设置密码
服务器只接受来自:IPv4和IPv6环回地址127.0.0.1和::1、以及Unix域套接字的客户端连接。
默认保护模式是启用的。只有当你确定你想要客户从其他主机连接到Redis,即使没有身份验证配置,也没有一个特定的接口设置明确列出使用“绑定”指令时,你应该禁用它。
默认端口号为6379。如果端口号被设置为0,则redis将不再保持TCP通信能力。
在高并发环境下,需要较高的缓冲机制来缓解客户端连接压力。
Linux内核将其写为/proc/sys/net/core/somaxconn的值(默认128),因此请确保提高somaxconn和tcp_max_syn_backlog的值,以获得预期的效果。
tcp-backlog 511
指定用于侦听传入连接的Unix套接字的路径方法如下。没有默认值,所以没有指定时,Redis不会监听unix套接字。
# unixsocket /tmp/redis.sock
# unixsocketperm 700
在客户端空闲N秒后关闭连接。
设置为0表示不使用该功能。
如果非零,则使用SO_KEEPALIVE在没有通信的情况下向客户端发送TCP ack。从以下两方面来看:
1)检测死亡同伴。
2)从中间网络设备的角度来看,让连接活起来。
在Linux上,指定的值(以秒为单位)是用于发送ack的周期。
注意,要关闭连接,需要双倍的时间。对于其他内核,周期取决于内核配置。
这个选项的合理值是300秒。
################################# GENERAL #####################################
# 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
# 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
# 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 liveness pings back to your supervisor.
supervised no
# If a pid file is specified, Redis writes it where specified at startup
# and removes it at exit.
#
# When the server runs non daemonized, no pid file is created if none is
# specified in the configuration. When the server is daemonized, the pid file
# is used even if not specified, defaulting to "/var/run/redis.pid".
#
# Creating a pid file is best effort: if Redis is not able to create it
# nothing bad happens, the server will start and run normally.
pidfile /var/run/redis_6379.pid
# 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
# 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 ""
# To enable logging to the system logger, just set 'syslog-enabled' to yes,
# and optionally update the other syslog parameters to suit your needs.
# syslog-enabled no
# Specify the syslog identity.
# syslog-ident redis
# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
# syslog-facility local0
# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT where
# dbid is a number between 0 and 'databases'-1
databases 16
# By default Redis shows an ASCII art logo only when started to log to the
# standard output and if the standard output is a TTY. Basically this means
# that normally a logo is displayed only in interactive sessions.
#
# However it is possible to force the pre-4.0 behavior and always show a
# ASCII art logo in startup logs by setting the following option to yes.
always-show-logo yes
默认情况下redis不是作为守护进程而运行的。如果需要的话,请选择“yes”。
注意,当监控pid时,Redis将在/var/run/ redisin中写入一个pid文件。
可以通过upstart 或 systemd管理守护进程。
如果pid文件被指定,Redis在启动时写入指定的位置,在退出时删除它。
当服务器运行非守护进程时,如果配置中没有指定pid文件,则不会创建任何pid文件。当服务器被守护化时,即使没有指定pid文件也会被使用,默认为“/var/run/redis.pid”。
创建一个pid文件是最好的尝试:如果Redis不能创建它,也不会有什么不好的事情发生,服务器依旧启动和正常运行。
指定服务器的消息级别
调试(大量信息,对开发/测试很有用)
冗长(许多很少有用的信息,但不像调试级别那样混乱)
注意(可能比较冗长,您在生产环境中需要什么)
警告(只有非常重要/关键的消息被记录)
指定日志文件名。
空字符串也可以用来强制Redis将日志消息输出到标准输出。注意,如果使用daemonize以外的标准输出进行日志记录,那么日志将被发送到/dev/null。
要启用到系统日志记录器的日志记录,只需将“syslog-enabled”设置为yes,并可选地更新其他syslog参数以满足您的需要。
指定syslog工具。必须是用户或介于LOCAL0-LOCAL7之间。
设置数据库的数量。
默认数据库是DB 0,您可以使用select dbid 在每个连接的基础上选择一个不同的数据库,其中dbid是一个处于 0 和 ‘databases’-1 之间的数字。
默认情况下,只有当日志开始输出到标准输出并且标准输出是TTY时,Redis才会显示一个ASCII艺术徽标。基本上,这意味着一个徽标通常只在交互会话中显示。
但是,通过将以下选项设置为yes,可以强制执行4.0之前的行为,并始终在启动日志中显示ASCII艺术徽标。
哇,累,粉丝可见吧,累死我了。。
下一篇:redis.conf 翻译与配置(二)【redis6.0.6】