redis.conf配置参数详解

合集下载

Redis配置参数详解

Redis配置参数详解

Redis配置参数详解Redis是⼀个应⽤⾮常⼴泛的⾼性能Key-Value型数据库,与memcached类似,但功能更加强⼤!本⽂将按照不同功能模块的⽅式,依次对各个功能模块的配置参数进⾏详细介绍。

GENERAL./redis-server /path/to/redis.conf 按照指定的配置⽂件启动include /path/to/other.conf 包含其它的redis配置⽂件daemonize yes 启⽤后台守护进程运⾏模式pidfile /var/run/redis.pid redis启动后的进程ID保存⽂件port 6379 指定使⽤的端⼝号bind IP 监听指定的⽹络接⼝unixsocket /tmp/redis.sock 指定监听的socket,适⽤于unix环境timeout N 客户端空闲N秒后断开连接,参数0表⽰不启⽤loglevel notice 指定服务器信息显⽰的等级,4个参数分别为debug\verbose\notice\warninglogfile “” 指定⽇志⽂件,默认是使⽤系统的标准输出syslog-enabled no 是否启⽤将记录记载到系统⽇志功能,默认为不启⽤syslog-ident redis 若启⽤⽇志记录,则需要设置⽇志记录的⾝份syslog-facility local0 若启⽤⽇志记录,则需要设置⽇志facility,可取值范围为local0~local7,表⽰不同的⽇志级别databases 16 设置数据库的数量,默认启动时使⽤DB0,使⽤“select <dbid>”可以更换数据库tcp-backlog 511 此参数确定TCP连接中已完成队列(3次握⼿之后)的长度,应⼩于Linux系统的/proc/sys/net/core/somaxconn的值,此选项默认值为511,⽽Linux的somaxconn默认值为128,当并发量⽐较⼤且客户端反应缓慢的时候,可以同时提⾼这两个参数。

redis集群 配置参数

redis集群 配置参数

redis集群配置参数
在Redis集群中,需要配置以下参数:
1. cluster-enabled:设置为yes来启用集群模式。

2. cluster-config-file:指定集群配置文件的路径。

3. cluster-node-timeout:指定集群节点之间的超时时间。

4. cluster-announce-ip:指定集群节点的IP地址。

5. cluster-announce-port:指定集群节点的端口号。

6. cluster-announce-bus-port:指定集群节点之间通信的端口号。

7. cluster-require-full-coverage:设置为yes来要求所有槽位都要有节点才能正常工作。

8. cluster-migration-barrier:设置为yes来阻止在槽迁移期间的对数据的写入操作。

这些参数可以在Redis的配置文件redis.conf中进行设置。

在配置文件中找到对应的参数进行修改并重启Redis服务即可生效。

redis配置文件详解

redis配置文件详解

redis 是一款开源的、高性能的键-值存储(key-value store),和 memcached 类似,redis 常被称作是一款 key-value 内存存储系统或者内存数据库,同时由于它支持丰富的数据结构,又被称为一种数据结构服务器(data structure server)。

编译完 redis,它的配置文件在源码目录下 redis.conf ,将其拷贝到工作目录下即可使用,下面具体解释redis.conf 中的各个参数:1 daemonize no默认情况下,redis 不是在后台运行的,如果需要在后台运行,把该项的值更改为 yes。

2 pidfile /var/run/redis.pid当 Redis 在后台运行的时候,Redis 默认会把 pid 文件放在/var/run/redis.pid,你可以配置到其他地址。

当运行多个 redis 服务时,需要指定不同的 pid 文件和端口3 port监听端口,默认为 63794 #bind 127.0.0.1指定 Redis 只接收来自于该 IP 地址的请求,如果不进行设置,那么将处理所有请求,在生产环境中为了安全最好设置该项。

默认注释掉,不开启5 timeout 0设置客户端连接时的超时时间,单位为秒。

当客户端在这段时间内没有发出任何指令,那么关闭该连接6 tcp-keepalive 0指定 TCP 连接是否为长连接,"侦探"信号有 server 端维护。

默认为 0.表示禁用7 loglevel noticelog 等级分为 4 级,debug,verbose, notice, 和 warning。

生产环境下一般开启 notice 8 logfile stdout配置 log 文件地址,默认使用标准输出,即打印在命令行终端的窗口上,修改为日志文件目录9 databases 16设置数据库的个数,可以使用 SELECT 命令来切换数据库。

resolvconf 参数

resolvconf 参数

resolvconf是一个用于管理DNS设置的工具,它允许您在不同的网络环境中使用不同的DNS服务器配置。

resolv.conf是DNS客户机的配置文件,用于设置DNS服务器的IP地址及DNS域名,还包含了主机的域名搜索顺序。

在resolv.conf文件中,每行都会以一个关键字开头,然后跟配置参数。

主要使用的关键词有:nameserver、search和options。

1. nameserver:定义DNS服务器的IP地址。

解析器应该查询的名称服务器的Internet 地址,可以是IPv4地址或IPv6地址。

2. search:定义域名的搜索列表,当查询的域名中包含的.的数量少于options.ndots的值时,会依次匹配列表中的每个值。

3. options:定义域名查找时的配置信息,例如ndots选项表示在搜索列表中,至少需要包含多少个点(.)才能进行域名查找。

Redis缓存的连接池配置

Redis缓存的连接池配置

Redis缓存的连接池配置Redis是一个开源的内存数据结构存储系统,被广泛用于缓存和分布式数据共享。

为了更有效地使用Redis作为缓存系统,我们需要配置连接池以确保与Redis服务器的连接的有效性和性能。

连接池是一组已经建立的连接对象的集合,它们可以被重复使用,以减少建立和销毁连接的开销。

在使用Redis作为缓存的同时,连接池的合理配置能够显著提高系统的性能和可靠性。

**连接池的基本配置**在Redis的配置文件redis.conf中,我们可以找到连接池相关的配置项。

以下是一些常用的连接池配置项及其说明:1. **maxclients**:该配置项控制Redis最大的客户端连接数。

可以根据系统的负载情况和预计的客户端访问量进行调整。

默认值为10000,在高并发的情况下可能需要增加此值。

2. **tcp-backlog**:该配置项控制Redis服务器监听套接字的未完成连接队列的长度。

未完成连接队列是已经收到客户端连接请求,但还没有完成握手的连接。

根据系统的负载情况和预计的连接请求量进行调整。

默认值为511,可以根据实际情况适当增加。

3. **timeout**:该配置项设定了连接池的超时时间(单位为秒)。

当一个客户端连接idle超过该时间时,连接池会主动关闭该连接。

默认值为0,表示不超时。

根据业务需求和系统资源情况进行配置。

4. **tcp-keepalive**:该配置项设置是否开启TCP keepalive功能。

TCP keepalive用于检测连接的有效性,如果连接空闲时间过长,可能由于网络故障等原因导致连接断开。

通过设置该配置项为一个非零值,可以启用TCP keepalive功能,并指定检测的时间间隔。

默认值为0,表示不开启。

5. **tcp-keepalive-interval**:该配置项指定了TCP keepalive探测的间隔时间(单位为秒)。

只有在tcp-keepalive开启的情况下才有效。

redis连接参数

redis连接参数

redis连接参数Redis是一款非常流行的开源内存数据库。

它支持多种数据结构,并提供了非常快速的读写性能。

