【redis6】第四章(配置文件)

news2025/1/16 21:03:27

自定义目录:/etc/redis.conf

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.

INCLUDES包含

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

NETWORK网络相关配置

bind

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

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all available network interfaces on the host machine.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
# Each address can be prefixed by "-", which means that redis will not fail to
# start if the address is not available. Being not available only refers to
# addresses that does not correspond to any network interfece. Addresses that
# are already in use will always fail, and unsupported protocols will always BE
# silently skipped.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1     # listens on two specific IPv4 addresses
# bind 127.0.0.1 ::1              # listens on loopback IPv4 and IPv6
# bind * -::*                     # like the default, all available interfaces
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only on the
# IPv4 and IPv6 (if available) loopback interface addresses (this means Redis
# will only be able to accept client connections from the same host that it is
# running on).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT OUT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1 -::1

protected-mode

将本机访问保护模式设置为no

# 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

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的值(128),所以需要确认增大/proc/sys/net/core/somaxconn 和 /proc/sys/net/ipv4/tcp_max_syn_backlog(128)两个值来达到想要的效果

# TCP listen() backlog.
#
# In high requests-per-second environments you need a high backlog in order
# to avoid slow clients connection issues. Note that the Linux kernel
# 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

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

# Unix socket.
#
# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
# unixsocket /run/redis.sock
# unixsocketperm 700

# Close the connection after a client is idle for N seconds (0 to disable)
timeout 0

tcp-keepalive

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

# 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) Force network equipment in the middle to consider the connection to be
#    alive.
#
# 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

GENERAL通用

daemonize

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

################################# GENERAL #####################################

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
# When Redis is supervised by upstart or systemd, this parameter has no impact.
daemonize yes

pidfile

存放pid文件的位置,每个实例会产生一个不同的pid文件

# If a pid file is specified, Redis writes it where specified at startup
# and removes it at exit.
#
# When the server runs non daemonized, no pid file is created if none is
# specified in the configuration. When the server is daemonized, the pid file
# is used even if not specified, defaulting to "/var/run/redis.pid".
#
# Creating a pid file is best effort: if Redis is not able to create it
# nothing bad happens, the server will start and run normally.
#
# Note that on modern Linux systems "/run/redis.pid" is more conforming
# and should be used instead.
pidfile /var/run/redis_6379.pid

loglevel

指定日志记录级别,Redis总共支持四个级别:debug、verbose、notice、warning,默认为notice

四个级别根据使用阶段来选择,生产环境选择notice 或者 warning

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

databases

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

# 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

设置密码

# IMPORTANT NOTE: starting with Redis 6 "requirepass" is just a compatibility
# layer on top of the new ACL system. The option effect will be just setting
# the password for the default user. Clients will still authenticate using
# AUTH <password> as usually, or more explicitly with AUTH default <password>
# if they follow the new protocol: both will work.
#
# The requirepass is not compatable with aclfile option and the ACL LOAD
# command, these will cause requirepass to be ignored.
#
# requirepass foobared

访问密码的查看、设置和取消

在命令中设置密码,只是临时的。重启redis服务器,密码就还原了。

永久设置,需要再配置文件中进行设置。

在这里插入图片描述

CLIENTS(LIMITS限制)

maxclients

  • 设置redis同时可以与多少个客户端进行连接。
  • 默认情况下为10000个客户端。
  • 如果达到了此限制,redis则会拒绝新的连接请求,并且向这些连接请求方发出“max number of clients reached”以作回应。
################################### CLIENTS ####################################
# 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'.
#
# IMPORTANT: When Redis Cluster is used, the max number of connections is also
# shared with the cluster bus: every node in the cluster will use two
# connections, one incoming and another outgoing. It is important to size the
# limit accordingly in case of very large clusters.
#
# maxclients 10000

maxmemory

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

# Set a memory usage limit to the specified amount of bytes.
# When the memory limit is reached Redis will try to remove keys
# according to the eviction policy selected (see maxmemory-policy).
#
# If Redis can't remove keys according to the policy, or if the policy is
# set to 'noeviction', Redis will start to reply with errors to commands
# that would use more memory, like SET, LPUSH, and so on, and will continue
# to reply to read-only commands like GET.
#
# This option is usually useful when using Redis as an LRU or LFU cache, or to
# set a hard memory limit for an instance (using the 'noeviction' policy).
#
# WARNING: If you have replicas attached to an instance with maxmemory on,
# the size of the output buffers needed to feed the replicas are subtracted
# from the used memory count, so that network problems / resyncs will
# not trigger a loop where keys are evicted, and in turn the output
# buffer of replicas is full with DELs of keys evicted triggering the deletion
# of more keys, and so forth until the database is completely emptied.
#
# In short... if you have replicas attached it is suggested that you set a lower
# limit for maxmemory so that there is some free RAM on the system for replica
# output buffers (but this is not needed if the policy is 'noeviction').
#
# maxmemory <bytes>

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: how Redis will select what to remove when maxmemory
# is reached. You can select one from the following behaviors:
#
# volatile-lru -> Evict using approximated LRU, only keys with an expire set.
# allkeys-lru -> Evict any key using approximated LRU.
# volatile-lfu -> Evict using approximated LFU, only keys with an expire set.
# allkeys-lfu -> Evict any key using approximated LFU.
# volatile-random -> Remove a random key having 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, when there are no suitable keys for
# eviction, Redis will return an error on write operations that require
# more memory. These are usually commands that create new keys, add data or
# modify existing keys. A few examples are: SET, INCR, HSET, LPUSH, SUNIONSTORE,
# SORT (due to the STORE argument), and EXEC (if the transaction includes any
# command that requires memory).
#
# The default is:
#
# maxmemory-policy noeviction

