美文网首页
REDIS----配置文件----NETWORK

REDIS----配置文件----NETWORK

作者: JuMinggniMuJ | 来源:发表于2020-05-31 13:25 被阅读0次

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.

默认情况下,如果未指定“ bind”配置指令,则Redis将侦听服务器上所有可用网络接口的连接。 可以使用“ bind”配置指令仅侦听一个或多个所选接口,然后侦听一个或多个IP地址.
就是说如果你没有设置bind项,那么所有的网络接口都可以访问该redis,如果设置了bind项,那么只有bind项内的网络接口可以访问,有点类似于白名单的意思

# ~~~ 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).

如果运行Redis的计算机直接暴露于Internet,则绑定到所有接口都是很危险的,并且会将实例暴露给Internet上的所有人。 因此,默认情况下,我们取消注释以下bind指令,这将强制Redis仅侦听IPv4环回接口地址(这意味着Redis将只能接受来自正在运行同一台计算机的客户端的连接)
意思就是如果redis不设置bind向所有网络接口开放太危险了,所以默认情况下设置bind127.0.0.1,即只能本地访问

# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
bind 127.0.0.1

如果您确定要让您的实例监听所有接口,只需注释以下行。
如果你确定向外暴露接口,那么就注释掉所有的bind设置

# 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

保护模式是安全保护的一层,以避免访问和利用Internet上打开的Redis实例,当保护模式生效的情况:1)没有使用bind指令绑定网络地址;2)redis没有设置密码。服务器仅接受来自客户端的连接,该客户端从IPv4和IPv6回送地址127.0.0.1和:: 1以及Unix域套接字连接;默认情况下启用保护模式。 仅当您确定您希望其他主机的客户端连接到Redis(即使未配置身份验证),或者使用“ bind”指令未明确列出一组特定的接口时,也应禁用它。
如果没有特殊需求,我们应该默认开启保护模式;如果有需求开放指定ip,我们应该使用bind绑定指定ip

# 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套接字上侦听。
如果我们想在指定端口上启动redis,那么就需要设置这个port设置项

# 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

在每秒请求数很高的环境中,您需要大量积压,以避免客户端连接速度慢的问题。 请注意,Linux内核将默默地将其截断为/ proc / sys / net / core / somaxconn的值,因此请确保同时提高somaxconn和tcp_max_syn_backlog的值,以获得所需的效果。
这个配置我们乍眼一看感觉不知所云,此参数确定了TCP连接中已完成队列(完成三次握手之后)的长度,但是此值必须不大于Linux系统定义的/proc/sys/net/core/somaxconn值,配置默认是511,而Linux的默认参数值是128。当系统并发量大并且客户端速度缓慢的时候,可以将这二个参数一起参考设定。所以我们在更改这个配置默认值得时候还需要修改linux系统的配置默认值,否则它只能是128.

# 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

指定将用于侦听传入连接的Unix套接字的路径。没有默认值,因此未指定时,Redis不会侦听unix套接字。客户端闲置N秒后关闭连接(0禁用)
当我们设置timeout为某个大于0的某个值的时候,如果客户端超过我们设置的这个时间没有响应,那么系统就会关闭该客户端的连接,如果设置为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

如果不为零,请在没有通信的情况下使用SO_KEEPALIVE向客户端发送TCP ACK。 这很有用,原因有两个:1)检测死亡的同伴。2)从中间的网络设备的角度来看,使连接保持活动状态。在Linux上,指定的值(以秒为单位)是用于发送ACK的时间段。 注意,关闭连接需要两倍的时间。 在其他内核上,时间取决于内核配置,此选项的合理值是300秒,这是从Redis 3.2.1开始的新Redis默认值.
这个配置项是在上面timeout不为0的时候生效的,当我们配置超时时间不为0的时候,系统就会每隔tcp-keepalive时间运行一次,查看那些已经连接超时的客户端

相关文章

网友评论

      本文标题:REDIS----配置文件----NETWORK

      本文链接:https://www.haomeiwen.com/subject/evvlzhtx.html