当前位置:网站首页>Redis配置文件详解

Redis配置文件详解

2022-06-27 08:06:00 小月亮6

Linux下Redis的安装成功后在src下redis.conf是redis主要配置文件,详细可以看这篇Linux下Redis的安装

那么redis.conf主要有什么功能呢

Redis.conf

通用:

  daemonize 是否让redis进程变为守护线程

################################# GENERAL #####################################

# By default Redis does not run as a daemon. Use 'yes' if you need it.            默认情况下,Redis不作为守护进程运行。如果需要,请使用“是”。
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.    注意Redis将在/var/run中编写一个pid文件/redis.pid当守护的时候。进程管道路径,不知道什么意思
daemonize yes      

  端口号port

# 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-backlog 

  设置tcp的backlog, backlog其实 是一个连接队列,backlog队列总和=未完成三次握手队列+已经完成三次握手队列。在高并发环境下你需要-一个 高backlog值来避免慢客户端连接问题。注意Linux内核会将这个值减小到  proc/sys/net/core/ somaxconn的值所以需要确认增大somaxconn和tcp_ max_ syn_ 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   在每秒请求数高的环境中,您需要一个高的backlog以便以避免客户端连接速度慢的问题
# 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

 timeout

# Close the connection after a client is idle for N seconds (0 to disable)    客户端空闲N秒后关闭连接(0表示一直连接不关闭)
timeout 0

  tcp-keepalive

   类似于心跳,检查是否还存在,而不是宕机状态


# 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

 loglevel 

 日志级别

# 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-enabled 

  系统日志默认是关闭的

# 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

  databases 

  redis数据库数量默认是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 回车按n寻找

 默认密码为""空,可以手动设置密码

################################## SECURITY ###################################

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared

 可以手动设置密码 

[[email protected]_SW_5748F_1 config]# redis-server /usr/config/redis.conf
3819:C 01 Apr 00:00:56.073 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
3819:C 01 Apr 00:00:56.073 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=3819, just started
3819:C 01 Apr 00:00:56.073 # Configuration loaded
[[email protected]_SW_5748F_1 config]# redis-cli -p 6379
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) ""
127.0.0.1:6379> config get dir
1) "dir"
2) "/usr/config"
127.0.0.1:6379> config set requirepass 123456
OK
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> 
127.0.0.1:6379> config set requirepass ""
OK
127.0.0.1:6379> set key00 value00
OK
127.0.0.1:6379> 

限制

  默认最大连接数为10000

# 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

Redis淘汰策略:

# maxmemory <bytes>

# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
#
# volatile-lru -> Evict using approximated LRU among the keys with an expire set.
# allkeys-lru -> Evict any key using approximated LRU.
# volatile-lfu -> Evict using approximated LFU among the keys with an expire set.
# allkeys-lfu -> Evict any key using approximated LFU.
# volatile-random -> Remove a random key among the ones 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 evict anything, just return an error on write operations.
#
# LRU means Least Recently Used
# LFU means Least Frequently Used
#
# Both LRU, LFU and volatile-ttl are implemented using approximated
# randomized algorithms.
#
# 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

1.volatile-lru
从已设置过期时间的数据集中,挑选最近最少使用的数据淘汰;

2.volatile-ttl
从已设置过期时间的数据集中,挑选将要过期的数据淘汰;

3.volatile-random
从已设置过期时间的数据集中,任意选择数据淘汰;

4.allkeys-lru
当内存不足以容纳新写入数据时,移除最近最少使用的key;

5.allkeys-random
从数据集中任意选择数据淘汰;

6.noeviction(默认)
禁止淘汰数据,也就是说当内存不足时,新写入操作会报错。
7.volatile-lfu
从已设置过期时间的数据集中,挑选最不经常使用的数据淘汰(注意lfu和lru的区别);
8.allkeys-lfu
当内存不足以容纳新写入数据时,移除最不经常使用的key。

 

 单位

  单元不区分大小写,所以1GB 1Gb都是一样的

# 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 5GB 4M等形式:

# 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.   单元不区分大小写,所以1GB 1Gb都是一样的。

redis持久性RDB和aof的配置

关于redis持久性RDB和aof的配置可以看这篇《Redis的持久化机制》

原网站

版权声明
本文为[小月亮6]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_42383680/article/details/115368896