Redis不仅可以缓存数据,还可以用于消息队列、计数器、分布式锁等场景。

在使用Redis时,需要设置连接参数来保证安全性、性能和可靠性。

本文将详细介绍Redis连接参数,帮助您更好地理解Redis。

安全性参数1. requirepass密码:Redis通过密码验证来保证连接的安全性。

在redis.conf配置文件中可以设置requirepass选项,如:requirepass yourpassword这样,每次客户端连接Redis时都必须提供正确的密码才能进行操作。

这可以有效保护Redis的数据安全性。

2. bind地址:bind选项用于设置Redis服务端所监听的网络地址。

如果设置为127.0.0.1表示只能通过本地访问,其他网络无法访问,这也可以提高Redis的安全性。

如:bind 127.0.0.13. protected-mode模式:protected-mode模式是Redis默认的安全模式,当它被启用时,只允许来自本地或受信任网络的客户端连接。

如果你要使用外部客户端连接Redis,请把protected-mode设置为no。

1. maxmemory内存限制:Redis主要是基于内存进行存储,可以用maxmemory参数来设置最大可用内存大小,如:maxmemory 1gb这里设置最大可用内存为1GB。

2. maxmemory-policy策略:当Redis的内存使用达到上述maxmemory限制时,需要一种关于如何删除数据的策略。

其中最简单的是 noeviction 策略,它表示不会发生任何删除操作,而是会返回错误信息。

Redis还提供了多种其他策略选项,例如:allkeys-lru表示删除使用LRU算法的最少使用key,volatile-lru表示在过期交集中删除最少使用的key来腾出空间,volatile-ttl表示在过期交集中删除最少使用key的时间戳。

redis.conf配置说明

redis.conf配置说明

redis.conf配置说明当前所用Redis版本为2.6.14,以内Redis.conf中已有比较详细的注释,本文多为翻译,外加个人实际配置过程中遇到的一些问题。

基本设置1. 备释当配置中需要配置内存大小时,可以使用 1k, 5GB, 4M 等类似的格式,其转换方式如下(不区分大小写):•1k => 1000 bytes•1kb => 1024 bytes•1m => 1000000 bytes•1mb => 1024*1024 bytes•1g => 1000000000 bytes•1gb => 1024*1024*1024 bytes2. daemonize no默认情况下,redis不是在后台运行的,如果需要在后台运行,把该项的值更改为yes3. pidfile /var/run/redis.pid当redis在后台运行的时候,Redis默认会把pid文件放在/var/run/redis.pid,你可以配置到其他地址。

当运行多个redis服务时,需要指定不同的pid文件和端口。

4. port 6379指定redis运行的端口5. bind 127.0.0.1翻看网上的文章,此处多翻译为“指定redis只接收来自于该IP 地址的请求,如果不进行设置,那么将处理所有请求,在生产环境中最好设置该项”。

这种解释会totally搞糊涂初学者,甚至是错误的。

该处的英文原文为1 2 # If you want you can bind a single interface, if the bind option is not3 # specified all the interfaces will listen for incomingconnections.# bind 127.0.0.1该处说明bind的是interface,也就是说是网络接口。

服务器可以有一个网络接口(通俗的说网卡),或者多个。

Redis哨兵模式的配置

Redis哨兵模式的配置

Redis哨兵模式的配置绪论现有三台设备,192.168.137.11、192.168.137.12和192.168.137.13,要求在三台设备上实现redis哨兵模式,其中192.168.137.11为master,其他两台为slave。

1、在Master上配置redis.conf⽂件配置⽂件内容如下:protected-mode no (关闭保护模式)port 6379daemonize yes (设置redis在后台启动)pidfile /var/run/redis_6379.pidlogfile "/opt/module/redis/6379/logs/redis_6379.log" (设置⽇志⽂件的存放位置)dbfilename dump_6379.rdb (设置dump⽂件名)dir "/opt/module/redis/6379" (设置dump⽂件和nodes⽂件的存放位置)masterauth bigdata (设置集群节点间访问密码,跟上⾯⼀致)requirepass bigdata (设置redis访问密码)# bind 127.0.0.1 注释掉该项2.启动redis,并配置另外两台设备为slave分别启动三台设备上的redis,然后使⽤redis-cli在192.168.137.12和192.168.137.13分别执⾏如下命令,表⽰以192.168.137.11为masterslaveof 192.168.137.11 6379 查看配置 info replication可以发现master已经启动3.配置哨兵抽取redis压缩⽂件下的sentinel.conf⽂件到/opt/module/redis/(存放redis配置⽂件)下修改配置如下:sentinel monitor hadoop-101 192.168.137.11 6379 1上⾯最后⼀个数字1,表⽰主机挂掉后salve投票看让谁接替成为主机,得票数多少后成为主机将上⾯的配置同步到其他两台机器上,并且修改Ip为被同步机器的IP。

redis集群配置参数及优化

redis集群配置参数及优化

Redis集群配置参数及优化Redis的主要参数配置在redis.conf文件中。

1.conf内存值2.bindip默认情况下,如果没有指定“bind”配置指令,Redis将侦听服务器上可用的所有网络接口的连接。

默认情况:bind127.0.0.1实际配置:bind本机ip3.protected-modeyes启用默认保护模式。

只有当您确定您希望其他主机的客户端连接到Redis 时,您才应该禁用它,即使没有配置身份验证,也没有使用“bind”指令显式列出特定的接口集。

4.tcp-keepalive300如果非零,请使用SO_KEEPALIVE向没有通信的客户发送TCP协议。

这很有用,有两个原因:a)检测死同伴b)从中间的网络设备的角度进行连接在Linux上,指定的值(以秒为单位)是用于发送ack的周期。

注意,要关闭连接,需要双倍的时间。

这个选项的合理值是300秒,这是新的Redis默认值,从Redis3.2.1开始。

5.timeout0在客户机空闲N秒后关闭连接(0到禁用)6.port6379在指定端口上接受连接,默认值是63797.daemonizeyesredis后台运行8.pidfile/var/run/redis_6379.pid如果指定了一个pid文件,Redis会在启动时指定,并在退出时删除它。

当服务器运行非守护进程时,如果配置中没有指定pid文件,则不会创建pid文件。

当服务器被守护时,即使没有指定,也会使用pid文件,默认为“/var/run/redis.pid”。

创建一个pid文件是最好的工作:如果Redis不能创建它,那么服务器就会正常启动和运行。

9.loglevelnotice指定服务器冗余级别包括:a)debug:大量信息,用于开发/测试b)verbose:许多很少有用的信息,但不像debug级别那样混乱c)notice:适度详细,可能在生产中需要d)warning:只有非常重要/关键的消息被记录10.logfile""指定日志文件名。

redis的config命令及配置

redis的config命令及配置

redis的config命令及配置Redis 配置Redis 的配置⽂件位于 Redis 安装⽬录下,⽂件名为 redis.conf。

你可以通过 CONFIG 命令查看或设置配置项。

