Redisの学習[7]データの永続性

2つの方法でRedisのデータの永続性。RDBとAOF。

1、RDB

RDBは、永続性の過程を経て道のスナップショットです。勝利の具体的な条件は、データのスナップショットは、ハードディスクにメモリになります。以下の条件のRDBスナップショット

1.1、redis.conf設定ファイル(Windowsファイルはredis.windows-service.confです)

################################ SNAPSHOTTING  ################################
#
# Save the DB on disk:
#
#   save <seconds> <changes>
#
#   Will save the DB if both the given number of seconds and the given
#   number of write operations against the DB occurred.
#
#   In the example below the behaviour will be to save:
#   after 900 sec (15 min) if at least 1 key changed
#   after 300 sec (5 min) if at least 10 keys changed
#   after 60 sec if at least 10000 keys changed
#
#   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
#   like in the following example:
#
#   save ""    设置为空是不开RDB

save 900 1        900秒内,有一个key更改就触发快照
save 300 10       300秒内,有10个key更改就触发快照
save 60 10000     60秒内有10000个key更改。触发快照
# 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 ./                  保存的路径

Redisのは、Windowsオペレーティングシステムでサイド情報として役立ちます

 それが見られるように保存操作は3600秒で実行しました

1.2、bgsave保存の実装

1.3、大丈夫flushall

 

2、AOF

AOFは、すべてのRedisのコマンドがディスクに書き込まれています

############################## APPEND ONLY MODE ###############################

# By default Redis asynchronously dumps the dataset on disk. This mode is
# good enough in many applications, but an issue with the Redis process or
# a power outage may result into a few minutes of writes lost (depending on
# the configured save points).
#
# The Append Only File is an alternative persistence mode that provides
# much better durability. For instance using the default data fsync policy
# (see later in the config file) Redis can lose just one second of writes in a
# dramatic event like a server power outage, or a single write if something
# wrong with the Redis process itself happens, but the operating system is
# still running correctly.
#
# AOF and RDB persistence can be enabled at the same time without problems.
# If the AOF is enabled on startup Redis will load the AOF, that is the file
# with the better durability guarantees.
#
# Please check http://redis.io/topics/persistence for more information.

appendonly no       AOF持久化开关

# The name of the append only file (default: "appendonly.aof")
appendfilename "appendonly.aof"       文件名
# The fsync() call tells the Operating System to actually write data on disk
# instead of waiting for more data in the output buffer. Some OS will really flush
# data on disk, some other OS will just try to do it ASAP.
#
# Redis supports three different modes:
#
# no: don't fsync, just let the OS flush the data when it wants. Faster.
# always: fsync after every write to the append only log . Slow, Safest.
# everysec: fsync only one time every second. Compromise.
#
# The default is "everysec", as that's usually the right compromise between
# speed and data safety. It's up to you to understand if you can relax this to
# "no" that will let the operating system flush the output buffer when
# it wants, for better performances (but if you can live with the idea of
# some data loss consider the default persistence mode that's snapshotting),
# or on the contrary, use "always" that's very slow but a bit safer than
# everysec.
#
# More details please check the following article:
# http://antirez.com/post/redis-persistence-demystified.html
#
# If unsure, use "everysec".

# appendfsync always           每个命令都执行同步
appendfsync everysec           每秒同步
# appendfsync no               不同步

ファイルAOF内容

 3、違いRDBとAOF

その後、RDBの永続指定した時間内にデータセットの間隔メモリのスナップショットがディスクに書き込まれ、実際の動作は、子プロセスのフォークであることを意味し、一時ファイルに書き込まれたデータの最初のセット、成功した書き込み、および前にファイルを置き換えます、バイナリ圧縮ストレージ。

 AOFは、サーバーごとの書き込みによって処理されたログレコードの形に固執し、削除、クエリ操作が記録されていない、記録されたテキストが、あなたは、詳細な操作履歴を参照し、ファイルを開くことができます。

図では、我々は、以下の情報を抽出することができます

1、RDBは、各命令が、永続媒体に書き込む必要AOF、AOFのRedisより小さい永続データを実施例を示します。

2、RDBコントラストAOF、データを失う大きなリスク。バックアップ間隔サーバーのダウンタイムの中で。

3、RDBのデータ復旧よりもAOFが長くかかります。

 

公開された22元の記事 ウォンの賞賛9 ビュー8813

おすすめ

転載: blog.csdn.net/ljm_c_bok/article/details/104924969