如何增加Debian 7上的碳缓存文件限制?

如何增加Debian 7上的碳缓存文件限制?,debian,file-descriptor,graphite,ulimit,Debian,File Descriptor,Graphite,Ulimit,我正在Debian7服务器上运行Graphite 0.9.12 最近我在carbon cache的日志中发现错误,说“打开的文件太多”。根据carbon cache的网站,我需要增加carbon cache的nofile限制 因此,我增加了系统范围和每个进程的限制: cat /proc/sys/fs/file-max 5000000 在/etc/security/limits.conf中 * hard nofile 1000000 * soft nofile 1000000 root soft

我正在Debian7服务器上运行Graphite 0.9.12

最近我在carbon cache的日志中发现错误,说“打开的文件太多”。根据carbon cache的网站,我需要增加carbon cache的nofile限制

因此,我增加了系统范围和每个进程的限制:

cat /proc/sys/fs/file-max
5000000
在/etc/security/limits.conf中

* hard nofile 1000000
* soft nofile 1000000
root soft nofile 1000000
root hard nofile 1000000
www-data soft nofile 1000000
www-data hard nofile 1000000
使用ulimit命令,我可以确认root/me/www数据的文件限制已增加

我多次重启碳缓存。但是,碳缓存的每个进程文件限制没有增加,仍然是1024:4096

Max open files            1024                 4096                 files
我正在使用/etc/init.d/carbon-cache启动脚本重新启动carbon-cache,
sudo服务carbon-cache restart
(或先停止,然后启动)

剧本是:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          carbon-cache
# Required-Start:
# Required-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: initscript for runit-managed carbon-cache service
### END INIT INFO

# Author: Opscode, Inc. <cookbooks@opscode.com>

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="runit-managed carbon-cache"
NAME=carbon-cache
RUNIT=/usr/bin/sv
SCRIPTNAME=/etc/init.d/$NAME

# Exit if runit is not installed
[ -x $RUNIT ] || exit 0

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions


case "$1" in
  start)
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
        $RUNIT start $NAME
        [ "$VERBOSE" != no ] && log_end_msg $?
        ;;
  stop)
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
        $RUNIT stop $NAME
        [ "$VERBOSE" != no ] && log_end_msg $?
        ;;
  status)
        $RUNIT status $NAME && exit 0 || exit $?
        ;;
  reload)
        [ "$VERBOSE" != no ] && log_daemon_msg "Reloading $DESC" "$NAME"
        $RUNIT reload $NAME
        [ "$VERBOSE" != no ] && log_end_msg $?
        ;;
  force-reload) ................ SO ON
我将文件编辑为:

#!/bin/sh
ulimit -n 999999
exec 2>&1
exec chpst -o 999999 -u www-data -l /opt/graphite/storage/carbon-cache.lock -- /opt/graphite/bin/carbon-cache.py --pid /opt/graphite/storage/carbon-cache-a.pid --debug start
现在在/proc/pid/limits中,软限制和硬限制都是999999

使用ulimit命令,您可以更改 当前shell环境,以及以root用户身份运行时的硬限制

init.d中的脚本以新的shell env(会话)开始,必须再次应用ulimit。您可以在
case
语句之前向
/etc/init.d/carbon cache
添加如下内容:

ulimit -n 999999
这将为当前(
init.d start
)会话设置每次启动/重新启动/重新加载/任何操作的新限制。限制从父进程继承到子进程,因此碳缓存也会受到影响

编辑

  • 使用
    ulimit-H设置硬限制

  • 是主管吗?如果是这样,请在
    [supervisord]
    部分中添加
    /etc/supervisor/supervisordconf

  • minfds=10000
    

    我在启动脚本时添加了ulimit-n1000。但是,当我检查新pid的限制时,(/proc/pid/limits)仍然显示为1024/4096,而不是10000。想法呢?试着用
    ulimit-h10000
    增加硬限制使用ulimit-H也没有帮助。然而,当我查看其他一些可能相关的文件时,我发现了这个“/etc/sv/carbon cache/run”。在“run”文件中,它显示“exec chpst-u www-data-l/opt/graphite/storage/carbon-cache.lock--/opt/graphite/bin/carbon-cache.py--pid/opt/graphite/storage/carbon-cache-a.pid--debug start”,因此我搜索了命令chpst,找到了一个-o选项来设置文件限制。我在“运行”文件中添加了-o99999,并重新启动了碳缓存。现在软限制和硬限制都是4096。似乎-o选项提高了软限制,但没有提高硬限制。有什么办法解决这个问题吗?你写道你编辑了/etc/security/limits.conf。您重新启动了系统吗?并且
    chpst
    只能在硬限制内更改进程(而不是会话)配置/状态。用它来改变硬限制是不可能的。
    ulimit -n 999999