峰Redis学习(8)Redis 持久化AOF方式
第三節(jié):Redis 的持久化之AOF 方式
AOF方式:將以日志,記錄每一個(gè)操作優(yōu)勢(shì):安全性相對(duì)RDB方式高很多;
劣勢(shì):效率相對(duì)RDB方式低很多;
?
1)AOF方式需要配置:
# Please check http://redis.io/topics/persistence for more information. appendonly no# The name of the append only file (default: "appendonly.aof")appendfilename "appendonly.aof"appendonly no默認(rèn)關(guān)閉aof方式 我們修改成yes 就開啟
下面那個(gè)是默認(rèn)的aof文件名
# If unsure, use "everysec".appendfsync always # appendfsync everysec # appendfsync no這里是三種同步策略:
always 是 只要發(fā)生修改,立即同步 (推薦實(shí)用 安全性最高)
everysec 是 每秒同步一次
no是不同步?
我們修改成always
?
2)保存退出,重新啟動(dòng)redis,然后隨便加幾個(gè)key
[root@bogon redis]# ll 總用量 52 drwxr-xr-x. 2 root root 134 3月 31 20:51 bin -rw-r--r--. 1 root root 102 4月 1 11:44 dump.rdb -rw-r--r--. 1 root root 46690 4月 1 11:47 redis.conf [root@bogon redis]# bin/redis-server redis.conf [root@bogon redis]# bin/redis-cli 127.0.0.1:6379> keys * (empty list or set) 127.0.0.1:6379> set test1 111 OK 127.0.0.1:6379> set test 222 OK 127.0.0.1:6379> shutdown save not connected> exit [root@bogon redis]# ll 總用量 56 -rw-r--r--. 1 root root 88 4月 1 11:49 appendonly.aof drwxr-xr-x. 2 root root 134 3月 31 20:51 bin -rw-r--r--. 1 root root 100 4月 1 11:49 dump.rdb -rw-r--r--. 1 root root 46690 4月 1 11:47 redis.conf [root@bogon redis]# rm -rf dump.rdb [root@bogon redis]# ll 總用量 52 -rw-r--r--. 1 root root 88 4月 1 11:49 appendonly.aof drwxr-xr-x. 2 root root 134 3月 31 20:51 bin -rw-r--r--. 1 root root 46690 4月 1 11:47 redis.conf這里就有一個(gè)appendonly.aof文件;
?
3)將appendonly.aof剪切到/root/目錄下,啟動(dòng)后,發(fā)現(xiàn)數(shù)據(jù)沒了:
[root@bogon redis]# ll 總用量 52 -rw-r--r--. 1 root root 88 4月 1 11:49 appendonly.aof drwxr-xr-x. 2 root root 134 3月 31 20:51 bin -rw-r--r--. 1 root root 46690 4月 1 11:47 redis.conf [root@bogon redis]# mv appendonly.aof /root/ [root@bogon redis]# cd /root/ [root@bogon ~]# ll 總用量 1528 -rw-------. 1 root root 1269 3月 31 23:56 anaconda-ks.cfg -rw-r--r--. 1 root root 88 4月 1 11:49 appendonly.aof drwxrwxr-x. 6 root root 4096 7月 28 2017 redis-3.2.10 -rw-r--r--. 1 root root 1550261 7月 29 2017 redis-3.2.10.tar.gz [root@bogon ~]# cd /usr/local/redis/ [root@bogon redis]# bin/redis-server redis.conf [root@bogon redis]# bin/redis-cli 127.0.0.1:6379> keys * (empty list or set)4)aof方式恢復(fù)數(shù)據(jù):將/root/appendonly.aof拷貝至/usr/local/redis/下面,再重新啟動(dòng)redis:
127.0.0.1:6379> keys * (empty list or set) 127.0.0.1:6379> shutdown not connected> exit [root@bogon redis]# ll 總用量 52 -rw-r--r--. 1 root root 0 4月 1 11:52 appendonly.aof drwxr-xr-x. 2 root root 134 3月 31 20:51 bin -rw-r--r--. 1 root root 77 4月 1 11:54 dump.rdb -rw-r--r--. 1 root root 46690 4月 1 11:47 redis.conf [root@bogon redis]# rm -rf appendonly.aof [root@bogon redis]# cd /root/ [root@bogon ~]# ll 總用量 1528 -rw-------. 1 root root 1269 3月 31 23:56 anaconda-ks.cfg -rw-r--r--. 1 root root 88 4月 1 11:49 appendonly.aof drwxrwxr-x. 6 root root 4096 7月 28 2017 redis-3.2.10 -rw-r--r--. 1 root root 1550261 7月 29 2017 redis-3.2.10.tar.gz [root@bogon ~]# cp appendonly.aof /usr/local/redis/ [root@bogon ~]# cd /usr/local/redis/ [root@bogon redis]# ll 總用量 56 -rw-r--r--. 1 root root 88 4月 1 11:55 appendonly.aof drwxr-xr-x. 2 root root 134 3月 31 20:51 bin -rw-r--r--. 1 root root 77 4月 1 11:54 dump.rdb -rw-r--r--. 1 root root 46690 4月 1 11:47 redis.conf [root@bogon redis]# bin/redis-server redis.conf [root@bogon redis]# bin/redis-cli 127.0.0.1:6379> keys * 1) "test" 2) "test1"我們發(fā)現(xiàn) 又有數(shù)據(jù)了
?
小結(jié): 我們平時(shí)可以把a(bǔ)of文件定期備份 然后需要的時(shí)候 拷貝到redis下 重啟即可;
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/tenWood/p/8686148.html
總結(jié)
以上是生活随笔為你收集整理的峰Redis学习(8)Redis 持久化AOF方式的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SVN错误信息汇总
- 下一篇: mysql两张主表person even