语法Redis CONFIG 命令格式如下:redis 127.0.0.1:6379> CONFIG GET CONFIG_SETTING_NAME实例redis 127.0.0.1:6379> CONFIG GET loglevel1) "loglevel"2) "notice"使⽤ * 号获取所有配置项:实例redis 127.0.0.1:6379> CONFIG GET *1) "dbfilename"2) "dump.rdb"3) "requirepass"4) ""5) "masterauth"6) ""7) "unixsocket"8) ""9) "logfile"10) ""11) "pidfile"12) "/var/run/redis.pid"13) "maxmemory"14) "0"15) "maxmemory-samples"16) "3"17) "timeout"18) "0"19) "tcp-keepalive"20) "0"21) "auto-aof-rewrite-percentage"22) "100"23) "auto-aof-rewrite-min-size"24) "67108864"25) "hash-max-ziplist-entries"26) "512"27) "hash-max-ziplist-value"28) "64"29) "list-max-ziplist-entries"30) "512"31) "list-max-ziplist-value"32) "64"33) "set-max-intset-entries"34) "512"35) "zset-max-ziplist-entries"36) "128"37) "zset-max-ziplist-value"38) "64"39) "hll-sparse-max-bytes"40) "3000"41) "lua-time-limit"42) "5000"43) "slowlog-log-slower-than"44) "10000"45) "latency-monitor-threshold"46) "0"47) "slowlog-max-len"48) "128"49) "port"50) "6379"51) "tcp-backlog"52) "511"53) "databases"54) "16"55) "repl-ping-slave-period"56) "10"57) "repl-timeout"58) "60"59) "repl-backlog-size"60) "1048576"61) "repl-backlog-ttl"62) "3600"63) "maxclients"64) "4064"65) "watchdog-period"66) "0"67) "slave-priority"68) "100"69) "min-slaves-to-write"70) "0"71) "min-slaves-max-lag"72) "10"73) "hz"74) "10"75) "no-appendfsync-on-rewrite"76) "no"77) "slave-serve-stale-data"78) "yes"79) "slave-read-only"80) "yes"81) "stop-writes-on-bgsave-error"82) "yes"83) "daemonize"84) "no"85) "rdbcompression"86) "yes"87) "rdbchecksum"88) "yes"89) "activerehashing"90) "yes"91) "repl-disable-tcp-nodelay"92) "no"93) "aof-rewrite-incremental-fsync"94) "yes"95) "appendonly"96) "no"97) "dir"98) "/home/deepak/Downloads/redis-2.8.13/src"99) "maxmemory-policy"100) "volatile-lru"101) "appendfsync"102) "everysec"103) "save"104) "3600 1 300 100 60 10000"105) "loglevel"106) "notice"107) "client-output-buffer-limit"108) "normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60" 109) "unixsocketperm"110) "0"111) "slaveof"112) ""113) "notify-keyspace-events"114) ""115) "bind"116) ""编辑配置你可以通过修改 redis.conf ⽂件或使⽤ CONFIG set 命令来修改配置。

Redis及其Sentinel配置项详细说明

Redis及其Sentinel配置项详细说明

13.dir ./
指定本地数据库存放目录
14. slaveof <masterip> <masterport>
设置当本机为slave服务时,设置master服务的IP地址及端口,在Redis启动时,它会自动从master进行数据同步
15.slave-serve-stable-data yes
11.rdbcompression yes
指定存储至本地数据库时是否压缩数据,默认为yes,Redis采用LZF压缩,如果为了节省CPU时间,可以关闭该选项,但会导致数据库文件变的巨大
12.dbfilename dump.rdb
指定本地数据库文件名,默认值为dump.rdb
3.port 6379
指定Redis监听端口,默认端口为6379,作者在自己的一篇博文中解释了为什么选用6379作为默认端口,因为6379在手机按键上MERZ对应的号码,而MERZ取自意大利歌女Alessia Merz的名字
4.bind 127.0.0.1
绑定的主机地址
maxmemory-policy (noeviction | allkeys-lru | volatile-lru | allkeys-random | volatile-random | volatile-ttl)
当内存到达阀值时redis对于会增加内存的命令的处理策略:
noeviction:返回错误
设置Redis连接密码,如果配置了连接密码,客户端在连接Redis时需要通过masterauth提供密码,默认关闭
27 maxclients 128
设置同一时间最大客户端连接数,默认无限制,Redis可以同时打开的客户端连接数为Redis进程可以打开的最大文件描述符数,如果设置 maxclients 0,表示不作限制。当客户端连接数到达限制时,Redis会关闭新的连接并向客户端返回max number of clients reached错误信息

redis.conf配置文件详解

redis.conf配置文件详解

redis.conf配置⽂件详解# Redis 配置⽂件⽰例# 注意单位: 当需要配置内存⼤⼩时, 可能需要指定像1k,5GB,4M等常见格式## 1k => 1000 bytes# 1kb => 1024 bytes# 1m => 1000000 bytes# 1mb => 1024*1024 bytes# 1g => 1000000000 bytes# 1gb => 1024*1024*1024 bytes## 单位是对⼤⼩写不敏感的 1GB 1Gb 1gB 是相同的。

################################## INCLUDES #################################### 可以在这⾥包含⼀个或多个其他的配置⽂件。

如果你有⼀个适⽤于所有Redis服务器的标准配置模板# 但也需要⼀些每个服务器⾃定义的设置,这个功能将很有⽤。

被包含的配置⽂件也可以包含其他配置⽂件,# 所以需要谨慎的使⽤这个功能。

## 注意“inclue”选项不能被admin或Redis哨兵的"CONFIG REWRITE"命令重写。

# 因为Redis总是使⽤最后解析的配置⾏最为配置指令的值, 你最好在这个⽂件的开头配置includes来# 避免它在运⾏时重写配置。

# 如果相反你想⽤includes的配置覆盖原来的配置,你最好在该⽂件的最后使⽤include## include /path/to/local.conf# include /path/to/other.conf################################ GENERAL ###################################### 默认Rdis不会作为守护进程运⾏。

如果需要的话配置成'yes'# 注意配置成守护进程后Redis会将进程号写⼊⽂件/var/run/redis.piddaemonize no# 当以守护进程⽅式运⾏时,默认Redis会把进程ID写到 /var/run/redis.pid。

redis配置文件redis.conf详解

redis配置文件redis.conf详解

Redis配置文件redis.conf 详解Redis配置文件redis.conf 详解1.基本配置内存单位的表示# 1k =&gt; 1000 bytes# 1kb =&gt; 1024 bytes# 1m =&gt; 1000000 bytes# 1mb =&gt; 1024*1024 bytes# 1g =&gt; 1000000000 bytes# 1gb =&gt; 1024*1024*1024 bytes单位中不区分大小写1GB 1Gb 1gB是一样的后台运行,yes是后台运行,no前台运行,将输出,输出到终端(默认)daemonize yes如果daemonize参数为yes的话就会产生pid文件,一下是pid文件的定义pidfile /usr/local/redis-master/run/redis.pid监听的端口port 6379绑定监听的IP地址bind 127.0.0.1如果在本地调用redis可以直接用sock文件unixsocket /tmp/redis.sock //sock文件的位置unixsocketperm 755 //sock文件的权限如果一个链接在N秒内是空闲的,就将其关闭timeout 0如果对方down了或者中间网络断了发送ACK到客户端在指定的时间内没有收到对方的回应就断开TCP链接(时间单位秒记),此参数会受到内核参数的影响,推荐配置60。

