李林超博客
首页
归档
留言
友链
动态
关于
归档
留言
友链
动态
关于
首页
其它
正文
Redis配置文件redis.conf介绍
Leefs
2020-04-16 AM
2176℃
0条
# Redis配置文件redis.conf介绍 ### 前言 我们在刚接触Redis就需要对redis.conf文件做修改和配置,包括端口号,持久化方式等等,本篇对redis.conf文件做一个介绍,对redis.conf文件有更深入的了解。 ### 一、简单配置解析 > daemonize yes #是否以后台进程运行 > > pidfile /var/run/redis/redis-server.pid #pid文件位置 > > port 6379#监听端口 > > bind 127.0.0.1 #绑定地址,如外网需要连接,设置0.0.0.0 > > timeout 300 #连接超时时间,单位秒 **日志:** > loglevel notice #日志级别, > > 分别有: > > (1)debug :适用于开发和测试 > > (2)verbose :更详细信息 > > (3)notice :适用于生产环境 > > (4) warning :只记录警告或错误信息 > > logfile /var/log/redis/redis-server.log #日志文件位置 > > syslog-enabled no #是否将日志输出到系统日志 > > databases 16#设置数据库数量,默认数据库为0 **保存快照方式:** > save 900 1 #在900s(15m)之后,至少有1个key发生变化,则快照 > > save 300 10 #在300s(5m)之后,至少有10个key发生变化,则快照 > > save 60 10000 #在60s(1m)之后,至少有1000个key发生变化,则快照 > > rdbcompression yes #dump时是否压缩数据 > > dir /var/lib/redis #数据库(dump.rdb)文件存放目录 **主从复制:** > **slaveof <``masterip``> <``masterport``>** #主从复制使用,用于本机redis作为slave去连接主redis > > **masterauth <``master-password``>** #当master设置密码认证,slave用此选项指定master认证密码 > > **slave-serve-stale-data yes** #当slave与master之间的连接断开或slave正在与master进行数据同步时,如果有slave请求,当设置为yes时,slave仍然响应请求,此时可能有问题,如果设置no时,slave会返回"SYNC with master in progress"错误信息。但INFO和SLAVEOF命令除外。 **安全:** requirepass foobared #配置redis连接认证密码 **限制:** > maxclients 128#设置最大连接数,0为不限制 **内存清理策略:** maxmemory <``bytes``>#内存清理策略 如果达到此值,将采取以下动作: > volatile-lru :默认策略,只对设置过期时间的key进行LRU算法删除 > > allkeys-lru :删除不经常使用的key > > volatile-random :随机删除即将过期的key > > allkeys-random :随机删除一个key > > volatile-ttl :删除即将过期的key > > noeviction :不过期,写操作返回报错 maxmemory-policy volatile-lru#如果达到maxmemory值,采用此策略 maxmemory-samples 3 #默认随机选择3个key,从中淘汰最不经常用的 **附加模式:** appendonly no #AOF持久化,是否记录更新操作日志,默认redis是异步(快照)把数据写入本地磁盘 appendfilename appendonly.aof #指定更新日志文件名 **AOF持久化三种同步策略:** (1)appendfsync always #每次有数据发生变化时都会写入appendonly.aof (2)appendfsync everysec #默认方式,每秒同步一次到appendonly.aof (3)appendfsync no #不同步,数据不会持久化 no-appendfsync-on-rewrite no #当AOF日志文件即将增长到指定百分比时,redis通过调用BGREWRITEAOF是否自动重写AOF日志文件。 **虚拟内存:** **vm-enabled no** #是否启用虚拟内存机制,虚拟内存机将数据分页存放,把很少访问的页放到swap上,内存占用多,最好关闭虚拟内存 vm-swap-file /var/lib/redis/redis.swap #虚拟内存文件位置 vm-max-memory 0 #redis使用的最大内存上限,保护redis不会因过多使用物理内存影响性能 vm-page-size 32 #每个页面的大小为32字节 vm-pages 134217728 #设置swap文件中页面数量 vm-max-threads 4 #访问swap文件的线程数 **高级配置:** hash-max-zipmap-entries 512 #哈希表中元素(条目)总个数不超过设定数量时,采用线性紧凑格式存储来节省空间 hash-max-zipmap-value 64 #哈希表中每个value的长度不超过多少字节时,采用线性紧凑格式存储来节省空间 list-max-ziplist-entries 512 #list数据类型多少节点以下会采用去指针的紧凑存储格式 list-max-ziplist-value 64 #list数据类型节点值大小小于多少字节会采用紧凑存储格式 set-max-intset-entries 512 #set数据类型内部数据如果全部是数值型,且包含多少节点以下会采用紧凑格式存储 activerehashing yes #是否激活重置哈希 **Redis.conf** ```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. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bind 127.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 1024 tcp-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表示不检测,建议设置为60 tcp-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、warning loglevel notice # 设置日志输出文件,若为空字符串"" 或者 stdout ,则将日志从定位到 /dev/null logfile "" # 若要将redis日志记录到系统日志,将此参数设置为 yes # syslog-enabled no # 用于指定日志标识:若开启系统日志,指定日志以 redis 开头 # syslog-ident redis # 设置系统日志输出设备,值可为 USER 或者 LOCAL0-LOCAL7,默认为local0 # syslog-facility local0 # 设置 redis 服务启动数据库的个数,默认 16 个,默认数据库为 DB 0 ,可使用 select
进行切库,dbid为 0 至 databases-1 databases 16 # 是否总是显示redis那个"蛋糕"logo always-show-logo yes ################################ SNAPSHOTTING ################################ # 指定在规定时间内,有多少此更新操作,就将数据同步至数据文件,可多个条件配合使用 # save
# save "" # 默认配置如下:15分钟内有一个更改,5分钟内有10个更改,1分钟内有10000个更改 save 900 1 save 300 10 save 60 10000 # 当RDB在后台持久化出错后,是否依然进行数据库写操作,yes:停止写操作,no:继续写操作 stop-writes-on-bgsave-error yes # 指定存储至本地数据库时是否压缩数据,默认为yes:使用压缩,redis采用LZF压缩算法,使用会消耗CPU,不使用占内存 rdbcompression yes # 是否校验压缩后的rdb文件,默认为yes:进行校验,开启大概有10%性能损耗 rdbchecksum yes # 指定本地数据库文件名,默认为dump.rdb dbfilename dump.rdb # 指定本地数据文件存放目录 dir ./ ################################# REPLICATION ################################# # 将当前服务器作为从库,同步备份主库的数据,并提供读操作 # replicaof
# replicaof 10.7.5.74 6379 # 当master服务设置了密码保护时,slave服务连接master的密码 # masterauth
# 登录 redis 数据库密码认证问题 # 执行命令 config get requirepass ,获取配置文件中默认认证密码,默认密码为 foobared # requirepass foobared # 执行命令 config set requirepass "redis" ,设置认证密码为 redis ,设置为空 "" 表示不认证 # 在执行命令前使用 auth
命令进行认证 # 禁止远程修改 DB 文件地址,就是对命令进行权限控制 # 将命令重命名为空 "",表示禁用该命令 # rename-command FLASHALL "" # 也可将命令重命名为 qazwsx741852edc ,然后将此名授权给特定用户使用即可 # rename-command CONFIG "qazwsx741852edc" ################################### CLIENTS #################################### # 设置客户端默认最大连接数,设置为0表示不限制,默认为10000 # maxclients 10000 ############################## MEMORY MANAGEMENT ################################ # 设置 redis 最大内存容量 # maxmemory
# 内存达到上限的处理策略(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 # 指定是否在每次更新操作后进行日志记录,redis默认异步将数据写入磁盘,不开启会导致断电时一段时间内的数据丢失,默认no appendonly no # 指定更新日志文件名,默认为appendonly.aof appendfilename "appendonly.aof" # 指定更新日志条件,建议使用 "everysec" # "always":同步持久化,每次发生数据更改会立即调用fsync()方法将数据写入磁盘,数据完整性好,性能差 # "everysec":默认值,异步同步,每秒同步一次,若一秒内宕机,则存在数据丢失 # "no":永不 # appendfsync always appendfsync 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 100 auto-aof-rewrite-min-size 64mb # 指定在超过一定数据或者最大的元素超过某一临界值时,采用如下特殊哈希算法,未超过则使用ziplist hash-max-ziplist-entries 512 hash-max-ziplist-value 64 stream-node-max-bytes 4096 stream-node-max-entries 100 # 指定是否激活重置哈希,默认为开启。对实时性要求高的,可更改为no,不开启 activerehashing yes # Enabled active defragmentation # activedefrag yes # Minimum amount of fragmentation waste to start active defrag # active-defrag-ignore-bytes 100mb # Minimum percentage of fragmentation to start active defrag # active-defrag-threshold-lower 10 # Maximum percentage of fragmentation at which we use maximum effort # active-defrag-threshold-upper 100 # Minimal effort for defrag in CPU percentage # active-defrag-cycle-min 5 # Maximal effort for defrag in CPU percentage # active-defrag-cycle-max 75 # Maximum number of set/hash/zset/list fields that will be processed from # the main dictionary scan # active-defrag-max-scan-fields 1000 ``` *附:参考文章链接* *https://www.jb51.net/article/135837.htm*
标签:
Redis
非特殊说明,本博所有文章均为博主原创。
如若转载,请注明出处:
https://lilinchao.com/archives/860.html
上一篇
Redis简单命令
下一篇
Eclipse中SVN提交冲突解决
取消回复
评论啦~
提交评论
栏目分类
随笔
2
Java
326
大数据
229
工具
31
其它
25
GO
47
标签云
Thymeleaf
MyBatis-Plus
机器学习
Jquery
高并发
国产数据库改造
Spark RDD
Nacos
Hive
SpringCloudAlibaba
Jenkins
Sentinel
Azkaban
JavaScript
随笔
Zookeeper
NIO
DataWarehouse
VUE
Hbase
序列化和反序列化
Docker
Quartz
Redis
Http
Spark SQL
CentOS
JavaWeb
gorm
Livy
友情链接
申请
范明明
庄严博客
Mx
陶小桃Blog
虫洞