Redis 配置说明
Redis 配置文件
Redis 的配置文件Linux位于 Redis 安装目录下,文件名为 redis.conf,Windows 名为 redis.windows.conf。
Redis 配置文件参数说明
参数名 | 默认值 | 说明 |
---|---|---|
daemonize | no | Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程 |
pidfile | 当Redis以守护进程方式运行时,Redis默认会把pid写入/var/run/redis.pid文件,可以通过pidfile指定 | |
port | 6379 | 指定Redis监听端口,默认端口为6379,作者在自己的一篇博文中解释了为什么选用6379作为默认端口,因为6379在手机按键上MERZ对应的号码,而MERZ取自意大利歌女Alessia Merz的名字 |
bind | 绑定的主机地址 | |
loglevel | notice | 指定日志记录级别,Redis总共支持四个级别:debug、verbose、notice、warning,默认为verbose |
logfile | 日志记录方式,默认为标准输出,如果配置Redis为守护进程方式运行,而这里又配置为日志记录方式为标准输出,则日志将会发送给/dev/null | |
databases | 16 | 设置数据库的数量,默认数据库为0,可以使用SELECT |
save | 3600 1 300 100 60 10000 | 指定在多长时间内,有多少次更新操作,就将数据同步到数据文件,可以多个条件配合。分别表示900秒(15分钟)内有1个更改,300秒(5分钟)内有10个更改以及60秒内有10000个更改。 |
rdbcompression | yes | 指定存储至本地数据库时是否压缩数据,默认为yes,Redis采用LZF压缩,如果为了节省CPU时间,可以关闭该选项,但会导致数据库文件变的巨大 |
dbfilename | dump.rdb | 指定本地数据库文件名,默认值为dump.rdb |
dir | /usr/local/bin | 指定本地数据库存放目录 |
slaveof | 设置当本机为slav服务时,设置master服务的IP地址及端口,在Redis启动时,它会自动从master进行数据同步 | |
masterauth | 当master服务设置了密码保护时,slav服务连接master的密码 | |
requirepass | 设置Redis连接密码,如果配置了连接密码,客户端在连接Redis时需要通过AUTH | |
maxclients | 10000 | 设置同一时间最大客户端连接数,默认无限制,Redis可以同时打开的客户端连接数为Redis进程可以打开的最大文件描述符数,如果设置 maxclients 0,表示不作限制。当客户端连接数到达限制时,Redis会关闭新的连接并向客户端返回max number of clients reached错误信息 |
maxmemory | 0 | 指定Redis最大内存限制,Redis在启动时会把数据加载到内存中,达到最大内存后,Redis会先尝试清除已到期或即将到期的Key,当此方法处理 后,仍然到达最大内存设置,将无法再进行写入操作,但仍然可以进行读取操作。Redis新的vm机制,会把Key存放内存,Value会存放在swap区 |
appendonly | no | 指定是否在每次更新操作后进行日志记录,Redis在默认情况下是异步的把数据写入磁盘,如果不开启,可能会在断电时导致一段时间内的数据丢失。因为 redis本身同步数据文件是按上面save条件来同步的,所以有的数据会在一段时间内只存在于内存中。默认为no |
appendfsync | everysec | 指定更新日志条件,共有3个可选值: no:表示等操作系统进行数据缓存同步到磁盘(快) always:表示每次更新操作后手动调用fsync()将数据写到磁盘(慢,安全) everysec:表示每秒同步一次(折中,默认值) |
activerehashing | yes | 指定是否激活重置哈希,默认为开启(后面在介绍Redis的哈希算法时具体介绍) |
cluster-announce-ip | ||
unixsocket | ||
slave-announce-ip | ||
replica-announce-ip | ||
proto-max-bulk-len | 536870912 | |
client-query-buffer-limit | 1073741824 | |
maxmemory-samples | 5 | |
lfu-log-factor | 10 | |
lfu-decay-time | 1 | |
timeout | 0 | |
active-defrag-threshold-lower | 10 | |
active-defrag-threshold-upper | 100 | |
active-defrag-ignore-bytes | 104857600 | |
active-defrag-cycle-min | 5 | |
active-defrag-cycle-max | 75 | |
active-defrag-max-scan-fields | 1000 | |
auto-aof-rewrite-percentage | 100 | |
auto-aof-rewrite-min-size | 67108864 | |
hash-max-ziplist-entries | 512 | |
hash-max-ziplist-value | 64 | |
stream-node-max-bytes | 4096 | |
stream-node-max-entries | 100 | |
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 | |
lua-time-limit | 5000 | |
slowlog-log-slower-than | 10000 | |
latency-monitor-threshold | 0 | |
slowlog-max-len | 128 | |
cluster-announce-port | 0 | |
cluster-announce-bus-port | 0 | |
tcp-backlog | 511 | |
repl-ping-slave-period | 10 | |
repl-ping-replica-period | 10 | |
repl-timeout | 60 | |
repl-backlog-size | 1048576 | |
repl-backlog-ttl | 3600 | |
watchdog-period | 0 | |
slave-priority | 100 | |
replica-priority | 100 | |
slave-announce-port | 0 | |
replica-announce-port | 0 | |
min-slaves-to-write | 0 | |
min-replicas-to-write | 0 | |
min-slaves-max-lag | 10 | |
min-replicas-max-lag | 10 | |
hz | 10 | |
cluster-node-timeout | 15000 | |
cluster-migration-barrier | 1 | |
cluster-slave-validity-factor | 10 | |
cluster-replica-validity-factor | 10 | |
repl-diskless-sync-delay | 5 | |
tcp-keepalive | 300 | |
cluster-require-full-coverage | yes | |
cluster-slave-no-failover | no | |
cluster-replica-no-failover | no | |
no-appendfsync-on-rewrite | no | |
slave-serve-stale-data | yes | |
replica-serve-stale-data | yes | |
slave-read-only | yes | |
replica-read-only | yes | |
slave-ignore-maxmemory | yes | |
replica-ignore-maxmemory | yes | |
stop-writes-on-bgsave-error | yes | |
rdbchecksum | yes | |
activedefrag | no | |
protected-mode | yes | |
repl-disable-tcp-nodelay | no | |
repl-diskless-sync | no | |
aof-rewrite-incremental-fsync | yes | |
rdb-save-incremental-fsync | yes | |
aof-load-truncated | yes | |
aof-use-rdb-preamble | yes | |
lazyfree-lazy-eviction | no | |
lazyfree-lazy-expire | no | |
lazyfree-lazy-server-del | no | |
slave-lazy-flush | no | |
replica-lazy-flush | no | |
dynamic-hz | yes | |
maxmemory-policy | noeviction | |
supervised | no | |
syslog-facility | local0 | |
client-output-buffer-limit | normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60 | |
unixsocketperm | 0 | |
notify-keyspace-events |
Redis 配置生产环境建议