峰Redis学习(8)Redis 持久化AOF方式
生活随笔
收集整理的這篇文章主要介紹了
峰Redis学习(8)Redis 持久化AOF方式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
第三節:Redis 的持久化之AOF 方式
AOF方式:將以日志,記錄每一個操作優勢:安全性相對RDB方式高很多;
劣勢:效率相對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默認關閉aof方式 我們修改成yes 就開啟
下面那個是默認的aof文件名
# If unsure, use "everysec".appendfsync always # appendfsync everysec # appendfsync no這里是三種同步策略:
always 是 只要發生修改,立即同步 (推薦實用 安全性最高)
everysec 是 每秒同步一次
no是不同步?
我們修改成always
?
2)保存退出,重新啟動redis,然后隨便加幾個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這里就有一個appendonly.aof文件;
?
3)將appendonly.aof剪切到/root/目錄下,啟動后,發現數據沒了:
[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方式恢復數據:將/root/appendonly.aof拷貝至/usr/local/redis/下面,再重新啟動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"我們發現 又有數據了
?
小結: 我們平時可以把aof文件定期備份 然后需要的時候 拷貝到redis下 重啟即可;
?
?
轉載于:https://www.cnblogs.com/tenWood/p/8686148.html
總結
以上是生活随笔為你收集整理的峰Redis学习(8)Redis 持久化AOF方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SVN错误信息汇总
- 下一篇: linux cmake编译源码,linu