四、 Redis配置文件介绍

1、Units单位

配置大小单位,开头定义了一些基本的度量单位,只支持bytes,不支持bit 大小写不敏感

# Redis configuration file example.
#
# Note that in order to read the configuration file, Redis must be
# started with the file path as first argument:
#
# ./redis-server /path/to/redis.conf

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

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.
#
# Note that 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 /path/to/other.conf
  • 类似jsp中的include,多实例的情况可以把公用的配置文件提取出来

3、网络相关配置

1、bind

  • 默认情况bind=127.0.0.1只能接受本机的访问请求
  • 不写的情况下,无限制接受任何ip地址的访问
  • 生产环境肯定要写你应用服务器的地址;服务器是需要远程访问的,所以需要将其注释掉
  • 如果开启了protected-mode,那么在没有设定bind ip且没有设密码的情况下,Redis只允许接受本机的响应

2、protected-mode

  • 将本机访问保护模式设置no
protected-mode no

3、port

  • 端口号,默认 6379

4、tcp-backlog

  • 设置tcp的backlog,backlog其实是一个连接队列,backlog队列总和=未完成三次握手队列 + 已经完成三次握手队列。
  • 在高并发环境下你需要一个高backlog值来避免慢客户端连接问题。
  • 注意Linux内核会将这个值减小到/proc/sys/net/core/somaxconn的值(128),所以需要确认增大/proc/sys/net/core/somaxconn和/proc/sys/net/ipv4/tcp_max_syn_backlog(128)两个值来达到想要的效果
tcp-backlog 511

5、 timeout

  • 一个空闲的客户端维持多少秒会关闭,0表示关闭该功能。即永不关闭。
timeout 0

6、tcp-keepalive

  • 对访问客户端的一种心跳检测,每个n秒检测一次。
  • 单位为秒,如果设置为0,则不会进行Keepalive检测,建议设置成60
tcp-keepalive 300

4、GENERAL通用

1、 daemonize

  • 是否为后台进程,设置为yes
  • 守护进程,后台启动
daemonize yes

2、pidfile

  • 存放pid文件的位置,每个实例会产生一个不同的pid文件
pidfile /var/run/redis_6379.pid

3、loglevel

  • 指定日志记录级别,Redis总共支持四个级别:debug、verbose、notice、warning,默认为notice
  • 四个级别根据使用阶段来选择,生产环境选择notice 或者warning
loglevel notice

4、logfile

  • 日志文件名称
logfile ""

5、databases 16

  • 设定库的数量 默认16,默认数据库为0,可以使用SELECT 命令在连接上指定数据库id
databases 16

5、SECURITY安全

1、设置密码

# requirepass foobared
  • 访问密码的查看、设置和取消
  • 在命令中设置密码,只是临时的。重启redis服务器,密码就还原了。
  • 永久设置,需要再配置文件中进行设置。
config get requirepass
config set requirepass "123456"
config set requirepass ""

6、LIMITS限制

1、maxclients

  • 设置redis同时可以与多少个客户端进行连接。
  • 默认情况下为10000个客户端。
  • 如果达到了此限制,redis则会拒绝新的连接请求,并且向这些连接请求方发出“max number of clients reached”以作回应。
# maxclients 10000

2、maxmemory

  • 建议必须设置,否则,将内存占满,造成服务器宕机
  • 设置redis可以使用的内存量。一旦到达内存使用上限,redis将会试图移除内部数据,移除规则可以通过maxmemory-policy来指定。
  • 如果redis无法根据移除规则来移除内存中的数据,或者设置了“不允许移除”,那么redis则会针对那些需要申请内存的指令返回错误信息,比如SET、LPUSH等。
  • 但是对于无内存申请的指令,仍然会正常响应,比如GET等。如果你的redis是主redis(说明你的redis有从redis),那么在设置内存使用上限时,需要在系统中留出一些内存空间给同步队列缓存,只有在你设置的是“不移除”的情况下,才不用考虑这个因素。
# maxmemory <bytes>

3、maxmemory-policy

  • volatile-lru:使用LRU算法移除key,只对设置了过期时间的键;
  • allkeys-lru:在所有集合key中,使用LRU算法移除key
  • volatile-random:在过期集合中移除随机的key,只对设置了过期时间的键
  • allkeys-random:在所有集合key中,移除随机的key
  • volatile-ttl:移除那些TTL值最小的key,即那些最近要过期的key
  • noeviction:不进行移除。针对写操作,只是返回错误信息
# maxmemory-policy noeviction

4、maxmemory-samples

  • 设置样本数量,LRU算法和最小TTL算法都并非是精确的算法,而是估算值,所以你可以设置样本的大小,redis默认会检查这么多个key并选择其中LRU的那个。
  • 一般设置3到7的数字,数值越小样本越不准确,但性能消耗越小。
# maxmemory-samples 5

下一篇:Redis的发布和订阅

更多内容:

更多内容大家可以关注一下个人博客网,https://blog.xueqimiao.com/,内容更丰富喔。
在这里插入图片描述
回复Redis可以获取完整md文档喔,谢谢关注。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小薛博客

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

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

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

打赏作者

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

抵扣说明:

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

余额充值