tcp-keepalive 0指定输出消息的级别# debug (调试级别,详细信息,信息量大)# verbose (详细信息,信息量较大)# notice (通知,生产环境推荐)# warning (错误信息警告信息)loglevel notice日志输出文件,默认在前端运行的时候此key的默认值是stdout输出到终端,如果用守护进程运行此key的stdout 的时候将日志输入到/dev/null,如果想记录日志,就必须为其指定logfile位置logfile /var/log/redis.log将日志记录的哦syslogsyslog-enabled no指定syslog的身份syslog-ident redis指定syslog的级别,必须是LOCAL0-LOCAL7之间syslog-facility local0设置数据库的数量databases 16设置数据库的数量。

redis.conf配置详细解析

redis.conf配置详细解析

redis.conf配置详细解析-# redis 配置⽂件⽰例# 当你需要为某个配置项指定内存⼤⼩的时候,必须要带上单位,# 通常的格式就是 1k 5gb 4m 等酱紫:## 1k => 1000 bytes# 1kb => 1024 bytes# 1m => 1000000 bytes# 1mb => 1024*1024 bytes# 1g => 1000000000 bytes# 1gb => 1024*1024*1024 bytes## 单位是不区分⼤⼩写的,你写 1K 5GB 4M 也⾏################################## INCLUDES #################################### 假如说你有⼀个可⽤于所有的 redis server 的标准配置模板,# 但针对某些 server ⼜需要⼀些个性化的设置,# 你可以使⽤ include 来包含⼀些其他的配置⽂件,这对你来说是⾮常有⽤的。

## 但是要注意哦,include 是不能被 config rewrite 命令改写的# 由于 redis 总是以最后的加⼯线作为⼀个配置指令值,所以你最好是把 include 放在这个⽂件的最前⾯,# 以避免在运⾏时覆盖配置的改变,相反,你就把它放在后⾯(外国⼈真啰嗦)。

## include /path/to/local.conf# include /path/to/other.conf################################ 常⽤ ###################################### 默认情况下 redis 不是作为守护进程运⾏的,如果你想让它在后台运⾏,你就把它改成 yes。

# 当redis作为守护进程运⾏的时候,它会写⼀个 pid 到 /var/run/redis.pid ⽂件⾥⾯。

Redis之配置文件redis.conf

Redis之配置文件redis.conf

Redis之配置⽂件redis.conf解读下 redis.conf 配置⽂件中常⽤的配置项,为不显得过于臃长,已选择性删除原配置⽂件中部分注释。

# Redis must be started with the file path as first argument:# ./redis-server /path/to/redis.conf## redis中的度量单位只⽀持bytes,不⽀持bit,⼤⼩写不敏感,且 k/kb、m/mb、g/gb 代表的单位⼤⼩有所不同。

