Linux下redis的安装

7 篇文章 0 订阅
1 篇文章 0 订阅

1.下载好安装包,并解压

[root@localhost /]# cd /usr/local/
[root@localhost local]# wget http://download.redis.io/releases/redis-3.2.0.tar.gz
[root@localhost local]# tar -zxvf redis-3.2.0.tar.gz 

2.进行编译,可能会报错,需要安装gcc依赖

[root@localhost local]# yum install gcc
[root@localhost local]# cd redis-3.2.0/
[root@localhost redis-3.2.0]# make prefix=/usr/local/redis-3.2.0/bin install

3.修改redis.conf配置文件,需要修改bind,默认为本机连接

[root@localhost redis-3.2.0]# vim redis.conf
 
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
...
protected-mode no
...
requirepass 123456
...
daemonize yes  #在后台运行

4.启动redis服务器

[root@localhost redis-3.2.0]# cd src/
[root@localhost src]# ./redis-server ../redis.conf 

5.查看是否启动成功

[root@localhost src]# ps -ef|grep redis
root     10950     1  0 14:55 ?        00:00:00 ./redis-server 127.0.0.1:6379
root     10970 10213  0 14:56 pts/1    00:00:00 grep --color=auto redis

6.常用配置

# save <seconds> <changes>
save 900 1
save 300 10
save 60 10000

# 开启 AOF 持久化 
appendonly yes
# The name of the append only file (default: "appendonly.aof")
appendfilename "appendonly.aof"

# AOF的刷盘策略,通过调用fsync()方法告诉操作系统将数据写入磁盘
# appendfsync always # 每次写操作之后刷盘
appendfsync everysec # (默认策略)每隔1s刷一次,可能会丢失1s的数据
# appendfsync no # 操作系统空闲的时候刷盘

# 当AOF日志大小按指定百分比增长时,Redis能够隐式地调用BGREWRITEAOF自动重写日志文件。
# Redis的工作原理是这样的:Redis会记住最近一次重写后的AOF文件的大小(如果重启后没有重写,则使用启动时的AOF文件的大小)。
# 指定百分比增长。指定一个百分比为零,以禁用自动AOF重写特性。
auto-aof-rewrite-percentage 100
# 指定要重写的AOF文件的最小大小
auto-aof-rewrite-min-size 64mb

# Redis 选择【惰性删除+定期删除】这两种策略配和使用
# 每隔一段时间【随机】从数据库中取出一定数量的 key 进行检查,并删除其中的过期key
hz 10

# Lists are also encoded in a special way to save a lot of space.
# The number of entries allowed per internal list node can be specified
# as a fixed maximum size or a maximum number of elements.
# For a fixed maximum size, use -5 through -1, meaning:
# -5: max size: 64 Kb  <-- not recommended for normal workloads
# -4: max size: 32 Kb  <-- not recommended
# -3: max size: 16 Kb  <-- probably not recommended
# -2: max size: 8 Kb   <-- good
# -1: max size: 4 Kb   <-- good
# Positive numbers mean store up to _exactly_ that number of elements
# per list node.
# The highest performing option is usually -2 (8 Kb size) or -1 (4 Kb size),
# but if your use case is unique, adjust the settings as necessary.
# quicklist中ziplist元素个数为8kb
# 参数为正整数时,ziplist元素个数就是这个正整数
list-max-ziplist-size -2

# Lists may also be compressed.
# Compress depth is the number of quicklist ziplist nodes from *each* side of
# the list to *exclude* from compression.  The head and tail of the list
# are always uncompressed for fast push/pop operations.  Settings are:
# 0: disable all list compression
# 1: depth 1 means "don't start compressing until after 1 node into the list,
#    going from either the head or tail"
#    So: [head]->node->node->...->node->[tail]
#    [head], [tail] will always be uncompressed; inner nodes will compress.
# 2: [head]->[next]->node->node->...->node->[prev]->[tail]
#    2 here means: don't compress head or head->next or tail->prev or tail,
#    but compress all nodes between them.
# 3: [head]->[next]->[next]->node->node->...->node->[prev]->[prev]->[tail]
# etc.
list-compress-depth 0

# set中int元素个数不超过512时,使用intset存储
set-max-intset-entries 512

# zset元素个数不超过128时,使用 ziplist
# zset中元素的长度不超过64字节时,使用 ziplist
zset-max-ziplist-entries 128
zset-max-ziplist-value 64

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值