文章目录
- 度量单位配置
- 网络相关配置
- 通用配置
- 安全配置
- 客户端设置
度量单位配置
# 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中的配置大小单位,开头定义了一些基本的度量单位,只支持bytes,不支持bit,大小写不敏感
网络相关配置
################################## NETWORK #####################################
# 网络相关配置
# 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.
# Each address can be prefixed by "-", which means that redis will not fail to
# start if the address is not available. Being not available only refers to
# addresses that does not correspond to any network interfece. Addresses that
# are already in use will always fail, and unsupported protocols will always BE
# silently skipped.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1 # listens on two specific IPv4 addresses
# bind 127.0.0.1 ::1 # listens on loopback IPv4 and IPv6
# bind * -::* # like the default, all available interfaces
#
# ~~~ 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 on the
# IPv4 and IPv6 (if available) loopback interface addresses (this means Redis
# will only be able to accept client connections from the same host that it is
# running on).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT OUT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#bind 127.0.0.1 -::1
默认情况bind=127.0.0.1只能接受本机的访问请求
不写的情况下,无限制接受任何ip地址的访问
生产环境肯定要写应用服务器的地址;服务器是需要远程访问的,所以需要将其注释掉。
如果开启了protected_mode,那么在没有设定bind ip且没有设密码的情况下,Redis只允许接受本机的响应。
protected-mode no
将本机访问保护模式设置no,支持远程访问
tcp-backlog 511
设置tcp的backlog,backlog其实是一个连接队列,backlog队列总和 = 未完成三次握手队列 + 已经完成三次握手队列
在高并发环境下你需要一个高 backlog 值来避免慢客户端连接问题
注意Linux内核会将这个值减小到/proc/sys/net/core/somaxconn的值(128),
所以需要确认增大/proc/sys/net/core/somaxconn 和 /poc/sys/net/ipv4/tcp_syn_backlog(128)两个值来达到想要的效果
timeout 0
表示客户端连接的时间,0表示永不超时
tcp-keepalive 300
检测是否在操作,如果超过指定时间没有操作,那么就会自动结束服务,这里的数值代表每隔多少秒检测一次
通用配置
daemonize yes
表示是否为后台进程,设置为yes,守护进程,允许后台运行
pidfile /var/run/redis_6379.pid
存放pid文件的位置,每个实例会产生一个不同的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 ""
设置日志的输出路径,默认为空
安全配置
# 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.
#
# The requirepass is not compatable with aclfile option and the ACL LOAD
# command, these will cause requirepass to be ignored.
#
# requirepass foobared
访问密码的查看/设置和取消
在命令中设置密码&#xff0c;只是临时的。重启redis服务器&#xff0c;密码就还原了。
永久设置&#xff0c;需要在配置文件中进行设置
客户端设置
maxclients 10000
设置redis同时可以与多少客户端进行连接
默认情况下为10000个客户端
如果达到了此限制&#xff0c;redis则会新的连接请求&#xff0c;并且像这些连接请求方发出"max number of clients reached"以作回应
maxmemory-policy noeviction
建议必须设置&#xff0c;否则&#xff0c;将内存占满&#xff0c;造成服务器宕机
设置redis可以使用的内存量。一旦到达内存使用上限&#xff0c;redis将会试图移除内部数据&#xff0c;移除规则可以通过maxmemory-policy来指定
maxmemory-samples 5
设置样本数量&#xff0c;LRU算法和最小TTL算法都并非是精确的算法&#xff0c;而是估算值&#xff0c;所以可以设置样本的大小&#xff0c;redis默认会检查这么多个key并选择其中LRU的那个
一般设置3到7的数字&#xff0c;数值越小样本越不准确&#xff0c;但是性能消耗越小