CentOS上的Redis配置文件通常位于/etc/redis/redis.conf
。以下是一些常见的配置参数及其详解:
bind
127.0.0.1
bind 0.0.0.0
允许所有IP访问。port
6379
daemonize
no
daemonize yes
以后台模式运行。pidfile
/var/run/redis.pid
logfile
/var/log/redis/redis.log
logfile /var/log/redis/redis.log
dbfilename
dump.rdb
dir
save
save 900 1
表示900秒内至少有1个key发生变化时进行快照。appendonly
no
appendonly yes
开启AOF持久化。appendfilename
appendonly.aof
appendfsync
always
:每次写操作都同步到磁盘(最安全,性能最低)。everysec
:每秒同步一次(折中方案)。no
:不同步,由操作系统决定(性能最高,安全性最低)。everysec
maxmemory
maxmemory 1gb
maxmemory-policy
volatile-lru
:从设置了过期时间的key中使用LRU算法淘汰数据。allkeys-lru
:从所有key中使用LRU算法淘汰数据。volatile-random
:从设置了过期时间的key中随机淘汰数据。allkeys-random
:从所有key中随机淘汰数据。volatile-ttl
:从设置了过期时间的key中淘汰剩余生存时间最短的key。noeviction
:不淘汰数据,只是返回错误信息。noeviction
timeout
0
表示不关闭空闲连接。tcp-keepalive
0
表示不发送keepalive探测。requirepass
requirepass yourpassword
masterauth
masterauth yourmasterpassword
slaveof
slaveof 127.0.0.1 6379
rename-command
rename-command FLUSHDB ""
禁用FLUSHDB命令。stop-writes-on-bgsave-error
yes
rdbcompression
yes
rdbchecksum
yes
dbfragments
no
lua-time-limit
5000
slowlog-log-slower-than
10000
毫秒slowlog-max-len
128
这些参数可以根据实际需求进行调整,以达到最佳的性能和安全性。修改配置文件后,需要重启Redis服务使更改生效:
sudo systemctl restart redis
希望这些信息对你有所帮助!如果有更多问题,请随时提问。