CentOS上的Redis配置文件通常位于/etc/redis/redis.conf
。以下是该配置文件的主要结构和部分关键配置项的解析:
全局配置
port
: Redis服务器监听的端口号。bind
: 绑定的IP地址,留空表示监听所有接口。protected-mode
: 是否启用保护模式,建议设置为yes
。daemonize
: 是否以守护进程方式运行,默认为no
。pidfile
: PID文件路径。logfile
: 日志文件路径。loglevel
: 日志级别,可选值有debug
、verbose
、notice
和warning
。持久化配置
save
: 设置自动保存快照的条件。appendonly
: 是否启用AOF持久化。appendfilename
: AOF文件名。appendfsync
: AOF同步策略,可选值有everysec
、always
和no
。安全性配置
requirepass
: 设置连接密码。masterauth
: 主节点认证密码(用于复制)。rename-command
: 重命名危险命令。内存管理配置
maxmemory
: 设置最大内存限制。maxmemory-policy
: 内存淘汰策略,可选值有volatile-lru
、allkeys-lru
等。网络配置
timeout
: 客户端空闲连接超时时间。tcp-keepalive
: TCP保持连接检测间隔。复制配置
slaveof
: 设置主节点地址和端口。repl-id
: 复制ID。repl-diskless-sync
: 是否启用无磁盘复制。repl-diskless-sync-delay
: 无磁盘复制的延迟时间。集群配置
cluster-enabled
: 是否启用集群模式。cluster-config-file
: 集群配置文件路径。cluster-node-timeout
: 节点超时时间。其他配置
lua-time-limit
: Lua脚本执行时间限制。notify-keyspace-events
: 键空间通知事件。# 全局配置
port 6379
bind 127.0.0.1
protected-mode yes
daemonize no
pidfile /var/run/redis_6379.pid
logfile /var/log/redis/redis_6379.log
loglevel notice
# 持久化配置
save 900 1
save 300 10
save 60 10000
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
# 安全性配置
requirepass your_password
masterauth your_master_password
rename-command FLUSHDB ""
rename-command FLUSHALL ""
# 内存管理配置
maxmemory 512mb
maxmemory-policy allkeys-lru
# 网络配置
timeout 300
tcp-keepalive 300
# 复制配置
slaveof 127.0.0.1 6380
repl-id your_replica_id
repl-diskless-sync yes
repl-diskless-sync-delay 5
# 集群配置
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
# 其他配置
lua-time-limit 5000
notify-keyspace-events KEA
maxmemory
策略,以确保数据的安全性和系统的稳定性。通过理解和配置这些关键项,可以更好地管理和优化Redis服务器的性能和安全性。