Redis] [persistence persistent AOF RDB and RDB and the AOF redis

redis RDB and the persistence AOF

 

redis data persistence

RedisIs a memory database, once the server process exits, the data in the database will be lost, in order to solve this problem, Redisprovides two of a lasting solution to save the data in memory to disk, to avoid loss of data.

RDB persistence

redisProvides RDB持久化functionality, this feature can redissave the state in memory to the hard disk, it can perform a manual. [Triggered by the save instruction manual execution]

Can also be re- redis.confconfigured, regularly perform .

RDB RDB persistence produced a file is compressed in a binary file , the file is saved on the hard disk, redis can restore the state of the database at the time of the adoption of the document.

rdb configuration parameters:

Copy the code
RDB (persistence) 
to save memory data to disk 
generated data set within a specified time interval time snapshots (point-in-time snapshot) 
Advantages: fast, suitable for backup master is based on RDB persistence function realized from the replication 
rdb rdb triggered again by using redis save command 


rdb configuration parameters: 

the dir / Data / 6379 / 
dbfilename dbmp.rdb 

every 900 seconds there is a persistent operation proceeds 

operation 900 seconds save a modified class 
save 10 seconds 300 operation 
save 60 seconds 10000 operation 

Save 900. 1 
Save 300 10 
save 60 10000
Copy the code

redis persistent practice of RDB

1. Start redis server configuration profiles

# Create a log log file 
mkdir -p / the Data / 6380 / 
cd / the Data / 6380 / 
Touch redis.log
Copy the code
daemonize yes # whether to open the background 
port 6379 # port 
logfile /data/6379/redis.log # custom log file 
dir / data / 6379 # custom persistent file storage location 
dbfilename dbmp.rdb #rdb persistent file 
bind 192.168. 61.129 #redis binding address 
requirepass redhat #redis login password 
save 900 1 #rdb mechanism every 900 seconds there is a modified record 
save 300 10 # every 300 seconds 10 modified record 
save 60 10000 # 10000 modify records within every 60 seconds
Copy the code

2. Start by redis server configuration file above

redis-server redis.conf

Login redis client

# --Raw parameters expressed support for the Chinese 
redis-cli -p 6380 -h 192.168.61.129 --raw   

3, after logging a key set redis

Because we want to verify his data persistence, so we need to create a login key, triggering persistent with the save command, and then kill the process redis service side,

Copy the code
192.168.61.129:6380> KEYS *

192.168.61.129:6380> set name "alex"
OK
192.168.61.129:6380> set age 19
OK
192.168.61.129:6380> get name
alex
192.168.61.129:6380> get age
19
Copy the code

4. At this time, check the directory, / data / 6380 under no file dbmp.rdb

5. triggered by persistent save, writing data to RDB file

Copy the code
192.168.61.129:6380> KEYS *

192.168.61.129:6380> set name "alex"
OK
192.168.61.129:6380> set age 19
OK
192.168.61.129:6380> get name
alex
192.168.61.129:6380> get age
19
192.168.61.129:6380> SAVE
OK
Copy the code

6, see the persistence file dbmp.rdb

redis persistent practice of AOF

AOF (append-only log file)
record of all operation commands executed by the server (e.g., set del, etc.), and when the server starts, be reduced by re-executing the command data sets
AOF commands in the file save all format redis protocol the new command is appended to the end of the file.
Advantages: maximum program to ensure that data is not lost
drawback: very large logging

redis-client write> redis-server synchronization command> AOF file

Configuration parameters

AOF persistence configuration, two parameters 

appendOnly Yes 
appendfsync Always always modify operation class 
             everysec done once per second persistence # commonly 
             no system-dependent mechanism comes cache size

1, ready aof profile redis.conf

Copy the code
daemonize yes # process is running in the background 
port 6380 # port 
logfile /data/6380/redis.log # log log 
dir / the Data / 6380             
dbfilename dbmp.rdb # persistent data file 
bind 192.168.61.129 # Bind ip 
requirepass root # Set password for root 
appendOnly yes 
appendfsync everysec # do a second persistence
Copy the code

2. Start redis server-based configuration file

redis-server /etc/redis.conf

3. Check redis data directory / data / 6380 / aof whether or not a file

[root@szx 6380]# ls
appendonly.aof  dbmp.rdb  redis.log

4. Log redis-cli, write data, real-time check aof file information

[root@szx ~ 20:09:35]#tail -f /data/6380/appendonly.aof 

5. Set the new key, aof check information, and then close Redis, to check whether data persistence

Copy the code
[root@szx / 19:50:25]#redis-cli -p 6380 -h 192.168.61.129 --raw  
192.168.61.129:6380> auth root
OK
192.168.61.129:6380> KEYS *

192.168.61.129:6380> SET name "alex"
OK
192.168.61.129:6380> SET age 87
OK
Copy the code

step:

Modify the configuration file -> Start redis server -> client login redis -> Create key

Quit killing redis client server process -> Restart and sign redis -> Check whether created before key presence

View data persistence files, all operation records are stored in a file

Real-time monitoring data persistence file:

redis persistence options? What's the difference?

rdb: snapshot-based persistence, faster, typically used as a backup, is copied from the master depends on persistence function rdb

aof: can additionally recorded redis operation log file. Redis can ensure the greatest degree of data security, similar to the mysql binlog

redis数据持久化

Redis是一种内存型数据库,一旦服务器进程退出,数据库的数据就会丢失,为了解决这个问题,Redis提供了两种持久化的方案,将内存中的数据保存到磁盘中,避免数据的丢失。

RDB持久化

redis提供了RDB持久化的功能,这个功能可以将redis在内存中的的状态保存到硬盘中,它可以手动执行。【手动执行时通过save指令触发的】

也可以再redis.conf中配置,定期执行

RDB持久化产生的RDB文件是一个经过压缩二进制文件,这个文件被保存在硬盘中,redis可以通过这个文件还原数据库当时的状态。

rdb配置参数:

Copy the code
RDB(持久化)
内存数据保存到磁盘
在指定的时间间隔内生成数据集的时间点快照(point-in-time snapshot)
优点:速度快,适合做备份,主从复制就是基于RDB持久化功能实现
rdb通过再redis中使用save命令触发 rdb


rdb配置参数:

dir /data/6379/
dbfilename  dbmp.rdb

每过900秒 有1个操作就进行持久化

save 900秒  1个修改类的操作
save 300秒  10个操作
save 60秒  10000个操作

save  900 1
save 300 10
save 60  10000
Copy the code

redis持久化之RDB实践

1.配置启动redis服务端的配置文件

# 创建log日志文件
mkdir -p /data/6380/
cd /data/6380/
touch redis.log
Copy the code
daemonize yes                  # 是否开启后台运行
port 6379                         #端口
logfile /data/6379/redis.log  # 自定义日志文件
dir /data/6379               #自定义持久化文件存储位置
dbfilename  dbmp.rdb        #rdb持久化文件
bind 192.168.61.129   #redis绑定地址
requirepass redhat            #redis登录密码
save 900 1                    #rdb机制 每900秒 有1个修改记录
save 300 10                    #每300秒        10个修改记录
save 60  10000                #每60秒内        10000修改记录
Copy the code

2.通过上面的配置文件启动redis服务端

redis-server redis.conf

登录redis客户端

# --raw参数表示支持中文
redis-cli -p 6380 -h 192.168.61.129 --raw   

3、登录redis后设置一个key

因为我们要验证他的数据持久化,所以我们登录后需要创建一个key,用save指令触发持久化,然后杀死redis服务端的进程,

Copy the code
192.168.61.129:6380> KEYS *

192.168.61.129:6380> set name "alex"
OK
192.168.61.129:6380> set age 19
OK
192.168.61.129:6380> get name
alex
192.168.61.129:6380> get age
19
Copy the code

4.此时检查目录,/data/6380底下没有dbmp.rdb文件

5.通过save触发持久化,将数据写入RDB文件

Copy the code
192.168.61.129:6380> KEYS *

192.168.61.129:6380> set name "alex"
OK
192.168.61.129:6380> set age 19
OK
192.168.61.129:6380> get name
alex
192.168.61.129:6380> get age
19
192.168.61.129:6380> SAVE
OK
Copy the code

6、查看持久化文件dbmp.rdb

redis持久化之AOF实践

AOF(append-only log file)
记录服务器执行的所有变更操作命令(例如set del等),并在服务器启动时,通过重新执行这些命令来还原数据集
AOF 文件中的命令全部以redis协议的格式保存,新命令追加到文件末尾。
优点:最大程序保证数据不丢
缺点:日志记录非常大

redis-client   写入数据  >  redis-server   同步命令   >  AOF文件

配置参数

AOF持久化配置,两条参数

appendonly yes
appendfsync  always    总是修改类的操作
             everysec   每秒做一次持久化   # 常用
             no     依赖于系统自带的缓存大小机制

1、准备aof配置文件redis.conf

Copy the code
daemonize yes   # 进程是否在后台运行
port 6380          # 端口
logfile /data/6380/redis.log   # log日志
dir /data/6380            
dbfilename  dbmp.rdb       # 数据持久化文件
bind 192.168.61.129        # 绑定ip
requirepass root         # 设置密码为root
appendonly yes
appendfsync everysec     #每秒做一次持久化
Copy the code

2. Start redis server-based configuration file

redis-server /etc/redis.conf

3. Check redis data directory / data / 6380 / aof whether or not a file

[root@szx 6380]# ls
appendonly.aof  dbmp.rdb  redis.log

4. Log redis-cli, write data, real-time check aof file information

[root@szx ~ 20:09:35]#tail -f /data/6380/appendonly.aof 

5. Set the new key, aof check information, and then close Redis, to check whether data persistence

Copy the code
[root@szx / 19:50:25]#redis-cli -p 6380 -h 192.168.61.129 --raw  
192.168.61.129:6380> auth root
OK
192.168.61.129:6380> KEYS *

192.168.61.129:6380> SET name "alex"
OK
192.168.61.129:6380> SET age 87
OK
Copy the code

step:

Modify the configuration file -> Start redis server -> client login redis -> Create key

Quit killing redis client server process -> Restart and sign redis -> Check whether created before key presence

View data persistence files, all operation records are stored in a file

Real-time monitoring data persistence file:

redis persistence options? What's the difference?

rdb: snapshot-based persistence, faster, typically used as a backup, is copied from the master depends on persistence function rdb

aof: can additionally recorded redis operation log file. Redis can ensure the greatest degree of data security, similar to the mysql binlog

Guess you like

Origin www.cnblogs.com/youxiu123/p/11493147.html