当前位置:网站首页>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的持久化机制》
边栏推荐
- MySQL about auto increment sum cannot be empty
- JS performance reward and punishment examples
- PayPal账户遭大规模冻结!跨境卖家如何自救?
- js用switch语句根据1-7输出对应英文星期几
- 认识O(NlogN)的排序
- The 6th Blue Bridge Cup
- File and multipartfile overview
- Blind survey shows that female code farmers are better than male code farmers
- sql注入之order by注入
- Pin details in rust
猜你喜欢
PayPal account has been massively frozen! How can cross-border sellers help themselves?
UE5神通--POI解决方案
What is a magnetic separator?
JS to judge the odd and even function and find the function of circular area
「短视频」临夏消防救援支队开展消防安全培训授课
The IPO of Yefeng pharmaceutical was terminated: Yu Feng, the actual controller who had planned to raise 540million yuan, made P2P investment
关联GIS:条条道路通UE5城
05 观察者(Observer)模式
一种太阳能电荷泵供电电路的方案设计
After working in a large factory for ten years with an annual salary of 400000 yuan, I was suddenly laid off. If the company wanted to abandon you, it wouldn't leave any kindness
随机推荐
[13. number and bit operation of 1 in binary]
關聯GIS:條條道路通UE5城
无论LCD和OLED显示技术有多好,都无法替代这个古老的显示数码管
All tutor information on one page
js打印99乘法表
【论文阅读】Intrinsically semi-supervised methods
[batch dos-cmd command - summary and summary] - map folder to virtual disk - subst
洛谷刷题心得记录
【c ++ primer 笔记】第3章 字符串、向量和数组
Win10 how to manage startup items?
JS uses the while cycle to calculate how many years it will take to grow from 1000 yuan to 5000 yuan if the interest rate for many years of investment is 5%
SPARQL basic introductory exercise
【13. 二进制中1的个数、位运算】
Experience record of Luogu's topic brushing
What is a magnetic separator?
Closure problem
SQL Sever column name or number of supplied values does not match the table definition
准备好迁移上云了?请收下这份迁移步骤清单
盲測調查顯示女碼農比男碼農更優秀
MySQL environment variable configuration tutorial