# 1k => 1000 bytes# 1kb => 1024 bytes# 1m => 1000000 bytes# 1mb => 1024*1024 bytes# 1g => 1000000000 bytes# 1gb => 1024*1024*1024 bytes################################## INCLUDES #################################### ⽤于引⼊其他配置⽂件,和本配置⽂件中配置共同配置redis服务# include /path/to/local.conf# include /path/to/other.conf################################## MODULES ###################################### Load modules at startup. If the server is not able to load modules# it will abort. It is possible to use multiple loadmodule directives.## loadmodule /path/to/my_module.so# loadmodule /path/to/other_module.so################################## NETWORK ###################################### By default, if no "bind" configuration directive is specified, Redis listens# for connections from all the network interfaces available on the server.# It is possible to listen to just one or multiple selected interfaces using# the "bind" configuration directive, followed by one or more IP addresses.## Examples:## bind 192.168.1.100 10.0.0.1# bind 127.0.0.1 ::1## ~~~ 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 into# the IPv4 loopback interface address (this means Redis will be able to# accept connections only from clients running into the same computer it# is running).## IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES# JUST COMMENT THE FOLLOWING LINE.# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~bind127.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# 服务启动端⼝,默认为 6379 ,如果设置端⼝为 0 ,redis 服务将不会监听任何TCP连接port 6379# 设置TCP的连接队列 backlog ,默认为 511 ,backlog 队列总和 = 未完成三次握⼿队列 + 已完成三次握⼿队列# 作⽤:在⾼并发环境中,设置⾼ backlog 值,来避免慢客户端的连接# 设置⽅式:(1)设置 /proc/sys/net/core/somaxconn (2)设置 tcp_max_syn_backlog# Linux内核会将 tcp_max_syn_backlog 的值减⼩到 somaxconn ,故需要同时设置# tcp_max_syn_backlog 1024tcp-backlog 511# 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 /tmp/redis.sock# unixsocketperm 700# 当客户端超过N秒空闲后,服务器主动断开连接,设置为 0 表⽰不主动断开连接timeout 0# 检测 TCP 连接alive状态的频率,设置为0表⽰不检测,建议设置为60tcp-keepalive 300################################# GENERAL ###################################### 设置redis服务以后台守护进程启动,默认为 no⾮daemon# 后台启动后服务的 pid 位于⽂件 /var/run/redis 中daemonize no# If you run Redis from upstart or systemd, Redis can interact with your# supervision tree. Options:# supervised no - no supervision interaction# supervised upstart - signal upstart by putting Redis into SIGSTOP mode# supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET# supervised auto - detect upstart or systemd method based on# UPSTART_JOB or NOTIFY_SOCKET environment variables# Note: these supervision methods only signal "process is ready."# They do not enable continuous liveness pings back to your supervisor.supervised no# 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.pidfile /var/run/redis_6379.pid# 设置输出⽇志级别,包括 debug、verbos、notice、warningloglevel notice# 设置⽇志输出⽂件,若为空字符串"" 或者 stdout ,则将⽇志从定位到 /dev/nulllogfile ""# 若要将redis⽇志记录到系统⽇志,将此参数设置为 yes# syslog-enabled no# ⽤于指定⽇志标识:若开启系统⽇志,指定⽇志以 redis 开头# syslog-ident redis# 设置系统⽇志输出设备,值可为 USER 或者 LOCAL0-LOCAL7,默认为local0# syslog-facility local0# 设置 redis 服务启动数据库的个数,默认 16 个,默认数据库为 DB 0 ,可使⽤ select <dbid> 进⾏切库,dbid为 0 ⾄ databases-1databases 16# 是否总是显⽰redis那个"蛋糕"logoalways-show-logo yes################################ SNAPSHOTTING ################################# 指定在规定时间内,有多少此更新操作,就将数据同步⾄数据⽂件,可多个条件配合使⽤# save <seconds> <changes># save ""# 默认配置如下:15分钟内有⼀个更改,5分钟内有10个更改,1分钟内有10000个更改save 9001save 30010save 6010000# 当RDB在后台持久化出错后,是否依然进⾏数据库写操作,yes:停⽌写操作,no:继续写操作stop-writes-on-bgsave-error yes# 指定存储⾄本地数据库时是否压缩数据,默认为yes:使⽤压缩,redis采⽤LZF压缩算法,使⽤会消耗CPU,不使⽤占内存rdbcompression yes# 是否校验压缩后的rdb⽂件,默认为yes:进⾏校验,开启⼤概有10%性能损耗rdbchecksum yes# 指定本地数据库⽂件名,默认为dump.rdbdbfilename dump.rdb# 指定本地数据⽂件存放⽬录dir ./################################# REPLICATION ################################## 将当前服务器作为从库,同步备份主库的数据,并提供读操作# replicaof <masterip> <masterport># replicaof 10.7.5.74 6379# 当master服务设置了密码保护时,slave服务连接master的密码# masterauth <master-password># When a replica loses its connection with the master, or when the replication# is still in progress, the replica can act in two different ways:## 1) if replica-serve-stale-data is set to 'yes' (the default) the replica will# still reply to client requests, possibly with out of date data, or the# data set may just be empty if this is the first synchronization.## 2) if replica-serve-stale-data is set to 'no' the replica will reply with# an error "SYNC with master in progress" to all the kind of commands# but to INFO, replicaOF, AUTH, PING, SHUTDOWN, REPLCONF, ROLE, CONFIG,# SUBSCRIBE, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBLISH, PUBSUB,# COMMAND, POST, HOST: and LATENCY.#replica-serve-stale-data yes# You can configure a replica instance to accept writes or not. Writing against# a replica instance may be useful to store some ephemeral data (because data# written on a replica will be easily deleted after resync with the master) but# may also cause problems if clients are writing to it because of a# misconfiguration.## Since Redis 2.6 by default replicas are read-only.## Note: read only replicas are not designed to be exposed to untrusted clients# on the internet. It's just a protection layer against misuse of the instance.# Still a read only replica exports by default all the administrative commands# such as CONFIG, DEBUG, and so forth. To a limited extent you can improve# security of read only replicas using 'rename-command' to shadow all the# administrative / dangerous commands.replica-read-only yes# Replication SYNC strategy: disk or socket.## -------------------------------------------------------# WARNING: DISKLESS REPLICATION IS EXPERIMENTAL CURRENTLY# -------------------------------------------------------## New replicas and reconnecting replicas that are not able to continue the replication # process just receiving differences, need to do what is called a "full# synchronization". An RDB file is transmitted from the master to the replicas.# The transmission can happen in two different ways:## 1) Disk-backed: The Redis master creates a new process that writes the RDB# file on disk. Later the file is transferred by the parent# process to the replicas incrementally.# 2) Diskless: The Redis master creates a new process that directly writes the# RDB file to replica sockets, without touching the disk at all.## With disk-backed replication, while the RDB file is generated, more replicas# can be queued and served with the RDB file as soon as the current child producing # the RDB file finishes its work. With diskless replication instead once# the transfer starts, new replicas arriving will be queued and a new transfer# will start when the current one terminates.## When diskless replication is used, the master waits a configurable amount of# time (in seconds) before starting the transfer in the hope that multiple replicas# will arrive and the transfer can be parallelized.## With slow disks and fast (large bandwidth) networks, diskless replication# works better.repl-diskless-sync no# When diskless replication is enabled, it is possible to configure the delay# the server waits in order to spawn the child that transfers the RDB via socket# to the replicas.## This is important since once the transfer starts, it is not possible to serve# new replicas arriving, that will be queued for the next RDB transfer, so the server # waits a delay in order to let more replicas arrive.## The delay is specified in seconds, and by default is 5 seconds. To disable# it entirely just set it to 0 seconds and the transfer will start ASAP.repl-diskless-sync-delay 5# Replicas send PINGs to server in a predefined interval. It's possible to change# this interval with the repl_ping_replica_period option. The default value is 10# seconds.## repl-ping-replica-period 10# The following option sets the replication timeout for:## 1) Bulk transfer I/O during SYNC, from the point of view of replica.# 2) Master timeout from the point of view of replicas (data, pings).# 3) Replica timeout from the point of view of masters (REPLCONF ACK pings).## It is important to make sure that this value is greater than the value# specified for repl-ping-replica-period otherwise a timeout will be detected# every time there is low traffic between the master and the replica.## repl-timeout 60# Disable TCP_NODELAY on the replica socket after SYNC?## If you select "yes" Redis will use a smaller number of TCP packets and# less bandwidth to send data to replicas. But this can add a delay for# the data to appear on the replica side, up to 40 milliseconds with# Linux kernels using a default configuration.## If you select "no" the delay for data to appear on the replica side will# be reduced but more bandwidth will be used for replication.## By default we optimize for low latency, but in very high traffic conditions# or when the master and replicas are many hops away, turning this to "yes" may # be a good idea.repl-disable-tcp-nodelay no# Set the replication backlog size. The backlog is a buffer that accumulates# replica data when replicas are disconnected for some time, so that when a replica # wants to reconnect again, often a full resync is not needed, but a partial# resync is enough, just passing the portion of data the replica missed while# disconnected.## The bigger the replication backlog, the longer the time the replica can be# disconnected and later be able to perform a partial resynchronization.## The backlog is only allocated once there is at least a replica connected.## repl-backlog-size 1mb# After a master has no longer connected replicas for some time, the backlog# will be freed. The following option configures the amount of seconds that# need to elapse, starting from the time the last replica disconnected, for# the backlog buffer to be freed.## Note that replicas never free the backlog for timeout, since they may be# promoted to masters later, and should be able to correctly "partially# resynchronize" with the replicas: hence they should always accumulate backlog. ## A value of 0 means to never release the backlog.## repl-backlog-ttl 3600# The replica priority is an integer number published by Redis in the INFO output. # It is used by Redis Sentinel in order to select a replica to promote into a# master if the master is no longer working correctly.## A replica with a low priority number is considered better for promotion, so# for instance if there are three replicas with priority 10, 100, 25 Sentinel will# pick the one with priority 10, that is the lowest.## However a special priority of 0 marks the replica as not able to perform the# role of master, so a replica with priority of 0 will never be selected by# Redis Sentinel for promotion.## By default the priority is 100.replica-priority 100# It is possible for a master to stop accepting writes if there are less than# N replicas connected, having a lag less or equal than M seconds.## The N replicas need to be in "online" state.## The lag in seconds, that must be <= the specified value, is calculated from# the last ping received from the replica, that is usually sent every second.## This option does not GUARANTEE that N replicas will accept the write, but# will limit the window of exposure for lost writes in case not enough replicas# are available, to the specified number of seconds.## For example to require at least 3 replicas with a lag <= 10 seconds use:## min-replicas-to-write 3# min-replicas-max-lag 10## Setting one or the other to 0 disables the feature.## By default min-replicas-to-write is set to 0 (feature disabled) and# min-replicas-max-lag is set to 10.# A Redis master is able to list the address and port of the attached# replicas in different ways. For example the "INFO replication" section# offers this information, which is used, among other tools, by# Redis Sentinel in order to discover replica instances.# Another place where this info is available is in the output of the# "ROLE" command of a master.## The listed IP and address normally reported by a replica is obtained# in the following way:## IP: The address is auto detected by checking the peer address# of the socket used by the replica to connect with the master.## Port: The port is communicated by the replica during the replication# handshake, and is normally the port that the replica is using to# listen for connections.## However when port forwarding or Network Address Translation (NAT) is# used, the replica may be actually reachable via different IP and port# pairs. The following two options can be used by a replica in order to# report to its master a specific set of IP and port, so that both INFO# and ROLE will report those values.## There is no need to use both the options if you need to override just# the port or the IP address.## replica-announce-ip 5.5.5.5# replica-announce-port 1234################################## SECURITY #################################### 登录 redis 数据库密码认证问题# 执⾏命令 config get requirepass ,获取配置⽂件中默认认证密码,默认密码为 foobared# requirepass foobared# 执⾏命令 config set requirepass "redis" ,设置认证密码为 redis ,设置为空 "" 表⽰不认证# 在执⾏命令前使⽤ auth <password> 命令进⾏认证# 禁⽌远程修改 DB ⽂件地址,就是对命令进⾏权限控制# 将命令重命名为空 "",表⽰禁⽤该命令# rename-command FLASHALL ""# 也可将命令重命名为 qazwsx741852edc ,然后将此名授权给特定⽤户使⽤即可# rename-command CONFIG "qazwsx741852edc"################################### CLIENTS ##################################### 设置客户端默认最⼤连接数,设置为0表⽰不限制,默认为10000# maxclients 10000############################## MEMORY MANAGEMENT ################################# 设置 redis 最⼤内存容量# maxmemory <bytes># 内存达到上限的处理策略(lru means Least Recently Used<最近最少>,lfu means Least Frequently Used<最不常>)# volatile-lru -> 利⽤LRU算法移除设置过过期时间的key# allkeys-lru -> 利⽤LRU算法移除任何key# volatile-lfu -> 利⽤LFU算法移除设置过过期时间的key# allkeys-lfu -> 利⽤LFU算法移除任何key# volatile-random -> 随机移除设置过过期时间的key# allkeys-random -> 随机移除所有key# volatile-ttl -> 移除即将过期的key# noeviction -> 不移除key,返回报错就⾏# 默认为不移除key策略# maxmemory-policy noeviction# 设置每次移除时的样本⼤⼩,默认5个:每次移除时选取5个样本,移除其中符合策略的key# maxmemory-samples 5# 从节点是否忽略maxmemory设置的值# replica-ignore-maxmemory yes############################# LAZY FREEING ##################################### Redis has two primitives to delete keys. One is called DEL and is a blocking# deletion of the object. It means that the server stops processing new commands# in order to reclaim all the memory associated with an object in a synchronous# way. If the key deleted is associated with a small object, the time needed# in order to execute the DEL command is very small and comparable to most other# O(1) or O(log_N) commands in Redis. However if the key is associated with an# aggregated value containing millions of elements, the server can block for# a long time (even seconds) in order to complete the operation.## For the above reasons Redis also offers non blocking deletion primitives# such as UNLINK (non blocking DEL) and the ASYNC option of FLUSHALL and# FLUSHDB commands, in order to reclaim memory in background. Those commands# are executed in constant time. Another thread will incrementally free the# object in the background as fast as possible.## DEL, UNLINK and ASYNC option of FLUSHALL and FLUSHDB are user-controlled.# It's up to the design of the application to understand when it is a good# idea to use one or the other. However the Redis server sometimes has to# delete keys or flush the whole database as a side effect of other operations.# Specifically Redis deletes objects independently of a user call in the# following scenarios:## 1) On eviction, because of the maxmemory and maxmemory policy configurations,# in order to make room for new data, without going over the specified# memory limit.# 2) Because of expire: when a key with an associated time to live (see the# EXPIRE command) must be deleted from memory.# 3) Because of a side effect of a command that stores data on a key that may# already exist. For example the RENAME command may delete the old key# content when it is replaced with another one. Similarly SUNIONSTORE# or SORT with STORE option may delete existing keys. The SET command# itself removes any old content of the specified key in order to replace# it with the specified string.# 4) During replication, when a replica performs a full resynchronization with# its master, the content of the whole database is removed in order to# load the RDB file just transferred.## In all the above cases the default is to delete objects in a blocking way,# like if DEL was called. However you can configure each case specifically# in order to instead release memory in a non-blocking way like if UNLINK# was called, using the following configuration directives:lazyfree-lazy-eviction nolazyfree-lazy-expire nolazyfree-lazy-server-del noreplica-lazy-flush no############################## APPEND ONLY MODE ################################ 指定是否在每次更新操作后进⾏⽇志记录,redis默认异步将数据写⼊磁盘,不开启会导致断电时⼀段时间内的数据丢失,默认no appendonly no# 指定更新⽇志⽂件名,默认为appendonly.aofappendfilename "appendonly.aof"# 指定更新⽇志条件,建议使⽤ "everysec"# "always":同步持久化,每次发⽣数据更改会⽴即调⽤fsync()⽅法将数据写⼊磁盘,数据完整性好,性能差# "everysec":默认值,异步同步,每秒同步⼀次,若⼀秒内宕机,则存在数据丢失# "no":永不# appendfsync alwaysappendfsync everysec# appendfsync no# 重写时,是否可以使⽤appendfsync(接受客户端的写操作),默认为 no ,保证数据安全性no-appendfsync-on-rewrite no# redis会记录上次重写AOF⽂件的⼤⼩,当AOF⽂件增加⾄上次重写⽂件的 100% 倍,且⼤⼩⼤于64MB时,触发AOF重写# auto-aof-rewrite-percentage ⽤于设置相对于上次AOF⽂件百分⽐,auto-aof-rewrite-min-size ⽤于设置另⼀基准值auto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mb# An AOF file may be found to be truncated at the end during the Redis# startup process, when the AOF data gets loaded back into memory.# This may happen when the system where Redis is running# crashes, especially when an ext4 filesystem is mounted without the# data=ordered option (however this can't happen when Redis itself# crashes or aborts but the operating system still works correctly).## Redis can either exit with an error when this happens, or load as much# data as possible (the default now) and start if the AOF file is found# to be truncated at the end. The following option controls this behavior.## If aof-load-truncated is set to yes, a truncated AOF file is loaded and# the Redis server starts emitting a log to inform the user of the event.# Otherwise if the option is set to no, the server aborts with an error# and refuses to start. When the option is set to no, the user requires# to fix the AOF file using the "redis-check-aof" utility before to restart# the server.## Note that if the AOF file will be found to be corrupted in the middle# the server will still exit with an error. This option only applies when# Redis will try to read more data from the AOF file but not enough bytes# will be found.aof-load-truncated yes# When rewriting the AOF file, Redis is able to use an RDB preamble in the# AOF file for faster rewrites and recoveries. When this option is turned# on the rewritten AOF file is composed of two different stanzas:## [RDB file][AOF tail]## When loading Redis recognizes that the AOF file starts with the "REDIS"# string and loads the prefixed RDB file, and continues loading the AOF# tail.aof-use-rdb-preamble yes################################ LUA SCRIPTING ############################### # Max execution time of a Lua script in milliseconds.## If the maximum execution time is reached Redis will log that a script is# still in execution after the maximum allowed time and will start to# reply to queries with an error.## When a long running script exceeds the maximum execution time only the# SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be# used to stop a script that did not yet called write commands. The second# is the only way to shut down the server in the case a write command was# already issued by the script but the user doesn't want to wait for the natural# termination of the script.## Set it to 0 or a negative value for unlimited execution without warnings.lua-time-limit 5000################################ REDIS CLUSTER ############################### ## ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # WARNING EXPERIMENTAL: Redis Cluster is considered to be stable code, however# in order to mark it as "mature" we need to wait for a non trivial percentage# of users to deploy it in production.# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ## Normal Redis instances can't be part of a Redis Cluster; only nodes that are# started as cluster nodes can. In order to start a Redis instance as a# cluster node enable the cluster support uncommenting the following:## cluster-enabled yes# Every cluster node has a cluster configuration file. This file is not# intended to be edited by hand. It is created and updated by Redis nodes.# Every Redis Cluster node requires a different cluster configuration file.# Make sure that instances running in the same system do not have# overlapping cluster configuration file names.## cluster-config-file nodes-6379.conf# Cluster node timeout is the amount of milliseconds a node must be unreachable # for it to be considered in failure state.# Most other internal time limits are multiple of the node timeout.## cluster-node-timeout 15000# A replica of a failing master will avoid to start a failover if its data# looks too old.## There is no simple way for a replica to actually have an exact measure of# its "data age", so the following two checks are performed:## 1) If there are multiple replicas able to failover, they exchange messages# in order to try to give an advantage to the replica with the best# replication offset (more data from the master processed).# Replicas will try to get their rank by offset, and apply to the start# of the failover a delay proportional to their rank.## 2) Every single replica computes the time of the last interaction with# its master. This can be the last ping or command received (if the master# is still in the "connected" state), or the time that elapsed since the# disconnection with the master (if the replication link is currently down).# If the last interaction is too old, the replica will not try to failover# at all.## The point "2" can be tuned by user. Specifically a replica will not perform# the failover if, since the last interaction with the master, the time# elapsed is greater than:## (node-timeout * replica-validity-factor) + repl-ping-replica-period## So for example if node-timeout is 30 seconds, and the replica-validity-factor# is 10, and assuming a default repl-ping-replica-period of 10 seconds, the# replica will not try to failover if it was not able to talk with the master# for longer than 310 seconds.## A large replica-validity-factor may allow replicas with too old data to failover# a master, while a too small value may prevent the cluster from being able to# elect a replica at all.## For maximum availability, it is possible to set the replica-validity-factor# to a value of 0, which means, that replicas will always try to failover the# master regardless of the last time they interacted with the master.# (However they'll always try to apply a delay proportional to their# offset rank).## Zero is the only value able to guarantee that when all the partitions heal# the cluster will always be able to continue.## cluster-replica-validity-factor 10# Cluster replicas are able to migrate to orphaned masters, that are masters# that are left without working replicas. This improves the cluster ability# to resist to failures as otherwise an orphaned master can't be failed over# in case of failure if it has no working replicas.## Replicas migrate to orphaned masters only if there are still at least a# given number of other working replicas for their old master. This number# is the "migration barrier". A migration barrier of 1 means that a replica# will migrate only if there is at least 1 other working replica for its master# and so forth. It usually reflects the number of replicas you want for every# master in your cluster.## Default is 1 (replicas migrate only if their masters remain with at least# one replica). To disable migration just set it to a very large value.# A value of 0 can be set but is useful only for debugging and dangerous# in production.。

