redis单机配置文档

redis简介

Redis(全称:Remote Dictionary Server 远程字典服务)Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库、缓存和消息中间件。 它支持多种类型的数据结构,如 字符串(strings), 散列(hashes), 列表(lists), 集合(sets), 有序集合(sorted sets) 与范围查询, bitmaps, hyperloglogs 和 地理空间(geospatial) 索引半径查询。 Redis 内置了 复制(replication),LUA脚本(Lua scripting), LRU驱动事件(LRU eviction),事务(transactions) 和不同级别的 磁盘持久化(persistence), 并通过 Redis哨兵(Sentinel)和自动 分区(Cluster)提供高可用性(high availability)

redis下载

  • 下载地址:https://redis.io/download

redis安装

详细文档(reids目录中的README.md)
# 下载redis
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
# 安装gcc
yum -y install gcc
# 解压redis
tar -xf redis-5.0.7.tar.gz
# 编译redis(具体为何使用MALLOC=libc请查看reids目录中的README.md)
make MALLOC=libc
# make install 默认会写入到/usr/local/bin下
make install

redis运行

# 通过默认的redis.conf运行
./redis-server
# 想要自定义配置文件路径
./redis-server /path/redis.conf
示例
    % ./redis-server --port 9999 --replicaof 127.0.0.1 6379
    % ./redis-server /etc/redis/6379.conf --loglevel debug

redis配置

# 自定义redis配置文件
mkdir /etc/redis
cp redis-5.0.7/redis.conf /etc/redis/
vim /etc/redis/redis.conf

# 默认配置如下(具体释义详见redis.conf)
bing 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes

# redis常见配置
 
# 设置redis服务IP,默认为127.0.0.1
bing 0.0.0.0
# redis访问端口号,默认为6379
port 6379
# 设置redis是否为守护进程,默认为no
daemonize yes
# 设置reidis日志位置,默认为""
logfile "/var/log/redis/redis.log"
 
###############rdb redis快照#################
# 设置redis的rdb快照位置,默认为./
dir /home/redis
# rdb快照名设置,默认为dump.rdb
dbfilename dump.rdb
# rdb快照触发条件
save 900 1    # 在900s内有1个改变
save 300 10       # 在300s内有10个改变
save 60 10000     # 在60s内有10000个改变
# 当快照出现写入错误时是否阻塞客户端,默认为yes
stop-writes-on-bgsave-error yes
# 是否启动rdb文件压缩,耗费CPU资源,默认为yes
rdbcompression yes
# 对rdb数据进行校验,耗费CPU资源,默认为yes
rdbchecksum yes
 
###############aof 持久化#################
# aof持久化默认关闭,配置为no
appendonly yes
# aof持久化文件名
appendfilename "appendonly.aof"
# aof持久化间隔,(always,everysec,no)优先选择everysec(性能与数据安全兼顾)
appendfsync everysec
# 默认设置为no(同时执行bgrewriteaof操作和主进程写aof文件的操作时,bgrewriteaof会涉及大量磁盘操作,会导致主进程在写aof文件时出现阻塞,当设置为no时,最为安全,要忍受阻塞。当设置为yes时,就相当于为写入磁盘,而是写入缓冲区,会造成丢失30s左右的数据)
no-appendfsync-on-rewrite no
# aof文件增长百分之多少,触发下一次rewrite
auto-aof-rewrite-percentage 100
# aof文件触发的最小大小,默认64mb,当达到此大小会触发rewrite
auto-aof-rewrite-min-size 64mb
# 指redis在恢复时,会忽略最后一条可能存在问题的指令。默认值yes
aof-load-truncated yes
# 混合持久化,默认值为yes
aof-use-rdb-preamble yes
 
#############redis 内存管理(MEMORY MANAGEMENT)####################
# 设置redis的最大使用内存,默认未打开,(<bytes>)
maxmemory 12G
# 当内存满时的缓存淘汰策略,默认为noeviction
### volatile-lru # 利用LRU算法移除设置过过期时间的key
### volatile-lfu # 利用LFU算法移除设置过过期时间的key
### allkeys-lru # 利用LRU算法移除任何key( lru 最近最少使用,如果数据最近被访问过,那么将来被访问的几率也更高)
### allkeys-lfu # 利用LFU算法移除任何key( lfu 最不经常使用,如果一个数据在最近一段时间内使用次数很少,那么在将来一段时间内被使用的可能性也很小)
### allkeys-random # 随机移除任何key
### volatile-random # 在所有超时中随机删除
### volatile-ttl # 移除即将过期的key,根据最近过期时间来删除(辅以TTL)
### noeviction # 不移除任何key,只是返回一个写错误
maxmemory-policy noeviction
# 会提高LRU或TTL的精准度(配置为10时已经非常接近全量LRU的精准度)(增加maxmemory-samples会导致在主动清理时消耗更多的CPU时间)
maxmemory-samples 5
 
#################### SECURITY ##################################
# 设置redis密码
requirepass foobared
# 最大客户端数,默认10000
maxclients 10000

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值