【问题标题】:Rack attack filling up hard drive space机架攻击填满硬盘空间
【发布时间】:2019-12-09 01:28:19
【问题描述】:

我也在GitHub 上问过这个问题,但似乎没有人回答。

问题是我使用 Rack Attack 作为阻止抓取的 gem。

我的配置位于here

我遇到的问题是将缓存写入文件系统并填满导致以下错误

No space left on device@ rb_sysopen - /var/app/current/tmp/cache/.rack%3A%3Aattack%3A5249968%3Areq%2Fip%3A104.199.176.25320191129-1869-11sg00n

如何防止这种情况发生?

【问题讨论】:

    标签: ruby-on-rails rackattack


    【解决方案1】:

    gem 文档没有提供有关缓存机制的任何信息,但查看源代码会告诉您they're using the Rails.cache,因此您可以查看。

    根据您给出的错误,您的 Rails 应用程序似乎使用了:file_store 缓存(这是默认缓存)和the Rails documentation says

    由于缓存会增长直到磁盘已满,建议定期清除旧条目。

    但是我发现a cleanup method 已经存在了一段时间(我从 Rails 版本 3 到 6 进行了检查)并且似乎知道过期数据,但是在 Rails 5.2 中已经修复了a bug preventing Rails to clean expired data。如果您使用的是 Rails 5.2 及更高版本,请尝试为缓存设置过期时间:

    config.cache_store = :file_store, Rails.root.join('tmp', 'cache'), { expires_in: 10.minutes }
    

    请更新缓存路径(第二个参数)并根据您的情况调整 expires_in 值。

    另一种选择是将change the Rails cache store 改为Redis(使用redis-rails gem)或Memcached

    当达到允许的空间限制时,Redis 会删除过期的键,Memcached 会删除最旧的键。

    【讨论】:

      猜你喜欢
      • 2021-03-03
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多