Redis篇3-redis.conf配置

Redis篇3-redis.conf配置

Redis篇3-redis.conf配置官⽅的redis.conf配置⽂件⼗分完事,且注释说明很详细到位,我们可以根据提⽰块,快速锁定⽬标配置项。

真正使⽤时,第⼀注意备份默认配置⽂件,第⼆覆盖或者注释掉⼀些仅适⽤于练习测试⽤的默认配置项,⽐如最⼤客户端数、最⼤内存接近处理策略等。

整理常⽤配置项说明如下:INCLUDES 多配置⽂件类⽐nginx配置,我们可以以默认的为主框架配置,然后使⽤include /xx/xx.conf将其他模块配置包含进来NETWORK ⽹络相关配置port 6379redis服务启动端⼝配置,m默认6379tcp-backlog 511连接队列⼤⼩配置,根据官⽅注释说明:⾼并发场景下需要⼀个tpc队列来避免慢客户端连接的问题,这⾥默认值为511但是,Linux内核将⾃动将其截断为/proc/sys/net/core/somaxconn的值,所以,如果系统的tps很⼤,需要同时调整/proc/sys/net/core/somaxconn和tcp-backlog来达到效果bind 127.0.0.1配置暴露给哪些客户端连接服务,默认只能本机作为客户端连接。