maxmemory-samples

  • 设置样本数量,LRU算法和最小TTL算法都并非是精确的算法,而是估算值,所以你可以设置样本的大小,redis默认会检查这么多个key并选择其中LRU的那个。
  • 一般设置3到7的数字,数值越小样本越不准确,但性能消耗越小。
# LRU, LFU and minimal TTL algorithms are not precise algorithms but approximated
# algorithms (in order to save memory), so you can tune it for speed or
# accuracy. By default Redis will check five keys and pick the one that was
# used least recently, you can change the sample size using the following
# configuration directive.
#
# The default of 5 produces good enough results. 10 Approximates very closely
# true LRU but costs more CPU. 3 is faster but not very accurate.
#
# maxmemory-samples 5

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/158843.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

D3.js基础教程

D3: Data-Driven Documents D3 (或D3.js)是一个JavaScript库&#xff0c;用于使用Web标准可视化数据。 D3帮助您使用SVG&#xff0c;Canvas和HTML使数据栩栩如生。 D3将强大的可视化和交互技术与数据驱动的DOM操作方法相结合&#xff0c;为您提供现代浏览器的全部功能&#xf…

【owt-server】RtpTransportControllerSend的创建和使用

owt-server 5.0 【owt-server】librtcadapter: VideoSendAdapterImpl 视频发送侧及mia 调用分片发送H264帧只是简单的发送发送侧必须有一套传输控制机制这套机制还需要接收测联动。发送侧 NonPacedSender bool VideoSendAdapterImpl::init() 创建 需要首先创建m_transportCont…

如何判断一个数据库是不是出问题了?

我在前面文章中,和你介绍了主备切换流程。通过这些内容的讲解,你应该已经很清楚了:在一主一备的双 M 架构里,主备切换只需要把客户端流量切到备库;而在一主多从架构里,主备切换除了要把客户端流量切到备库外,还需要把从库接到新主库上。 主备切换有两种场景,一种是主动…

Linux系统编程——线程

守护进程 守护进程: daemon进程。通常运行与操作系统后台&#xff0c;脱离控制终端。 一般不与用户直接交互。 周期性的等待某个事件发生或周期性执行某一动作。 不受用户登录注销影响。 通常采用以a结尾的命名方式。守护进程创建步骤; fork子进程&#xff0c;让父进程终止。…

年轻人的颜值担当,当下正流行的开关面板设计,你pick哪一款?

在颜值即正义的时代 越来越多的年轻人选择产品时 除了关注产品的功能外 也愈加愿意为产品的颜值买单近年来&#xff0c;鸿雁从大自然和生活中汲取灵感 以年轻、新鲜、现代的设计风格 赋予开关面板更有格调的外形 引领了墙面上的家居美学 下面&#xff0c;小雁带大家一起从鸿雁热…

微服务调用组件Feign的原理及高级功能实战

目录 一、Fegin的原理 二、Spring Cloud 整合Feign 三、Spring Cloud整合Dubbo 微服务调用组件Feign的原理及高级功能是我们今天分享的主题&#xff0c;此组件可以说是微服务必用的&#xff0c;服务远程调用&#xff0c;属于RPC远程调用的一种&#xff0c;RPC 全称是 Remote …

如何划分子网(例题讲解)

44(12分)设某ISP拥有一个网络地址块201.123.16.0/21,现在该ISP要为A、B、C、D四个组织分配IP地址,其需要的地址数量分别为985、486、246以及211,而且要求将低地址段的 IP 地址分配给 IP 地址需求量大的组织。请给出一个合理的分配方案以满足该需求。要求将各组织所获得的子网地…

2023年,推荐10个让你事半功倍的CSS在线生产力工具

谈到 CSS&#xff0c;您总是必须编写许多代码行&#xff0c;才能使您的项目在样式方面看起来美观大方。当然&#xff0c;专注于为前端编写好的 CSS 很重要&#xff0c;但这个过程可能会花费很多时间。作为 Web 开发人员&#xff0c;CSS 是我们开展项目时必不可少的语言之一。我…

