Redis相关配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35977237/article/details/79875785
计量单位说明
大小写不敏感
只支持bytes,不支持bit
# 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.


include
类似jsp中的include,多实例的情况可以把公用的配置文件提取出来
################################## 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


NETWORK相关
ip地址的绑定(bind)
默认情况bind = 127.0.0.1,即只能接受本机的访问请求
不写的情况下,无限制接受任何ip地址的访问
生产环境肯定要写应用服务器的地址
如果开启了protected-mode,那么在没有设定bind ip且没有设置密码的情况下,Redis只允许接受本机的响应
port(端口)
默认端口为6379
tcp-backlog
可以理解是一个请求到达后 至 接受进程处理前的队列
backlog队列总和 = 未完成三次握手队列 + 已完成三次握手队列
在高并发环境下,需要一个高backlog值来避免慢客户端连接问题。同时需要注意Linux内核会将整个值减小到/proc/sys/net/core/somaxconn的值,所以需要确认增大somaxconn和tcp_max_syn_backlog两个值来达到想要的想过
timeout
一个空闲的客户端维持多少秒会关闭,0为永不关闭
TCP keepalive
对访问客户端的一种心跳检测,每个n秒检测一次
如果设置为0,则不会进行Keepalive检测
官方推荐设为60秒


常规配置
daemonized
是否为后台进程,默认为no
# 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
pidfile
存放pid文件的文职,每个实例会产生一个不同的pid文件
# 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
log level
四个级别,根据使用阶段选择。生产环境选择notice或者warning
# 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
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 ""
syslog
是否将Redis日志输送到Linux系统日志服务中
# 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
syslog-ident
日志的标志
# Specify the syslog identity.
# syslog-ident redis
syslog-facility
输出日志的设备,值可以是USER或LOCAL0-LOCAL7
# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
# syslog-facility local0
databases
设定库的数量,默认16
# 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


security
命令行中设置密码
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) ""
127.0.0.1:6379> config set requirepass "root"
OK
127.0.0.1:6379> auth root
OK
127.0.0.1:6379> 操作


LIMIT相关
maxclient
最大客户端连接数,默认情况下为10000个客户端
当你无法设置进程文件句柄限制时,redis会设置为当前的文件句柄限制值减去32,因为redis会为自身内部处理逻辑留一些句柄出来。如果达到了此限制,redis则会拒绝新的连接请求,并向这些连接请求方发送“max number of clients reached”以作回应
# 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'.
#
# maxclients 10000
maxmemory
设置Redis可以使用的内存量。一旦到达内存使用上限,Redis将会视图移除内部数据,移除规则可以通过maxmemory-policy来指定。如果Redis无法根据移除规则来移除内存中的数据,或者设置了“不允许移除”,那么Redis则会针对那些需要申请内存的指令返回错误信息,比如SET,LPUSH等
但是对于无内存申请的指令,仍然会正常响应,比如GET等。如果你的redis是主redis(说明你的redis有从redis),那么在设置内存使用上限时,需要在系统中留出一些内存空间给同步队列缓存,只有在你设置的是“不移除”的情况下,才不用考虑这个因素
# Don't use more memory than 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).
#
# If Redis can't remove keys according to the policy, or if the policy is
# set to 'noeviction', Redis will start to reply with errors to commands
# that would use more memory, like SET, LPUSH, and so on, and will continue
# to reply to read-only commands like GET.
#
# This option is usually useful when using Redis as an LRU cache, or to set
# a hard memory limit for an instance (using the 'noeviction' policy).
#
# WARNING: If you have slaves attached to an instance with maxmemory on,
# the size of the output buffers needed to feed the slaves are subtracted
# from the used memory count, so that network problems / resyncs will
# not trigger a loop where keys are evicted, and in turn the output
# buffer of slaves is full with DELs of keys evicted triggering the deletion
# of more keys, and so forth until the database is completely emptied.
#
# In short... if you have slaves attached it is suggested that you set a lower
# limit for maxmemory so that there is some free RAM on the system for slave
# output buffers (but this is not needed if the policy is 'noeviction').
#
# maxmemory <bytes>
maxmemory-policy
volatile-lru -> 使用LRU算法移除key,只对设置了过期时间的键
allkeys-lru -> 使用LRU算法移除key
volatile-random -> 在过期集合中移除随机的key,只对设置了过期时间的键
allkeys-random -> 移除随机的key
volatile-ttl -> 移除那些TTL值最小的key,即那些最近要过期的key
noeviction -> 不进行移除。针对写操作,只是返回错误信息
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
#
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key according to the LRU algorithm
# volatile-random -> remove a random key with 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 expire at all, just return an error on write operations
#
# 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
maxmemory-samples
设置样本数量。LRU算法和最小TTL算法都并非是精确的算法,而是估算值,所以你可以设置样本的大小
一般设置3到7的数字,数值越小样本越不准确,但是性能消耗也越小
redis默认会检查这么多个key并选择其中LRU的那个
# LRU and minimal TTL algorithms are not precise algorithms but approximated
# algorithms (in order to save memory), so you can tune it for speed or
# accuracy. For default Redis will check five keys and pick the one that was
# used less recently, you can change the sample size using the following
# configuration directive.
#
# The default of 5 produces good enough results. 10 Approximates very closely
# true LRU but costs a bit more CPU. 3 is very fast but not very accurate.
#
# maxmemory-samples 5






redis.conf.bak

猜你喜欢

转载自blog.csdn.net/qq_35977237/article/details/79875785
今日推荐