如果允许任意机器连接,注掉所有bind配置即可,但是这时请单独配置redis密码。

如果指定⼏台机器才能访问,继续添加bind项即可。

timeout 0redis-cli客户端空闲超时断开连接的时间设置,默认0代表⼀直不断开连接tcp-keepalive 300tcp连接⼼跳确认时间设置,redis3.2.1开始默认推荐设置300秒(之前默认推荐是60秒)。

该值⾮0,则会redis服务端会在客户端没有动静时,周期性向客户端发送TCP-ACK信号,原因有俩(还不⼤懂啥意思):Detect dead peers.Take the connection alive from the point of view of network equipment in the middle.GENERAL 通⽤标准配置daemonize no是否以守护进程⽅式运⾏redis服务,默认为nopidfile /var/run/redis_6379.pid指定⽤于记录redis服务进程⽂件的位置。

redis配置文件详解

redis配置文件详解

redis配置⽂件详解Redis是⼀个⾼性能的key-value数据库。

Redis⽀持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可以再次加载进⾏使⽤。

Redis不仅仅⽀持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存储。

Redis⽀持数据的备份,即master-slave模式的数据备份。

 为了更好的使⽤redis,我们需要详细的了解redis配置⽂件及相关参数作⽤。

include /path/to/local.conf额外载⼊配置⽂件,如果有需要的话,可以开启此配置bind 127.0.0.1bind 192.168.1.100绑定redis服务器⽹卡IP,默认为127.0.0.1,即本地回环地址。

这样的话,访问redis服务只能通过本机的客户端连接,⽽⽆法通过远程连接。

如果bind选项为空的话,那会接受所有来⾃于可⽤⽹络接⼝的连接。

如上配置,绑定⼀个127.0.0.1的本机地址和192.168.1.100的外⽹地址。

protected-mode yes保护模式,默认是开启状态,只允许本地客户端连接,可以设置密码或添加bind来连接port 6379监听端⼝号,默认为6379,如果设为0,redis将不在socket 上监听任何客户端连接tcp-backlog 511TCP监听的最⼤容纳数量,在⾼并发的环境下,你需要把这个值调⾼以避免客户端连接缓慢的问题。

Linux 内核会把这个值缩⼩成/proc/sys/net/core/somaxconn对应的值,要提升并发量需要修改这两个值才能达到⽬的unixsocket /tmp/redis.sockunixsocketperm 700指定redis监听的unix socket路径,默认不启⽤,unixsocketper指定⽂件的权限timeout 0指定在⼀个 client 空闲多少秒之后关闭连接(0表⽰永不关闭)tcp-keepalive 300单位是秒,表⽰将周期性的使⽤SO_KEEPALIVE检测客户端是否还处于健康状态,避免服务器⼀直阻塞,官⽅给出的建议值是300s,如果设置为0,则不会周期性的检测daemonize yes默认情况下 redis 不是作为守护进程运⾏的,如果你想让它在后台运⾏,你就把它改成 yes。

Redis配置文件详解

Redis配置文件详解

Redis配置⽂件详解Redis.conf详解启动的时候,就是通过配置⽂件来启动的!单位单位1、配置⼤⼩单位,开头定义了⼀些基本的度量单位,只⽀持bytes,不⽀持bit2、对⼤⼩写不敏感INCLUDES 包含INCLUDES 包含和Spring配置⽂件类似,可以通过includes包含,redis.conf 可以作为总⽂件,可以包含其他⽂件!NETWORK ⽹络配置NETWORK ⽹络配置bind 127.0.0.1 # 绑定的ipprotected-mode yes # 保护模式port 6379 # 默认端⼝GENERAL 通⽤GENERAL 通⽤daemonize yes # 默认情况下,Redis不作为守护进程运⾏。

