Linking

Capturing Life & Tech

  • 主页
  • 随笔
  • 关于我
所有文章 外链

Linking

Capturing Life & Tech

  • 主页
  • 随笔
  • 关于我

redis.conf-readthrough

阅读数:次 2019-12-25
字数统计: 1.9k字   |   阅读时长≈ 11分

目录

  • 说明
  • 文件概况
  • 文件所含节点
    • 0.开始
    • 1.Includes
    • 2.Modules
    • 3.NetWork
    • 4.General
    • 5.Snapshotting
    • 6.Replication
    • 7.Security
    • 8.Clients
    • 9.Memory Management
    • 10.Lazy Freeing
    • 11.Appned only mode
    • 12.lua scripting
    • 13.redis cluster
    • 14.CLUSTER DOCKER/NAT support
    • 15.Slow Log
    • 16.LATENCY MONITOR
    • 17.EVENT NOTIFICATION
    • 18.ADVANCED CONFIG
    • 19.ACTIVE DEFRAGMENTATION
  • 总结
    • 第一次梳理

说明

解读官方配置文件,也可以说是翻译。

借此机会,深入了解Redis。

旨在梳理一遍,不会逐行翻译。大体根据自己的理解,记录重要的点。

文件概况

  • lines: 1317
1
wc -l redis.conf
  • words: 10187
1
wc -w redis.conf

文件所含节点

文档所述,共包含8个节点。分别如下

0.开始

使配置文件生效,必须采用特别的启动方式

1
./redis-server /path/to/redis.conf

关于内存单位的说明

1
2
3
4
5
6
1k  == 1000 bytes
1kb == 1024 bytes
1m == 1000 * 1000 bytes
1mb == 1024 * 1024 bytes
1g == 1000 * 1000 * 1000 bytes
1gb == 1024 * 1024 * 1024 bytes

结论1:1k 和 1kb是不一样的,1000 和 1024 的差距;2:以 1000 和 1024 的次方增长。

单位不区分大小写,如 1GB 1gB 1Gb是等同的。

1.Includes

配置文件嵌套,适合一些定制化的配置,配置文件又可以include配置文件。

1
2
include /path/to/local.conf
include /path/to/other.conf

2.Modules

Load modules at startup.

1
loadmodule /path/to/my_module.so

load local native module

3.NetWork

  • bind

if no bind configuration directive, Redis listens for connections from all the network interfaces auailable on the server.

examples:

1
2
bind 192.168.1.100 10.0.0.1
bind 127.0.0.1 ::1

if Redis directly exposed to internet, binding to all interface is dangerous.

1
2
# uncomment following bin directive, Redis accept connections only from clients running into same computer it is running. comment..., it is dangerous if Redis is exposed to internet. 
bind 127.0.0.1
  • protected-mode

与bind配合使用,如果bind配置了ip,则只有ip内的connect client才被accept。默认开启

1
protected-mode yes
  • port

if port 0 is specified Redis will not listen on TCP scoket.

1
port 6379
  • tcp-backlog

TCP listen() log.

1
tcp-backlog 511
  • Unix socket

unix socket used to listen for incoming connections.
no default

1
2
unixsocket /tmp/redis.sock
unixsocketperm 700
  • timeout

close connection after client idle for N seconds
0 disable

1
timeout 0
  • tcp-keepalive

period used to send TCP ACKs to client.

1
tcp-keepalive 300

4.General

  • daemonize

run as a daemon

1
daemonize yes
  • supervised
  • supervised no
  • supervised upstart
  • supervised systemd
  • supervised auto
1
supervised no
  • pidfile

若指定该文件,则会自动创建、自动remove;non daemonized, no pidfile if none is specified following. daemonized, if non specified pipfile, it has default “/var/run/redis.pid”.

1
pidfile /var/run/redis_6379.pip
  • loglevel
  • debug
  • verbose
  • notice
  • warning
1
loglevel notice
  • logfile

empty string, logs will be send to /dev/null

1
logfile "/usr/local/redis/log/redis.log"
  • syslog-enable
