Ubuntu 上的 Squid 用尽文件描述符

Ubuntu 上的 Squid 用尽文件描述符

我在 Ubuntu 10.04 64 位上运行 Squid 2.7。我遇到了 Squid 用尽文件描述符的问题,/var/log/squid/cache.log 中显示以下错误:

警告!您的缓存文件描述符即将用完

我检查过:

squidclient mgr:信息|grep'文件描述'

它显示我只有 1024 个可用的文件描述符。

我更改了 /etc/security/limits.conf,在末尾添加了以下内容:

* soft nofile 32768
* hard nofile 32768
proxy           soft    nofile          32768
proxy           hard    nofile          32768

将其添加到 /etc/squid/squid.conf:

max_filedescriptors 32768

还更改了 /etc/default/squid:

SQUID_MAXFD=32768

什么都没发生。最后我编辑了 /etc/init.d/squid 并添加了“ulimit -n 32768”:

#!/bin/sh -e
# upstart-job
#
# Symlink target for initscripts that have been converted to Upstart.

set -e
ulimit -n 32768
<... snipped  ...>

成功了!:)

我必须在实时生产 Squid 服务器极其缓慢的压力下完成所有这些工作,所以我确信这不是正确的方法。

但正确的方法是什么?

答案1

您必须在 squid init 脚本中添加 ulimit 行,并在 squid.conf 中增加 max_filedescriptors。这是两个必不可少的步骤。您不再需要从源代码编译 squid 来增加此限制。这是您必须使用非常旧的 squid 版本才能做的事情。

答案2

我以前也遇到过同样的问题。我无法增加quid的文件描述符数量。

除了您所做的操作之外,我还使用以下配置选项配置了 squid:

./configure --prefix=/usr/local/squid --enable-start-stop-daemon --with-filedescriptors=65536 --enable-storeio=ufs,aufs --with-aufs-threads=10

案例的重要部分是:

--with-filedescriptors=65536

完成此操作并重新启动 squid 后,我得到了文件描述符的最大值:65536。

当然,这需要从源代码安装 squid,而不是通过命令安装:

apt-get install squid

答案3

/etc/init.d/squid 是 /lib/init/upstart-job 的符号链接,因此您最初的建议提高了所有 upstart 服务的 ulimit。

我同意原始问题/解决方案会提高文件描述符限制,所以谢谢你。理想情况下,一个不全面提高文件描述符的解决方案会更好。

相关内容