需要开启的话,改为 yes(开启就以后台的⽅式允许)supervised no # 可通过upstart和systemd管理Redis守护进程pidfile /var/run/redis_6379.pid # 以后台进程⽅式运⾏redis,则需要指定pid ⽂件loglevel notice # ⽇志级别。

可选项有:# debug(记录⼤量⽇志信息,适⽤于开发、测试阶段);# verbose(较多⽇志信息);# notice(适量⽇志信息,使⽤于⽣产环境);# warning(仅有部分重要、关键信息才会被记录)。

logfile "" # ⽇志⽂件的位置,当指定为空字符串时,为标准输出databases 16 # 设置数据库的数⽬。

默认的数据库是DB 0always-show-logo yes # 是否总是显⽰logoSNAPSHOPTING 快照SNAPSHOPTING 快照后⾯做持久化的时候会⽤到!在规定的时间内,有多少个key值变化,才会持久化到⽂件 .rdb⽂件或者.aof⽂件!redis是内存数据库,如果没有持久化,那么数据断电即失,所以需要持久化的机制!# 900秒(15分钟)内⾄少1个key值改变(则进⾏数据库保存--持久化)save 900 1# 300秒(5分钟)内⾄少10个key值改变(则进⾏数据库保存--持久化)save 300 10# 60秒(1分钟)内⾄少10000个key值改变(则进⾏数据库保存--持久化)save 60 10000stop-writes-on-bgsave-error yes # 持久化出现错误后,是否依然进⾏继续进⾏⼯作rdbcompression yes # 是否压缩rdb⽂件 yes:压缩,但是需要⼀些cpu的消耗。

8)详解Redis的配置文件以及数据持久化

8)详解Redis的配置文件以及数据持久化

8)详解Redis的配置文件以及数据持久化楔子Redis 的配置非常多,加上注释的话,配置文件大概一两千行,里面有大量的配置可以供我们进行设置。

其实关于Redis 的配置我们之前也提到过,比如:开启多线程、设置线程数、数据结构内部存储元素的数量限制等等,那么下面我们就来介绍一下Redis 配置文件中的一些其它的常见配置项。

配置文件不过提到了配置文件,这里再提一个命令,叫做config,是专门获取当前 Redis 配置项的。

127.0.0.1:6379> config get requirepass1) "requirepass"2) ""127.0.0.1:6379> config get dir1) "dir"2) "/root"127.0.0.1:6379>config get requirepass查看密码,如果没有设置的话会返回空字符串。

config get dir 查看 redis-server 的启动路径,我是在 /root 下启动的。

既然有 get,那就有 set。

127.0.0.1:6379> config set requirepass 123456OK # 设置密码,一旦设置立即生效127.0.0.1:6379> auth 12345 # 验证(error) WRONGPASS invalid username-password pair127.0.0.1:6379> auth 123456OK127.0.0.1:6379> config set requirepass ""OK # 这里我们再改回来127.0.0.1:6379>所以修改配置有两种方式,一种是直接在命令行中通过config set 进行修改,该方式修改之后会立即生效,但只会影响当前这一个客户端,其它客户端不受影响。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
loglevel 日志记录等级,有4个可选值,debug,verbose(默认值),notice,warning
logfile 日志记录方式,默认值为stdout
databases 可用数据库数,默认值为16,默认数据库为0
save <seconds> <changes> 指出在多长时间内,有多少次更新操作,就将数据同步到数据文件。这个可以多个条件配合,比如默认配置文件中的设置,就设置了三个条件。
save 900 1
900秒(15分钟)内至少有1个key被改变
save 300 10 300秒(5分钟)内至少有300个key被改变
save 60 10000 60秒内至少有10000个key被改变
rdbcompression 存储至本地数据库时是否压缩数据,默认为yes
dbfilename 本地数据库文件名,默认值为dump.rdb
maxclients 最大客户端连接数,默认不限制(注释)
maxmemory <bytes> 设置最大内存,达到最大内存设置后,Redis会先尝试清除已到期或即将到期的Key,当此方法处理后,任到达最大内存设置,将无法再进行写入操作。(注释)
appendonly 是否在每次更新操作后进行日志记录,如果不开启,可能会在断电时导致一段时间内的数据丢失。因为redis本身同步数据文件是按上面save条件来同步的,所以有的数据会在一段时间内只存在于内存中。默认值为no
hash-max-ziverehashing yes
Redis官方文档对VM的使用提出了一些建议: 当你的key很小而value很大时,使用VM的效果会比较好.因为这样节约的内存比较大. 当你的key不小时,可以考虑使用一些非常方法将很大的key变成很大的value,比如你可以考虑将key,value组合成一个新的value. 最好使用linux ext3 等对稀疏文件支持比较好的文件系统保存你的swap文件. vm-max-threads这个参数,可以设置访问swap文件的线程数,设置最好不要超过机器的核数.如果设置为0,那么所有对swap文件的操作都是串行的.可能会造成比较长时间的延迟,但是对数据完整性有很好的保证.
#最大客户端连接数
# maxclients 128
#最大内存使用率
# maxmemory <bytes>
########## APPEND ONLY FILE MODE #########
#是否开启日志功能
appendonly no
# 刷新日志到disk的规则
# appendfsync always
redis.conf配置选项如下
daemonize 是否以后台进程运行,默认为no
pidfile 如以后台进程运行,则需指定一个pid,默认为/var/run/redis.pid
bind 绑定主机IP,默认值为127.0.0.1(注释)
port 监听端口,默认为6379
timeout 超时时间,默认为300(秒)
appendfsync everysec
# appendfsync no
################ VIRTUAL MEMORY ###########
#是否开启VM功能
vm-enabled no
# vm-enabled yes
vm-swap-file logs/redis.swap
vm-max-memory 0
vm-page-size 32
vm-pages 134217728
vm-max-threads 4
############# ADVANCED CONFIG ###############
glueoutputbuf yes
hash-max-zipmap-entries 64
#当dump .rdb数据库的时候是否压缩数据对象
rdbcompression yes
#dump数据库的数据保存的文件名
dbfilename dump.rdb
#Redis的工作目录
dir /var/lib/redis/
########### Replication #####################
vm-enabled 是否使用虚拟内存,默认值为no
vm-swap-file 虚拟内存文件路径,默认值为/tmp/redis.swap,不可多个Redis实例共享
vm-max-memory 将所有大于vm-max-memory的数据存入虚拟内存,无论vm-max-memory设置多小,所有索引数据都是内存存储的(Redis的索引数据就是keys),也就是说,当vm-max-memory设置为0的时候,其实是所有value都存在于磁盘。默认值为0。
dir 本地数据库存放路径,默认值为 ./
slaveof <masterip> <masterport> 当本机为从服务时,设置主服务的IP及端口(注释)
masterauth <master-password> 当本机为从服务时,设置主服务的连接密码(注释)
requirepass 连接密码(注释)
#Redis的复制配置
# slaveof <masterip> <masterport>
# masterauth <master-password>
############## SECURITY ###########
# requirepass foobared
############### LIMITS ##############
appendfilename 更新日志文件名,默认值为appendonly.aof(注释)
appendfsync 更新日志条件,共有3个可选值。no表示等操作系统进行数据缓存同步到磁盘,always表示每次更新操作后手动调用fsync()将数据写到磁盘,everysec表示每秒同步一次(默认值)。
相关文档
最新文档