优化策略
- 数据持久化使用RDB,不使用AOF。
- RDB保存时关闭压缩
- 使用LRU淘汰策略
- 允许Redis分配所有的物理内存
- 关闭Transparent Huge Pages(THP)
- 修改Linux的tcp连接数量
配置文件(Redis5.05)
针对于Redis作为缓存系统
bind 0.0.0.0
protected-mode no
port 6739
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile "/var/run/redis.pid"
loglevel notice
logfile "master.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression no
rdbchecksum yes
dbfilename "dump.rdb"
dir "./"
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
appendonly no
一键优化
#!/bin/bash
echo "内存分配优化"
#以下为永久生效
#echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
sysctl vm.overcommit_memory=1
echo "关闭THP"
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo "tcp优化"
sysctl -w net.ipv4.tcp_timestamps=1
#sysctl -w net.ipv4.tcp_tw_recycle=1
sysctl net.core.somaxconn=65535
网友评论