Linux下安装配置Redis2.8

Linux Distribution:ubuntu-16.04.2

Redis:2.8.2402


一,安装

root@ubuntu:/home/sean# tar -xzf redis-2.8.24.tar.gz 
root@ubuntu:/home/sean# cd redis-2.8.24/
root@ubuntu:/home/sean/redis-2.8.24# make
root@ubuntu:/home/sean/redis-2.8.24# make install

Redis将被安装在/usr/local/bin目录下

root@ubuntu:/home/sean/redis-2.8.24# cd /usr/local/bin
root@ubuntu:/usr/local/bin# ll
total 8744
drwxr-xr-x  2 root root    4096 Mar 16 03:02 ./
drwxr-xr-x 10 root root    4096 Feb 15 12:19 ../
-rwxr-xr-x  1 root root 2196096 Mar 16 03:02 redis-benchmark*
-rwxr-xr-x  1 root root   28848 Mar 16 03:02 redis-check-aof*
-rwxr-xr-x  1 root root   65184 Mar 16 03:02 redis-check-dump*
-rwxr-xr-x  1 root root 2340616 Mar 16 03:02 redis-cli*
lrwxrwxrwx  1 root root      12 Mar 16 03:02 redis-sentinel -> redis-server*
-rwxr-xr-x  1 root root 4301568 Mar 16 03:02 redis-server*

创建单独目录存放配置、日志、数据文件

root@ubuntu:/usr/local/bin# cd /home/sean
root@ubuntu:/home/sean# mkdir redis
root@ubuntu:/home/sean# cd redis
root@ubuntu:/home/sean/redis# mkdir conf
root@ubuntu:/home/sean/redis# mkdir log
root@ubuntu:/home/sean/redis# mkdir data
root@ubuntu:/home/sean/redis# cd conf
root@ubuntu:/home/sean/redis/conf# cp /home/sean/redis-2.8.24/redis.conf ./


二,配置

修改Redis配置

root@ubuntu:/home/sean/redis/conf# vi redis.conf

修改日志文件路径

logfile /home/sean/redis/log/redis.log

修改数据文件路径

dir /home/sean/redis/data

RDB持久化规则

60s内对数据库进行至少10次修改即可触发RDB持久化

save 60 10

日志如下

[5324] 14 Mar 16:11:31.619 * 10 changes in 60 seconds. Saving...
[5324] 14 Mar 16:11:31.625 * Background saving started by pid 14676
[5324] 14 Mar 16:11:31.725 # fork operation complete
[5324] 14 Mar 16:11:31.731 * Background saving terminated with success

开启AOF持久化

appendonly yes

AOF持久化规则

Redis执行一条命令之后,会将这条命令放入写缓存中,appendfsync用来控制何时将缓存中的数据写到磁盘上

# 每条命令执行完成之后都写磁盘,速度最慢,安全性最高
# appendfsync always 
# 每一秒执行一次写磁盘操作
appendfsync everysec 
# 让操作系统控制写磁盘操作,速度最快
# appendfsync no 


三,启动

启动Redis

root@ubuntu:/home/sean/redis/conf# /usr/local/bin/redis-server ./redis.conf

如果既没有RDB文件也没有AOF文件,系统会直接启动

[14536] 14 Mar 16:17:47.486 # Server started, Redis version 2.8.2402
[14536] 14 Mar 16:17:47.486 * The server is now ready to accept connections on port 6379

如果只有RDB文件,则会从RDB文件中加载数据

[12692] 14 Mar 16:25:22.242 # Server started, Redis version 2.8.2402
[12692] 14 Mar 16:25:22.242 * DB loaded from disk: 0.000 seconds
[12692] 14 Mar 16:25:22.242 * The server is now ready to accept connections on port 6379

如果只有AOF文件,则会从AOF文件中加载数据

[2760] 14 Mar 17:21:45.032 # Server started, Redis version 2.8.2402
[2760] 14 Mar 17:21:45.032 * DB loaded from append only file: 0.000 seconds
[2760] 14 Mar 17:21:45.032 * The server is now ready to accept connections on port 6379

如果既有RDB文件,也有AOF文件,用AOF文件加载数据


四,备份

手动生成备份文件(RDB)

save

[14536] 14 Mar 16:20:43.938 * DB saved on disk

bgsave

[14536] 14 Mar 16:22:44.043 * Background saving started by pid 3616
[14536] 14 Mar 16:22:44.160 # fork operation complete
[14536] 14 Mar 16:22:44.166 * Background saving terminated with success

AOF文件重写,有效减少AOF备份文件大小

bgrewriteaof

[13436] 14 Mar 18:12:45.373 * Background append only file rewriting started by pid 4204
[13436] 14 Mar 18:12:45.520 # fork operation complete
[13436] 14 Mar 18:12:45.533 * Background AOF rewrite terminated with success
[13436] 14 Mar 18:12:45.533 * Parent diff successfully flushed to the rewritten AOF (0 bytes)
[13436] 14 Mar 18:12:45.539 * Background AOF rewrite finished successfully
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值