本文共 1357 字,大约阅读时间需要 4 分钟。
在配置文件开头包含其他配置文件,可以确保不会被后续重写。例如:
include /path/to/local.confinclude /path/to/other.conf
默认Redis不会作为守护进程运行。配置为yes后,Redis会将进程号写入指定文件:
daemonize yespidfile /var/run/redis.pid
默认监听所有网络接口,需用bind指定特定IP:
bind 192.168.1.100bind 127.0.0.1
设置监听Unix套接字的路径:
unixsocket /tmp/redis.sock
TCP连接 backlog设置建议:
tcp-backlog 511
设置空闲连接的关闭时间:
timeout 0
禁用TCP keepalive:
tcp-keepalive 0
设置日志等级,默认为notice:
loglevel notice
开启RDB快照,默认保存到dump.rdb文件:
save 900 1save 300 10save 60 10000
关闭RDB压缩:
rdbcompression no
添加CRC校验:
rdbchecksum yes
持久化目录:
dir ./
主从同步配置:
slaveof 192.168.1.100 6379
允许从服务器处理写操作:
slave-read-only yes
设置从服务器优先级:
slave-priority 100
禁用从服务器的写操作:
min-slaves-to-write 0
启用客户端身份验证:
requirepass your-secret-password
重命名危险命令,如禁用CONFIG:
rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
设置最大客户端数量:
maxclients 10000
内存限制和回收策略:
maxmemory 64mbmaxmemory-policy volatile-lru
启用AOF持久化,设置写入策略:
appendonly yesappendfsync everysec
自动重写AOF文件:
auto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mb
设置脚本执行时间限制:
lua-time-limit 5000
记录慢查询,超时为10秒:
slowlog-log-slower-than 10000slowlog-max-len 128
优化哈希表刷新:
activerehashing yes
设置列表和有序集合的内存优化:
hash-max-ziplist-entries 512zset-max-ziplist-entries 128
通过以上配置,您可以根据实际需求调整Redis服务器的性能和安全性。
转载地址:http://tdofk.baihongyu.com/