从GPT到chatGPT(一):GPT1

GPT1 文章目录GPT1前言正文模型架构无监督学习有监督学习处理不同特定任务实验训练细节实验结果分析预训练层参数转移的影响zero-shot的表现消融实验总结前言 GPT1&#xff0c;出自于OpenAI的论文《Improving Language Understanding by Generative Pre-Training》&#xff0c…

Serverless介绍

Serverless架构应该是采用FaaS&#xff08;函数即服务&#xff09;和Baas&#xff08;后端即服务&#xff09;服务来解决问题的一种设计 狭义Serverless FaaS BaaS BaaS: Bakend as a Service 负责存储后端即服务&#xff1a;Serverless把后端架构工作包揽下来&#xff0c;硬…

CIO如何控制老板提需求?CIO PLUS

老板乱提需求&#xff0c;员工苦不堪言&#xff0c;职场中经常听到吐槽老板的言论&#xff0c;这个话题很有意思。因为一般老板这个角色基本上是不会管公司具体业务的&#xff0c;公司运营一般都是由专业的职业经理人就是CEO来管理&#xff0c;所以作为公司的老板就更不可能亲自…

Web(五)

JavascriptDOM* 功能&#xff1a;控制html文档的内容* 获取页面标签(元素)对象&#xff1a;Element* document.getElementById("id值"):通过元素的id获取元素对象* 操作Element对象&#xff1a;1. 修改属性值&#xff1a;明确获取的对象是哪一个&#xff1f;查看API文…

【SpringCloud06】SpringCloud Eureka 服务注册与发现

1.Eureka基础知识 1.1什么是服务治理&#xff1f; Spring Cloud 封装了 Netflix 公司开发的 Eureka 模块来实现服务治理 在传统的rpc远程调用框架中&#xff0c;管理每个服务与服务之间依赖关系比较复杂&#xff0c;管理比较复杂&#xff0c;所以需要使用服务治理&#xff0…

Linux - top命令详解

目录top启动参数基础字段说明第一行&#xff0c;系统任务统计信息&#xff1a;第二行&#xff0c;进程统计信息&#xff1a;第三行&#xff0c;CPU统计信息&#xff1a;第四行&#xff0c;内存统计信息&#xff1a;第五行&#xff0c;swap交换分区统计信息&#xff1a;第六行&a…

堆和栈详解js

认识堆和栈学习编程的时候&#xff0c;经常会看到stack这个词&#xff0c;它的中文名字叫做"栈"。理解这个概念&#xff0c;对于理解程序的运行至关重要。容易混淆的是&#xff0c;这个词其实有几种含义在理解堆与栈这两个概念时&#xff0c;需要放到具体的场景下去理…

基于java SSM图书管理系统简单版设计和实现

基于java SSM图书管理系统简单版设计和实现 博主介绍&#xff1a;5年java开发经验&#xff0c;专注Java开发、定制、远程、文档编写指导等,csdn特邀作者、专注于Java技术领域 作者主页 超级帅帅吴 Java毕设项目精品实战案例《500套》 欢迎点赞 收藏 ⭐留言 文末获取源码联系方式…

软件测试/测试开发 | Jenkins通过什么方式报警?

在工作中&#xff0c;一般是没有时间一直看着 Jenkins 直到它运行结果出现的。所以采用了配置 Email 的方式&#xff0c;可以及时将结果通知给我们。 所需要用到的Jenkins插件 需要下载的 Email 插件名称&#xff0c;这两个插件的作用是帮助用户方便的设置格式化邮件&#xf…

【Java集合】开发中如何选择集合实现类

在实际开发中&#xff0c;选择什么集合实现类&#xff0c;主要取决于业务操作的特点&#xff0c;然后根据集合实现类特性进行选择&#xff1a; &#x1f449; 先判断存储的类型&#xff08;一组对象或一组键值对&#xff09;&#xff1a; 一组对象 【单列】&#xff1a;Colle…

ES6-11这一篇就够啦

ES6-11这一篇就够啦ECMAScript 6-111、ECMAScript 相关介绍1.1 ECMAScript简介1.2 ES6的重要性2、ECMAScript 6新特性2.1 let关键字2.2 const关键字2.3 变量的解构赋值2.4 模板字符串2.5 简化对象写法2.6 箭头函数2.7 rest参数2.8 spread扩展运算符2.9 Symbol2.10 迭代器2.11 生…

在GCP上创建GCE的三种方式(Console,gcloud,Terraform)

1 简介 如果要选择GCP为云平台&#xff0c;则经常需要创建GCE(Google Compute Engine)&#xff0c;有以下几种方式&#xff1a; (1) 在浏览器创建 (2) 命令 gcloud (3) Terraform 在开始之前&#xff0c;可以查看&#xff1a;《初始化一个GCP项目并用gcloud访问操作》。 …