Redis配置redis.conf详解【Linux环境】

小伙伴们好,欢迎关注,一起学习,无限进步
以下内容为学习过程中的笔记

Redis.conf详解(Linux环境)

1、单位
# Redis configuration file example

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

配置文件unti单位对大小下不明显

2、包含
################################## 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 c:\path\to\other.conf

includ可以包含多个配置文件

3、网络
################################## NETWORK #####################################
bind 127.0.0.1  # 绑定ip
protected-mode yes # 保护模式,默认开启
port 6379  # 端口设置
4、通用配置
################################# GENERAL #####################################

daemonize yes # 以守护进程的方式运行,默认时no,需要我们自己设置为 yes,windows 环境
supervised no # 后台运行需要设置supervised,默认我no
pidfile /var/run/redis_6379.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
logfile "" # 日志的文件名
databases 16 # 数据库的数量,默认是16个数据库
always-show-logo yes # 是否显示是logo
5、快照
################################ SNAPSHOTTING  ################################
# 持久化,在规定的世纪那内,执行了多少此操作,则会持久化到文件 .rbd .aof中

#如果900s内,如果至少有 1 个 key 进行了修改,则进行持久化操作
save 900 1 
#如果300s内,如果至少有 10 个 key 进行了修改,则进行持久化操作
save 300 10
#如果60s内,如果至少有 10000 个 key 进行了修改,则进行持久化操作
save 60 10000

stop-writes-on-bgsave-error yes # 持久化如果出错,是否需要继续工作,默认为no

rdbcompression yes # 是否压缩 rdb 文件,需要消耗一些 cpu 资源,默认为yes

rdbchecksum yes  # 保存 rdb 文件的时候,进行错误进行校验

dir ./  # rdb 文件保存的目录

6、复制(REPLICATION)
################################# REPLICATION #################################
主从复制

后面详细讲解
7、安全(SECURITY)
################################## SECURITY ###################################

# 设置密码
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> config get requirepass  # 获取redis的密码
1) "requirepass"
2) ""
127.0.0.1:6379> config set requirepass "123456"  # 设置redis的密码
OK
127.0.0.1:6379> config get requirepass  # 发现所有的命令都没有权限了
(error) NOAUTH Authentication required.
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456  # 使用密码进行登录!
OK
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "123456
8、客户端(CLIENTS)
################################### CLIENTS ####################################
maxclients 10000 # 设置能连接上redis的最大客户端数量

# 内存
############################## MEMORY MANAGEMENT ################################
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-ttl : 删除即将过期的 
  6、noeviction : 永不过期,返回错误
9、AOF持久化
############################## APPEND ONLY MODE ###############################

appendonly yes # 默认是开启aof持久化方式
appendfilename "appendonly.aof" # 持久化的文件名字

# appendfsync always   # 每次修改都会 sync。消耗性能
appendfsync everysec   # 每秒执行一次 sync,可能会丢失这1s的数据
# appendfsync no       # 不执行sync,这个是操作系统自己同步数据,速度最快
  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

师小师

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

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

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

打赏作者

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

抵扣说明:

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

余额充值