1
syslog-enable no
  • syslog-ident

syslog identity

1
syslog-ident redis
  • syslog-facility

must be user or between LOCAL0-LOCAL7

1
syslog-facility local0
  • databases

default 0

1
databases 16
  • always-show-logo
1
always-show-logo yes

5.Snapshotting

  • save

save db if both seconds and write operations against the db occurred.

Save db on disk:

    save <seconds> <changes>

remove all previously configured save points

    save ""
1
2
3
4
# 900 sec at least 1 key changed
save 900 1
save 300 10
save 60 10000
  • stop-writes-on-bgsave-error
1
stop-writes-on-bgsave-error yes
  • rdbcompression

compress string objects using LZF when dump .rdb databases.

1
rdbcompression yes
  • rdbchecksum
1
rdbchecksum yes
  • dbfilename
1
dbfilename dump.rdb
  • dir
  • Important. if not specified, db file or append only file will store in a directory you just opened. create so many uselessfile.
  • working directory store db.
  • .rdb and .aof file store in.
  • specify a directory, not file name.
1
dir /usr/local/redis/data/

6.Replication

  • Master-Slave replication
1
slaveof <masterip> <masterport>
  • master is password protected
1
masterauth <master-password>
  • slave loses its connection with the master
  • yes: slave still reply to client requests
  • no: slave will reply with error “SYNC with master in progress”
1
slave-serve-stale-data yes
  • slave instance to accept writes or not
1
slave-read-only yes
  • Replication SYNC strategy: disk or socket
  • 1.Disk-backed: Redis master creates a new process that writes the RDB file on disk. Later the file is transferred by the parent process to the slaves incrementally
  • 2.Diskless: Redis master creates a new process that directly writes the RDB file to slave sockets, without touching the disk
1
repl-diskless-sync no
  • delay the server waits
1
repl-diskless-sync-delay 5
  • Slaves send PINGs to server in a predefined interval
1
repl-ping-slave-period 10
  • replication timeout

greater than the value specified for repl-ping-slave-period

1
repl-timeout 60
  • TCP_NODELAY on the slave socket after SYNC
  • 1.”yes” Redis will use a smaller number of TCP packets and less bandwidth to send data to slaves
  • 2.”no” the delay for data to appear on the slave side will be reduced but more bandwidth will be used for replication
1
repl-disable-tcp-nodelay no
  • replication backlog size

    • buffer
    • slaves are disconnected
    • full resync is not needed, but a partial resync is enough, just passing the portion of data the slave missed while disconnected.
1
repl-backlog-size 1mb
  • master has no longer connected slaves for some time, the backlog will be freed

seconds that need to elapse, starting from the time the last slave disconnected, for the backlog buffer to be freed.

1
# repl-backlog-ttl 3600
  • slave priority
  • master no longer working, select from slave as master.选举
  • 优先级,数字越小越考前,当然0不能被选做master
1
slave-priority 100
  • master to stop accepting writes if there are less than N slaves connected
1
2
# min-slaves-to-write 3
# min-slaves-max-lag 10
  • master is able to list the address and port of the attached slaves in different ways
1
2
# slave-announce-ip 5.5.5.5
# slave-announce-port 1234

7.Security

  • Require clients issue AUTH

useful in environments in which you do not trust others. stay commented

1
# requirepass foobared
  • command renaming

dangerous commands in shared environment.

1
2
# Example:
# rename-command CONFIG b8123sdfa98df6asd7fa93asdf323j

8.Clients

  • max number of connected clients at the same time.
1
# maxclients 10000

9.Memory Management

  • max memory
1
# maxmemory <bytes>
  • max memory policy noeviction

maxmemory policy: how Redis will select what to remove when maxmemory reached.

