Redis configuration file redis.conf detailed configuration instructions

赶牛上岸
Release: 2018-03-06 17:16:18
Original
1880 people have browsed it

This article lists the detailed description of each configuration item of the Redis configuration file redis.conf. It is simple and easy to understand. Friends in need can refer to it.

redis.conf configuration item description is as follows

redis configuration file detailed explanation

# vi 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 #日志级别,分别有: # debug :适用于开发和测试 # verbose :更详细信息 # notice :适用于生产环境 # 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   #主从复制使用,用于本机redis作为slave去连接主redis masterauth  #当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 #内存清理策略,如果达到此值,将采取以下动作: # 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持久化三种同步策略: # appendfsync always #每次有数据发生变化时都会写入appendonly.aof # appendfsync everysec #默认方式,每秒同步一次到appendonly.aof # 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 #是否激活重置哈希
Copy after login

Summary:

1. Redis provides several persistence mechanisms:

a). RDB persistence

Working method: according to time interval Snapshot (dump) the data in redis to the dump.rdb file

Advantages: Simple backup and recovery. RDB completes persistence work through child processes, which is relatively more efficient than AOF startup

Disadvantage: server failure will lose data within a few minutes

b). AOF persistence

Working method: Record all update operations in the form of logs to the AOF log file. When the redis service is restarted, the log file will be read to rebuild the database to ensure data integrity after startup.

Advantages: AOF provides two synchronization mechanisms, one is fsync always synchronizes to the log file every time there is a data change, and fsync everysec synchronizes to the log file once per second to maximize data integrity.

Disadvantage: The log file is much larger than the RDB snapshot file

AOF log rewriting function:

If the AOF log file is too large, redis will Automatically rewrite the AOF log. The append mode continuously writes updated records to the old log file. At the same time, redis will also create a new log file for appending subsequent records.

c). Apply AOF and RDB at the same time

For scenarios with high data security, AOF and RDB can be used at the same time, which will reduce performance.

d). No persistence

Disable the redis service persistence function.

2. After the AOF log file has an error, the repair method:

redis-check-aof --fix appendonly.aof #--fix parameter is to repair the log file. If not added, check the log

3. Switch from RDB persistence to AOF persistence without restarting redis:

redis-cli> CONFIG SET appendonly yes #启用AOF redis-cli> CONFIG SET save "" #关闭RDB
Copy after login

The redis configuration file details the basic configuration of redis. The items are relatively common. When using redis, you must understand these configuration items

Related recommendations:

Redis configuration file redis.conf Detailed explanation

[Redis Notes] Part 4: Description of the Replication configuration item in redis.conf

Why is the save configuration item commented in redis.conf, and the redis content after restarting the server Is there still data written last time?


The above is the detailed content of Redis configuration file redis.conf detailed configuration instructions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!