美文网首页
Redis优化策略及作为缓存的合理配置

Redis优化策略及作为缓存的合理配置

作者: Dakini_Wind | 来源:发表于2019-07-06 15:09 被阅读0次

优化策略

  1. 数据持久化使用RDB,不使用AOF。
  2. RDB保存时关闭压缩
  3. 使用LRU淘汰策略
  4. 允许Redis分配所有的物理内存
  5. 关闭Transparent Huge Pages(THP)
  6. 修改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

相关文章

网友评论

      本文标题:Redis优化策略及作为缓存的合理配置

      本文链接:https://www.haomeiwen.com/subject/clbphctx.html