# policies:
- # volatile-lru -> Evict using approximated LRU among the keys with an expire set.
- # allkeys-lru -> Evict any key using approximated LRU.
- # volatile-lfu -> Evict using approximated LFU among the keys with an expire set.
- # allkeys-lfu -> Evict any key using approximated LFU.
- # volatile-random -> Remove a random key among the ones with an expire set.
- # allkeys-random -> Remove a random key, any key.
- # volatile-ttl -> Remove the key with the nearest expire time (minor TTL)
- # noeviction -> Don't evict anything, just return an error on write operations.
- #
- # LRU means Least Recently Used
- # LFU means Least Frequently Used
1
maxmemory-policy noeviction
  • max memory samples
1
# maxmemory-samples 5

10.Lazy Freeing

two primitives to delete keys. one: del, blocking deletion of object. two: non blocking deletion, such as unlink and async option of flushall, flushdb. reclaim memory in background.

release memory in a non-blocking way like if UNLINK was called, using following configuration directives:

1
2
3
4
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy--server-del no
lazyfree-lazy-flush no

11.Appned only mode

  • appendonly yes or no
  • asynchronously dumps dataset on disk.
  • can lose just one second of wirtes
1
appendonly yes
  • append filename

append only file store in dir

1
appendfilename "appendonly.aof"
  • appendfsync
1
2
3
# appendfsync always 
appendfsync everysec
# appendfsync no
  • no appendfsync on rewrite
1
no-appendfsync-on-rewrite yes
  • automatic rewrite of the append only file
1
2
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
  • aof load truncated
1
aof-load-truncated yes
  • aof use rdb preamble
1
aof-use-rdb-preamble no

12.lua scripting

  • max execution time of a lua script in milliseconds.

set 0 or negative value for unlimited execution without warnings.

1
lua-time-limit 5000

13.redis cluster

  • cluster enable

start a Redis instance as a cluster node enable the cluster.

1
# cluster-enable yes
  • cluster config file
1
cluster-config-file nodes-6379.conf
  • cluster node timeout
1
cluster-node-timeout 15000
  • cluster slave validity factor
1
# cluster-slave-validity-factor 10
  • cluster migration barrier
1
cluster-migration-barrier 1
  • cluster require full coverage
1
cluster-require-full-coverage yes
  • cluster slave no failover
  • 故障转移?
  • prevents slaves from trying to failover its master during master failures.
1
cluster-slave-no-failover

14.CLUSTER DOCKER/NAT support

Redis Cluster nodes address discovery fails. A static configuration where each node knows its public address.

  • cluster-announce-ip
  • cluster-announce-port
  • cluster-announce-bus-port
1
2
3
# cluster-announce-ip
# cluster-announce-port
# cluster-announce-bus-port

15.Slow Log

  • execution time, in microseconds
1
slowlog-log-slower-than 10000
  • length of the slow log
1
slowlog-max-len 128

16.LATENCY MONITOR

  • 隐形监控
  • latency-monitor-threshold
  • time equal or greater than , system will operate in order to collect data related to possible sources of latency of a Redis instance.
  • 0: turn off
1
latency-monitor-threshold 0

17.EVENT NOTIFICATION

  • notify Pub/Sub clients about events happening in the key space.
  • document: http://redis.io/topics/notifications
1
notify-keyspace-events ""

18.ADVANCED CONFIG

高级配置?

  • hash encoded using memory efficient data structure. biggest entyr does not exceed a given threshold.
1
2
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
  • list-max-ziplist-size
1
list-max-ziplist-size -2
  • lsit-compress-depth
1
lsit-compress-depth 0
  • set-max-intset-entries
1
set-max-intset-entries 512
1
2
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
1
hll-sparse-max-bytes 3000
1
activerehashing yes
1
2
3
client-output-buffer-limit normal 0 0 0 
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
1
hz 10
1
apf-rewrite-incremental-fsync yes

19.ACTIVE DEFRAGMENTATION

  • experimental
  • 内存碎片重组、压缩
  • activedefrag yes or no
1
# activedefrag yes
  • active-defrag-ignore-bytes
1
# active-defrag-ignore-bytes 100mb
  • active-defrag-threshold-lower
1
# active-defrag-threshold-lower 10
  • active-defrag-threshold-upper
1
# active-defrag-threshold-upper 100
  • active-defrag-cycle-min
1
# active-defrag-cycle-min 25
  • active-defrag-cycle-max
