最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】WordPress的PHP的log日志出现:PHP message RedisException OOM command not allowed when used memory maxmemory in plugins redis-cache

WordPress crifan 569浏览 0评论
折腾:
【未解决】去修复WordPress登录页死循环:去看php的log日志
期间,去看看php的log,其中发现:
[[email protected] log]# tail php-fpm.log
PHP message: PHP Deprecated:  在d_textbanner中为WP_Widget调用的构造函数已自版本4.3.0起<strong>废弃</strong>!请改用<code>__construct()</code>。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4866"
PHP message: RedisException: OOM command not allowed when used memory > 'maxmemory'. in /data/wwwroot/www.crifan.com/wp-content/plugins/redis-cache/includes/class-plugin.php:898"
Stack trace:"
#0 /data/wwwroot/www.crifan.com/wp-content/plugins/redis-cache/includes/class-plugin.php(898): Redis->zAdd('wp:redis-cache:...', 1604106870, 'i=7644e3c;h=464...')"
#1 /data/wwwroot/www.crifan.com/wp-includes/class-wp-hook.php(287): Rhubarb\RedisCache\Plugin->record_metrics('')"
#2 /data/wwwroot/www.crifan.com/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array)"
#3 /data/wwwroot/www.crifan.com/wp-includes/plugin.php(478): WP_Hook->do_action(Array)"
#4 /data/wwwroot/www.crifan.com/wp-includes/load.php(1007): do_action('shutdown')"
#5 [internal function]: shutdown_action_hook()"
#6 {main}"
看起来是:
PHP message: RedisException: OOM command not allowed when used memory > 'maxmemory'
和redis有关,且OOM是out of memory,内存不够用了?
或许就是redis导致cookie没法正常保存,无法登录的?
不过去看看更多行的log:
[[email protected] log]# tail -n 40 php-fpm.log 
PHP message: RedisException: OOM command not allowed when used memory > 'maxmemory'. in /data/wwwroot/www.crifan.com/wp-content/object-cache.php:1570"
Stack trace:"
#0 /data/wwwroot/www.crifan.com/wp-content/object-cache.php(1570): Redis->set('wp:transient:do...', '1604106893.6660...')"
#1 /data/wwwroot/www.crifan.com/wp-content/object-cache.php(203): WP_Object_Cache->set('doing_cron', '1604106893.6660...', 'transient', 0)"
#2 /data/wwwroot/www.crifan.com/wp-includes/option.php(875): wp_cache_set('doing_cron', '1604106893.6660...', 'transient', 0)"
#3 /data/wwwroot/www.crifan.com/wp-includes/cron.php(691): set_transient('doing_cron', '1604106893.6660...')"
#4 /data/wwwroot/www.crifan.com/wp-includes/cron.php(774): spawn_cron(1604106893.6661)"
#5 /data/wwwroot/www.crifan.com/wp-includes/class-wp-hook.php(287): wp_cron('')"
#6 /data/wwwroot/www.crifan.com/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array)"
#7 /data/wwwroot/www.crifan.com/wp-includes/plugin.php(478): WP_Hook->do_action(Array)"
#8 ..."
PHP message: PHP Notice:  Undefined variable: wp_sh_class_name in /data/wwwroot/www.crifan.com/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1002"
PHP message: PHP Notice:  Undefined variable: wp_sh_class_name in /data/wwwroot/www.crifan.com/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1002"
PHP message: PHP Warning:  Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.com/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048"
PHP message: PHP Notice:  wp_deregister_script的调用方法<strong>不正确</strong>。脚本和样式应在<code>wp_enqueue_scripts</code>、<code>admin_enqueue_scripts</code>和<code>login_enqueue_scripts</code>钩子之后再加入加载队列(enqueue)或注册(register)。 This notice was triggered by the <code>l10n</code> handle. 请查阅<a href="https://wordpress.org/support/article/debugging-in-wordpress/">调试WordPress</a>来获取更多信息。 (这个消息是在3.3.0版本添加的。) in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 5225"
PHP message: PHP Warning:  Use of undefined constant DESC - assumed 'DESC' (this will throw an Error in a future version of PHP) in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/404.php on line 10"
PHP message: PHP Deprecated:  自3.1.0版本起,已<strong>不建议</strong>给WP_Query传入一个参数!<code>caller_get_posts</code>已被废弃,请改用<code>ignore_sticky_posts</code>。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 5057"
PHP message: PHP Notice:  Undefined variable: control_ops in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-banner.php on line 11"
PHP message: PHP Deprecated:  在d_banner中为WP_Widget调用的构造函数已自版本4.3.0起<strong>废弃</strong>!请改用<code>__construct()</code>。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4866"
PHP message: PHP Notice:  Undefined variable: control_ops in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-slidebanner.php on line 11"
PHP message: PHP Deprecated:  在d_slidebanner中为WP_Widget调用的构造函数已自版本4.3.0起<strong>废弃</strong>!请改用<code>__construct()</code>。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4866"
PHP message: PHP Notice:  Undefined variable: control_ops in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-readers.php on line 11"
PHP message: PHP Deprecated:  在d_reader中为WP_Widget调用的构造函数已自版本4.3.0起<strong>废弃</strong>!请改用<code>__construct()</code>。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4866"
PHP message: PHP Notice:  Undefined variable: control_ops in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-postlist.php on line 11"
PHP message: PHP Deprecated:  在d_postlist中为WP_Widget调用的构造函数已自版本4.3.0起<strong>废弃</strong>!请改用<code>__construct()</code>。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4866"
PHP message: PHP Notice:  Undefined variable: control_ops in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-comment.php on line 11"
PHP message: PHP Deprecated:  在d_comment中为WP_Widget调用的构造函数已自版本4.3.0起<strong>废弃</strong>!请改用<code>__construct()</code>。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4866"
PHP message: PHP Notice:  Undefined variable: control_ops in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-tags.php on line 11"
PHP message: PHP Deprecated:  在d_tag中为WP_Widget调用的构造函数已自版本4.3.0起<strong>废弃</strong>!请改用<code>__construct()</code>。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4866"
PHP message: PHP Notice:  Undefined variable: control_ops in /data/wwwroot/www.crifan.com/wp-content/themes/daqianduan-d8-jquiss/widgets/wid-textbanner.php on line 11"
PHP message: PHP Deprecated:  在d_textbanner中为WP_Widget调用的构造函数已自版本4.3.0起<strong>废弃</strong>!请改用<code>__construct()</code>。 in /data/wwwroot/www.crifan.com/wp-includes/functions.php on line 4866"
PHP message: RedisException: OOM command not allowed when used memory > 'maxmemory'. in /data/wwwroot/www.crifan.com/wp-content/plugins/redis-cache/includes/class-plugin.php:898"
Stack trace:"
#0 /data/wwwroot/www.crifan.com/wp-content/plugins/redis-cache/includes/class-plugin.php(898): Redis->zAdd('wp:redis-cache:...', 1604106893, 'i=8db1692;h=464...')"
#1 /data/wwwroot/www.crifan.com/wp-includes/class-wp-hook.php(287): Rhubarb\RedisCache\Plugin->record_metrics('')"
#2 /data/wwwroot/www.crifan.com/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array)"
#3 /data/wwwroot/www.crifan.com/wp-includes/plugin.php(478): WP_Hook->do_action(Array)"
#4 /data/wwwroot/www.crifan.com/wp-includes/load.php(1007): do_action('shutdown')"
#5 [internal function]: shutdown_action_hook()"
#6 {main}"
除了中间的php的提示,好像就只是此处的 RedisException: OOM 的问题了。
wordpress RedisException OOM
WordPress排查解决您的站点遇到了致命错误的过程-Redis内存缓存不足 – 全部 – 真不是你的
#0 /data/wwwroot/www.crifan.com/wp-content/plugins/redis-cache/includes/class-plugin.php(898): Redis->zAdd('wp:redis-cache:...', 1604106893, 'i=8db1692;h=464...')"
此处直接的原因就是:
redis-cache
[[email protected] log]# redis-cli
127.0.0.1:6379> info memory
# Memory
used_memory:473004392
used_memory_human:451.09M
used_memory_rss:495353856
used_memory_rss_human:472.41M
used_memory_peak:478294600
used_memory_peak_human:456.14M
used_memory_peak_perc:98.89%
used_memory_overhead:80705822
used_memory_startup:791200
used_memory_dataset:392298570
used_memory_dataset_perc:83.08%
allocator_allocated:473418200
allocator_active:482840576
allocator_resident:497201152
total_system_memory:3973521408
total_system_memory_human:3.70G
used_memory_lua:37888
used_memory_lua_human:37.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:473000000
maxmemory_human:451.09M
maxmemory_policy:noeviction
allocator_frag_ratio:1.02
allocator_frag_bytes:9422376
allocator_rss_ratio:1.03
allocator_rss_bytes:14360576
rss_overhead_ratio:1.00
rss_overhead_bytes:-1847296
mem_fragmentation_ratio:1.05
mem_fragmentation_bytes:22390488
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:49694
mem_aof_buffer:0
mem_allocator:jemalloc-5.1.0
active_defrag_running:0
lazyfree_pending_objects:0
127.0.0.1:6379> 
其中:
  • used_memory_human:451.09M
  • maxmemory_human:451.09M
