Redis服务器高CPUdebugging策略

最近,我们注意到由redis引起的生产环境的CPU峰值,这可以在下面看到:

在这里输入图像说明

为了解决这个问题,我每天大概两次重新启动redis服务器(这显然很不理想,我想找出根本原因。

以下是我到目前为止所看到的一些事情:
1)查看redis日志文件中的任何exception。 以下似乎是可疑的:

在这里输入图像说明

2)研究了nginx的访问日志,看看我们是否遇到exception高的stream量。 答案是不。

3)New Relic透露,这个问题从16日(大约一个月前)的11月21日开始,但是在那个时候没有发布代码。

以下是关于我们设置的一些细节:

Redis服务器: Redis server v=2.8.17 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=64a9cf396cbcc4c7

PHP: 5.3.27与fpm

Redisconfiguration:

 daemonize yes pidfile /var/run/redis/redis.pid port 6379 timeout 0 tcp-keepalive 0 loglevel notice logfile /var/log/redis/redis.log syslog-enabled yes databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error no rdbcompression yes rdbchecksum yes dbfilename redis.rdb dir /var/lib/redis/ slave-serve-stale-data yes slave-read-only yes repl-disable-tcp-nodelay no slave-priority 100 maxmemory 15GB appendonly no appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb lua-time-limit 5000 slowlog-max-len 128 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-entries 512 list-max-ziplist-value 64 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes include /etc/redis/conf.d/local.conf 

框架:Magento 1.7.2与Cm_Cache_Backend_Redis

请让我知道,如果给予上述信息有什么我可以做,以缓解高CPU使用率。

非常重要的更新

您的服务器可能已被黑客入侵。 这不是引起高CPU使用率的redis,而是一个单独的命令叫做yam(看看你的htop的最右边,我第一次错过它)。 yam命令用于众所周知的redis攻击,通常会导致CPU使用率过高。 您需要仔细检查以确保您的服务器是安全的。

这里有一些文章和链接,你可以参考,如果你想了解更多的漏洞和如何保护自己:


这是我的核对清单magento / redis,呃,性能问题:

  1. 确保你使用的是新版本的redis,比如3.2,如果在CentOS上,我个人更喜欢IUS仓库中的redis32u。
  2. 检查你的redis数据库的大小,它应该在/var/lib/redis ,并确保它比较小。
  3. 确认你有足够的ram用于redis。 你已经指定了一个15GB的maxmemory ,对于magento来说真是maxmemory过分了。 我通常使用更接近256mb东西。 如果你正在使用redis(!!!!!!),你可能在你的magento堆栈中有其他问题。
  4. 确保在syscntl中设置了vm overcommit设置。 https://redis.io/topics/admin (有关您需要的更多详细信息,请参阅此链接)
  5. 确保你有足够的开放文件限制来处理连接到redis的数量。

一般来说,日志文件是不可疑的,因为你的redis保存设置告诉redis保存每分钟如果已经> 10000写,每五分钟如果已经> 10写,每15分钟,如果已经> 1写。 所以它基本上是每分钟坚持信息到磁盘,这不应该是繁重的。