Redis-浅谈redis.conf配置文件

Redis.conf

Redis.conf是Redis的配置文件,它包含了一系列用于配置Redis服务器行为和功能的选项。

以下是Redis.conf中常见的一些选项配置:

  • bind: 指定Redis服务器监听的IP地址,默认为127.0.0.1,表示只能本地访问,可以改为0.0.0.0以允许来自任意IP地址的访问。

  • port: 指定Redis服务器监听的端口号,默认为6379。

  • timeout: 指定客户端连接到Redis服务器的超时时间,默认为0,表示无限制。

  • requirepass: 设置连接Redis服务器所需的密码,默认为空,即不需要密码。

  • databases: 指定Redis服务器中可以创建的数据库数量,默认为16个。

  • maxclients: 指定Redis服务器同时连接的最大客户端数量,默认为10000个。

  • maxmemory: 指定Redis服务器可以使用的最大内存数量,默认为0,表示不限制。

  • logfile: 指定Redis服务器的日志文件路径,默认为空,即不输出日志。

  • save: 指定Redis服务器进行持久化的条件,默认为三个条件都满足时进行持久化:900秒内进行了1次写操作、300秒内进行了10次写操作、60秒内进行了10000次写操作。

  • rdbcompression: 指定Redis服务器在进行RDB持久化时是否压缩数据,默认为yes。

  • appendonly: 指定是否开启AOF持久化,默认为no,可以改为yes。

  • appendfsync: 指定AOF持久化的方式,默认为everysec,表示每秒钟同步一次。

  • requirepass: 指定连接Redis服务器所需的密码,默认为空,表示不需要密码。

这些只是Redis.conf中的一部分选项,实际上还有很多其他选项可以进行配置。通过修改Redis.conf,可以根据实际需求对Redis服务器进行定制化的配置。
在这里插入图片描述

1.容量单位不区分大小写,G和GB有区别

在这里插入图片描述

2.可以使用 include 组合多个配置问题

在这里插入图片描述

3.网络配置

#ip绑定
bind 127.0.0.1
# 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
# Accept connections on the specified port,default is 6379 (IANA #815344)# If port @ isspecified Redis will not listen on a TCP socket.
#端口
port 6379

4.日志输出级别

daemonize yes  #以守护进程的方式运行,默认是 no,我们需要自己开启为yes!
pidfile /var/run/redis_6379.pid # 如果以后台的方式运行,我们就需要指定一个 pid 文件!
# 日志
# Specify the server verbosity Teve1
# 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
  1. 日志输出文件
logleve1 notice
logfile“” # 日志的文件位置名
databases 16 # 数据库的数量,默认是 16 个数据库
always-show-logo yes # 是否总是显示LOGO

6.持久化规则 (RDB)

由于Redis是基于内存的数据库,需要将数据由内存持久化到文件中

  • AOF
#持久化规则,持久化到文件 .rdb .aof
# 如果了900秒内 至少1个key进行了修改,就进行持久化
save 900 1
#300秒内 10个key进行了修改
save 300 10
save 60 10000
  • RDB文件相关
#持久化错误是否继续工作
stop-writes-on-bgsave-error yes
#Compress string objects using LZF when dump .rdb databases?
#For default that's set to 'yes' as it's almost always a win.
#If you want to save some CPU in the saving child set it to 'no' but# the dataset will likely be bigger if you have compressible values or keys.

#是否压缩.rdb文件
rdbcompression yes
#Since version 5 of RDB a CRC64 checksum is placed at the end of the file.# This makes the format more resistant to corruption but there is a performance# hit to pay (around 10%) when saving and loading RDB files, so you can disable it
#for maximum performances.
#RDB files created with checksum disabled have a checksum of zero that will
#tell the Loading code to skip the check.
#校验校rdb文件
rdbchecksum yes
#The filename where to dump the DB
dbfilename dump.rdb
# 如果900s内,如果至少有一个1 key进行了修改,我们及进行持久化操作
save 900 1
# 如果300s内,如果至少10 key进行了修改,我们及进行持久化操作
save 300 10
# 如果60s内,如果至少10000 key进行了修改,我们及进行持久化操作
save 60 10000
# 我们之后学习持久化,会自己定义这个测试!
# 持久化如果出错,是否还需要继续工作!
stop-writes-on-bgsave-error yes
rdbcompression yes  #是否压缩 rdb 文件,需要消耗一些cpu资源!
rdbchecksum yes  #保存rdb文件的时候,进行错误的检查校验!
dir ./ #rdb 文件保存的目录!

7.主从复制

replication在这里插入图片描述

8.Security模块中进行密码设置

在这里插入图片描述

在这里插入图片描述

9.客户端连接相关

maxclients 10000 #设置能连接上redis的最大客户端的数量
maxmemory <bytes> # redis 配置最大的内存容量
maxmemory-policy noeviction # 内存到达上限之后的处理策略
1、volatile-lru: 只对设置了过期时间的key进行LRu(默认值)
2、allkeys-lru: 删除lru算法的key
3、volatile-random: 随机删除即将过期key
4、allkeys-random: 随机删除
5、volatile-tt1 :删除即将过期的
6、noeviction : 永不过期,返回错误
maxclients 10000  最大客户端数量
maxmemory <bytes> 最大内存限制
maxmemory-policy noeviction # 内存达到限制值的处理策略

redis 中的默认的过期策略是 volatile-lru

设置方式

config set maxmemory-policy volatile-lru 

10.AOF相关部分

appendonly no  # 默认是不开启aof模式的,默认是使用rdb方式持久化的,在大部分所有的情况下,rdb完全够用!
appendfilename "appendonly.aof"  # 持久化的文件的名字
#appendfsync always  # 每次修改都会 sync。消耗性能
appendfsync everysec  # 每秒执行一次 sync,可能会丢失这1s的数据!
# appendfsync no # 不执行 sync,这个时候操作系统自己同步数据,速度最快!
appendonly no # 默认不开启 aof 使用rdb持久化
# The name of the append only file (default: "appendonty.aof")	
appendfilename"appendonly.aof"
# appendfsync always 每次修改进行同步
appendfsync everysec # 每秒执行一次同步
# appendfsync no 不进行同步 由操作系统进行同步 速度最快

Redis-浅谈redis.conf配置文件 到此完结,笔者归纳、创作不易,大佬们给个3连再起飞吧

  • 13
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小孔靠得住

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值