1
# active-defrag-cycle-max 75

总结

第一次梳理

本次只是简单的过一遍,在后面用到的过程中,有个印象,及时的找到需要的配置。

很多属性还没有用过,需要在项目中或者自己创造条件运用,测试。

  • 本文作者: Linking
  • 本文链接: https://linking.fun/2019/12/25/redis-conf-readthrough/
  • 版权声明: 版权所有,转载请注明出处!
  • redis
  • CS

扫一扫,分享到微信

APPScan-SQL盲注与xss跨站点脚本编织问题记录
nginx安装后添加第三方module
  1. 1. 目录
  2. 2. 说明
  3. 3. 文件概况
  4. 4. 文件所含节点
    1. 4.1. 0.开始
    2. 4.2. 1.Includes
    3. 4.3. 2.Modules
    4. 4.4. 3.NetWork
    5. 4.5. 4.General
    6. 4.6. 5.Snapshotting
    7. 4.7. 6.Replication
    8. 4.8. 7.Security
    9. 4.9. 8.Clients
    10. 4.10. 9.Memory Management
    11. 4.11. 10.Lazy Freeing
    12. 4.12. 11.Appned only mode
    13. 4.13. 12.lua scripting
    14. 4.14. 13.redis cluster
    15. 4.15. 14.CLUSTER DOCKER/NAT support
    16. 4.16. 15.Slow Log
    17. 4.17. 16.LATENCY MONITOR
    18. 4.18. 17.EVENT NOTIFICATION
    19. 4.19. 18.ADVANCED CONFIG
    20. 4.20. 19.ACTIVE DEFRAGMENTATION
  5. 5. 总结
    1. 5.1. 第一次梳理
© 2015-2026 Linking
GitHub:hexo-theme-yilia-plus by Litten
本站总访问量次 | 本站访客数人
  • 所有文章
  • 外链

tag:

  • weather
  • 需求
  • essay
  • basketball
  • olympic
  • nginx
  • APPScan
  • SQl盲注
  • xss
  • Ajax
  • ajax
  • ai
  • agent
  • openclaw
  • ccf
  • Nginx
  • HTML5
  • html5
  • hmtl5
  • sse
  • JavaScriptCore
  • Oracle
  • operation
  • Linux
  • deploy
  • Mac Office
  • markdown
  • ListView
  • GridView
  • MySQL
  • 慢查询
  • mongodb
  • 转置
  • thought
  • network
  • ubuntu
  • NetworkManager
  • RFKill
  • Netplan
  • avatar
  • cocoa
  • blog
  • Gitalk
  • container
  • macvlan
  • docker
  • oracle
  • cookie
  • patch
  • gitea
  • git
  • iOS
  • https
  • 多线程
  • bundle
  • 兼容性
  • HTTP
  • 绘图
  • cs
  • java
  • 效率
  • 快捷键
  • route
  • nodejs
  • pip
  • arcgis
  • arcgis 建模
  • 标识
  • redis
  • read
  • bookList
  • running
  • showdoc
  • disk
  • unit-test
  • D.Wade
  • thoughts
  • duoduo
  • Python
  • python
  • tomcat
  • 读书节
  • session
  • jdk
  • war
  • 加班
  • Android onclick事件监听
  • 正则
  • 手机品牌匹配
  • ntp
  • OpenLayers
  • Geoserver
  • wechat
  • 微信公众号
  • 爬虫
  • WeChat
  • 张靓颖
  • 动漫
  • vpn
  • PPT
  • MarkDown
  • plan
  • 朱赟
  • 极客时间专栏
  • 极客邦
  • 模块化
  • MVC
  • excel
  • NBA
  • kobe
  • team
  • crawler
  • 进度条
  • ssl
  • book
  • anti-stealing-link
  • Agentic Engineering
  • Vibe Coding
  • Software 3.0
  • Andrej Karpathy
  • LLM
  • Programming

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia-plus根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

  • GitHub Trending
  • OpenAI ChatGPT
  • Gitee码云
  • 简书
  • CSDN