当前位置:   article > 正文

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

redis中redis.conf配置

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

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.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

配置文件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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

includ可以包含多个配置文件

3、网络
################################## NETWORK #####################################
bind 127.0.0.1  # 绑定ip
protected-mode yes # 保护模式,默认开启
port 6379  # 端口设置
  • 1
  • 2
  • 3
  • 4
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
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 文件保存的目录

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
6、复制(REPLICATION)
################################# REPLICATION #################################
主从复制

后面详细讲解
  • 1
  • 2
  • 3
  • 4
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
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 : 永不过期,返回错误
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
9、AOF持久化
############################## APPEND ONLY MODE ###############################

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

# appendfsync always   # 每次修改都会 sync。消耗性能
appendfsync everysec   # 每秒执行一次 sync,可能会丢失这1s的数据
# appendfsync no       # 不执行sync,这个是操作系统自己同步数据,速度最快
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/498008
推荐阅读
相关标签
  

闽ICP备14008679号