的确是已占用完毕了。
去调整:
vi /usr/local/redis/etc/redis.conf
去看看原先内容
Vultr/usr/local/redis/etc/redis.conf
maxmemory 473000000
-》
473000000 = 451.08795166015625 MB
-》的确是上面的结果:used_memory_human 已经用的内容,超过了 最大的内存maxmemory_human
去改大点,比如1G
# maxmemory 473000000
maxmemory 1073741824
以及:
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
#
# volatile-lru -> Evict using approximated LRU among the keys with an expire set.
# allkeys-lru -> Evict any key using approximated LRU.
# volatile-lfu -> Evict using approximated LFU among the keys with an expire set.
# allkeys-lfu -> Evict any key using approximated LFU.
# volatile-random -> Remove a random key among the ones with an expire set.
# allkeys-random -> Remove a random key, any key.
# volatile-ttl -> Remove the key with the nearest expire time (minor TTL)
# noeviction -> Don't evict anything, just return an error on write operations.
#
# LRU means Least Recently Used
# LFU means Least Frequently Used
#
# Both LRU, LFU and volatile-ttl are implemented using approximated
# randomized algorithms.
#
# Note: with any of the above policies, Redis will return an error on write
#       operations, when there are no suitable keys for eviction.
#
#       At the date of writing these commands are: set setnx setex append
#       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
#       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
#       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
#       getset mset msetnx exec sort
#
# The default is:
#
# maxmemory-policy noeviction
去改为:
# maxmemory-policy noeviction
maxmemory-policy volatile-lru
然后重启redis:
service redis-server restart
不过重启之前,删除php的log:
[[email protected] log]# cd /usr/local/php/var/log/
[[email protected] log]# lh
total 5.8G
-rw------- 1 root root 5.8G Oct 31 09:29 php-fpm.log
[[email protected] log]# rm -rf php-fpm.log
[[email protected] log]# lh
total 0
这样后续更方便调试,找到最新的log
[[email protected] log]# service redis-server restart
Redirecting to /bin/systemctl restart redis-server.service
再去确保redis正常运行了:
[[email protected] log]# service redis-server status
Redirecting to /bin/systemctl status redis-server.service
● redis-server.service - Redis In-Memory Data Store
   Loaded: loaded (/usr/lib/systemd/system/redis-server.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-10-31 09:30:37 CST; 17s ago
  Process: 11169 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
  Process: 11180 ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf (code=exited, status=0/SUCCESS)
  Process: 11177 ExecStartPre=/bin/chown -R redis:redis ${statedir} (code=exited, status=0/SUCCESS)
  Process: 11175 ExecStartPre=/bin/mkdir -p ${statedir} (code=exited, status=0/SUCCESS)
 Main PID: 11183 (redis-server)
   CGroup: /system.slice/redis-server.service
           └─11183 /usr/local/redis/bin/redis-server 127.0.0.1:6379

Oct 31 09:30:37 crifan.com systemd[1]: Starting Redis In-Memory Data Store...
Oct 31 09:30:37 crifan.com systemd[1]: PID file /var/run/redis/redis.pid not readable (yet?) after start.
Oct 31 09:30:37 crifan.com systemd[1]: Started Redis In-Memory Data Store.
重启php-fpm:
[[email protected] log]# service php-fpm restart
Redirecting to /bin/systemctl restart php-fpm.service
结果:问题依旧。
不过再去试了试,突然发现
看到页面中提示cookie问题
点击了 启用cookie
跳转到WordPress官网页面,没啥帮助
点击返回之后,突然发现,貌似好了?
可以跳转到wp-admin
换Safari浏览器,也可以了:
-》
说明此处就是
redis的cache超过大小了,导致cookie有问题,导致虽然用户名和密码都正确,但是由于生成的cookie,无法被正常保存,导致登录实际上没生效,无法登录,还会跳转回登录页
而前面之所以问题解决,是因为:
根据错误提示,点击了 开启cookie
然后内部redis根据之前设置的:
maxmemory-policy volatile-lru
去清理掉之前不用的cookie
或者说,由于maxmemory已经增加了,有额外空间保存新登录生成的cookie了,就可以了使得登录生效了。
【总结】
此处php的log中报错:
PHP message: RedisException: OOM command not allowed when used memory > 'maxmemory'
背景:
此处WordPress开启了redis作为缓存
原因:此处redis已使用的缓存空间,超过了最大允许值,导致无更多可用内存空间供保存缓存
解决办法:
增加缓存空间
且同时调整缓存策略:确保可以及时删除掉旧的不用的缓存,以便于腾出空间给新内容去缓存
具体办法:
编辑配置文件
/usr/local/redis/etc/redis.conf
增加最大缓存大小,比如1G:
maxmemory 1073741824
另外,也更改缓存失效剔除策略为:
maxmemory-policy volatile-lru
即可。
注:
(1)更改配置后要重启redis
service redis-server restart
也最好顺带重启一下php
service php-fpm restart
查看状态是:
service redis-server status
service php-fpm status
(2)默认内存策略是
maxmemory-policy noeviction
  • noeviction
    • eviction:驱赶,剔除
      • no eviction = 不剔除
        • 即使缓存满了也不剔除
          • 导致后续内容无法被redis缓存
            • 导致(登录后的)新cookie无法被保存,导致无法登录
(3)如何发现是缓存满的了?
参考别人帖子:
WordPress排查解决您的站点遇到了致命错误的过程-Redis内存缓存不足 – 全部 – 真不是你的
redis-cli
info memory
查看
redis中的 当前已使用缓存内存空间 和 最大允许缓存内存空间大小
分别对应的是:
  • used_memory_human
  • maxmemory_human
自己此处分别都是:451.09M
对应着配置文件中的
/usr/local/redis/etc/redis.conf
maxmemory 473000000
-》473000000 = 451.08795166015625 MB = 451.09 MB
由此得知,redis缓存满了

转载请注明:在路上 » 【已解决】WordPress的PHP的log日志出现:PHP message RedisException OOM command not allowed when used memory maxmemory in plugins redis-cache

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
89 queries in 0.118 seconds, using 20.59MB memory