标签:aof sharp auto ber already fork 命令 错误 rgb
优点
缺点
2. AOF(追加)
优点
缺点
RDB持久化是把当前进程数据生成的快照保存到硬盘的过程,触发RDB持久化过程分为手动触发和自动触发
root@e7576f2fbb11:/# redis-cli save OK root@e7576f2fbb11:/# redis-cli info|grep save #查看持久化相关信息 rdb_changes_since_last_save:0 rdb_bgsave_in_progress:0 rdb_last_save_time:1497083505 rdb_last_bgsave_status:ok rdb_last_bgsave_time_sec:0 rdb_current_bgsave_time_sec:-1 root@e7576f2fbb11:/# tail -n 4 /var/log/redis/redis-server.log 61:C 10 Jun 08:20:46.257 * DB saved on disk 61:C 10 Jun 08:20:46.258 * RDB: 0 MB of memory used by copy-on-write 29:M 10 Jun 08:20:46.316 * Background saving terminated with success 29:M 10 Jun 08:31:45.676 * DB saved on disk ###运行redis-cli save对应的redis服务日志
root@e7576f2fbb11:/# redis-cli bgsave Background saving started root@e7576f2fbb11:/# redis-cli info|grep fork latest_fork_usec:771 #####最近一次fork子进程阻塞用的时间us root@e7576f2fbb11:/# redis-cli info|grep save #####获取持久化相关信息 rdb_changes_since_last_save:0 rdb_bgsave_in_progress:0 rdb_last_save_time:1497084106 ####最后一个RDB时间 rdb_last_bgsave_status:ok rdb_last_bgsave_time_sec:0 rdb_current_bgsave_time_sec:-1 root@e7576f2fbb11:/# tail -n 4 /var/log/redis/redis-server.log ####使用bgsave持久化redis服务产生的日志 29:M 10 Jun 08:41:46.346 * Background saving started by pid 77 77:C 10 Jun 08:41:46.380 * DB saved on disk 77:C 10 Jun 08:41:46.381 * RDB: 0 MB of memory used by copy-on-write 29:M 10 Jun 08:41:46.385 * Background saving terminated with success
2.1 通过reids.conf配置动触发bgsave
2.2 当从节点执行全量复制操作时,主节点自动执行bgsave生成bgsave RDB文件并发送给从节点.
2.3 当使用redis-cli shutdown关闭redis服务时,如果没有开启AOF持久化功能则也会自动执行bgsave
root@e7576f2fbb11:/# grep ‘save‘ /etc/redis/redis.conf # save <seconds> <changes> # Will save the DB if both the given number of seconds and the given # In the example below the behaviour will be to save: # Note: you can disable saving completely by commenting out all "save" lines. # It is also possible to remove all the previously configured save # points by adding a save directive with a single empty string argument # save "" save 900 1 ###900s内至少一次改动,自动触发bgsave save 300 10 ###300s内至少10次改动,自动触发bgsave save 60 10000 ###60s内至少10000次改动,自动触发bgsave
# save "" ###如果最后一行是save ""则上面自动触发bgsave规则会失效
root@e7576f2fbb11:/# egrep -i "filename|dir" /etc/redis/redis.conf # line as value of a configuration directive, you‘d better put includes # interfaces using the "bind" configuration directive, followed by one or # points by adding a save directive with a single empty string argument # The filename where to dump the DB dbfilename dump.rdb #RDB文件保存的文件名,默认采取压缩 # The working directory. # The DB will be written inside this directory, with the filename specified # above using the ‘dbfilename‘ configuration directive. # The Append Only File will also be created inside this directory. # Note that you must specify a directory here, not a file name. dir /var/lib/redis ###RDB文件保存目录
在redis正常运行过程中如果默认的RDB存储路径磁盘写满或不能正常写时,可以使用config set dbfilename newfilename和config set dir newdir动态改变默认的存储路径.
root@e7576f2fbb11:/# redis-cli -h 127.0.0.1 -p 6379 config set dir /var/lib/ OK root@e7576f2fbb11:/# redis-cli -h 127.0.0.1 -p 6379 config set filename newfilename.rdb (error) ERR Unsupported CONFIG parameter: filename root@e7576f2fbb11:/# redis-cli -h 127.0.0.1 -p 6379 config set dbfilename newfilename.rdb OK root@e7576f2fbb11:/# redis-cli bgsave Background saving started root@e7576f2fbb11:/# ls -l /var/lib/newfilename.rdb -rw-r--r-- 1 root root 34 Jun 10 09:28 /var/lib/newfilename.rdb root@e7576f2fbb11:/# date Sat Jun 10 09:29:14 UTC 2017 root@e7576f2fbb11:/#
root@e7576f2fbb11:/# redis-check-dump /var/lib/newfilename.rdb #####使用redis-check-dump 工具检测RDB文件是否有问题.
==== Processed 3 valid opcodes (in 17 bytes) ===================================
CRC64 checksum is OK
AOF
AOF(append only file)持久化:使用独立的日志的方式记录每次写的命令,重启时再重新执行AOF文件中的命令达到恢复数据的目的.AOF的主要作用是解决了数据持久化的实时性.
如果要开启AOF需要修改redis.conf配置:appendonly yes(默认不开启:appendonly no)
通过定义appendfilename和dir修改aof文件名和保存路径.
AOF工作流程:
文件同步
redis提供多种缓冲区同步文件策略,由参数appendfsync控制,不同值含义如下:
可配置值 | 说明 |
---|---|
always | 命令写入aof_buf后调用fsync同步操作同步到aof文件,fsync同步完成后线程返回 |
everysec | 命令写入aof_buf后调用系统write操作,write完成后线程返回,fsync操作由专门线程每秒调用一次 (建议配置) |
no | 命令写入aof_buf后调用系统write操作,不对aof文件做fsync同步,同步硬盘由操作系统负责,通常最长同步周期30秒 |
系统调用write和fsync说明
重写机制
随着不断的追加写入,aof文件越来越大,此时重写机制会压缩文件大小.重写指的是:把redis进程内的数据转化为写命令同步到新AOF文件的过程.
重写使aof文件变小原因:
重写的触发
重写运作流程
1. AOF持久化开启且存在AOF文件时,优先加载AOF文件
2. AOF关闭或AOF文件不存在时,加载RDB文件(前提是RDB存在,不存在也会启动)
3.加载AOF/RDB文件成功后,rdis启动成功
4. AOF/RDB存在错误时,启动失败
标签:aof sharp auto ber already fork 命令 错误 rgb
原文地址:http://www.cnblogs.com/diaosir/p/6979780.html