apache2ctl: 87: ulimit: error setting limit (Operation not allowed)

Pas*_*nus 12 debian apache-2.2 debian-wheezy

服务器运行良好——或者至少看起来如此——但总是出现以下错误:

apache2/usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)

它发生在 Debian Wheezy 上的 Apache 2.2.22-9 上。

# apache2ctl configtest

/usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not allowed)
Syntax OK

# service apache2 reload

[....] 重新加载 Web 服务器配置:apache2/usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not allowed)
。好的

# service apache2 restart

[....] 重新启动 Web 服务器:apache2/usr/sbin/apache2ctl: 87: ulimit: 错误设置限制(不允许操作)
...等待 /usr/sbin/apache2ctl: 87: ulimit: 错误设置限制(操作不允许)
。好的

# service apache2 status

Apache2 正在运行(pid 32045)。

Muk*_*ain 17

这可能会有所帮助:- http://ubuntuforums.org/showthread.php?p=11950245#post11950245

sudo service apache2 restart # no errors
service apache2 restart      # errors
Run Code Online (Sandbox Code Playgroud)

  • +1 魔法 `sudo` 总能奏效 (2认同)

小智 6

问题源于 /usr/sbin/apache2ctl (在 Debian 上)。一探究竟:

~$ grep ULIMIT /usr/sbin/apache2ctl
ULIMIT_MAX_FILES="${APACHE_ULIMIT_MAX_FILES:-ulimit -n 8192}"
if [ "x$ULIMIT_MAX_FILES" != "x" ] ; then
    $ULIMIT_MAX_FILES
Run Code Online (Sandbox Code Playgroud)

在这里,它将允许打开的文件数设置为 8192。或者在您的情况下尝试并失败。

因此,为了避免在 apache2ctl 执行此操作时出现错误,请通过添加以下两行来调整 /etc/security/limits.conf 文件中的系统设置:

*               soft    nofile          8192
*               hard    nofile          8192
Run Code Online (Sandbox Code Playgroud)

我没有将它增加到不必要的(8192),因为我不知道它还会影响什么。然而,这摆脱了警告。

不确定在那之后是否需要重新启动系统,因为 ulimit 有一个我不熟悉的动态元素。但是,您可以轻松地进行测试,以找出您当前的 ulimit 文件数是多少:

ulimit -n
Run Code Online (Sandbox Code Playgroud)

您可能想阅读我在哪里找到它:stackoverflow - setting ulimit