the max number of open files 最大打开文件数 ulimit -n RabbitMQ调优

Installing on RPM-based Linux (RHEL, CentOS, Fedora, openSUSE) — RabbitMQ https://www.rabbitmq.com/install-rpm.html

ulimit -n

1024

Controlling System Limits on Linux

RabbitMQ installations running production workloads may need system limits and kernel parameters tuning in order to handle a decent number of concurrent connections and queues. The main setting that needs adjustment is the max number of open files, also known as ulimit -n. The default value on many operating systems is too low for a messaging broker (eg. 1024 on several Linux distributions). We recommend allowing for at least 65536 file descriptors for userrabbitmq in production environments. 4096 should be sufficient for most development workloads.

There are two limits in play: the maximum number of open files the OS kernel allows (fs.file-max) and the per-user limit (ulimit -n). The former must be higher than the latter.

With systemd (Recent Linux Distributions)

On distributions that use systemd, the OS limits are controlled via a configuration file at /etc/systemd/system/rabbitmq-server.service.d/limits.conf, for example:

[Service]
LimitNOFILE=300000

Without systemd (Older Linux Distributions)

The most straightforward way to adjust the per-user limit for RabbitMQ on distributions that do not use systemd is to edit the rabbitmq-env.conf to invoke ulimit before the service is started.

ulimit -S -n 4096

This soft limit cannot go higher than the hard limit (which defaults to 4096 in many distributions). The hard limit can be increased via /etc/security/limits.conf. This also requires enabling the pam_limits.so module and re-login or reboot.

Note that limits cannot be changed for running OS processes.

For more information about controlling fs.file-max with sysctl, please refer to the excellentRiak guide on open file limit tuning.

Verifying the Limit

RabbitMQ management UI displays the number of file descriptors available for it to use on the Overview tab.

rabbitmqctl status
includes the same value.

The following command

cat /proc/$RABBITMQ_BEAM_PROCESS_PID/limits
can be used to display effective limits of a running process. $RABBITMQ_BEAM_PROCESS_PID is the OS PID of the Erlang VM running RabbitMQ, as returned by rabbitmqctl status.

Configuration Management Tools

Configuration management tools (e.g. Chef, Puppet, BOSH) provide assistance with system limit tuning. Our developer tools guide lists relevant modules and projects.

Managing the Broker

To stop the server or check its status, etc., you can use package-specific scripts (e.g. the service tool) or invoke rabbitmqctl (as an administrator). It should be available on the path. All rabbitmqctl commands will report the node absence if no broker is running.

  • Invoke rabbitmqctl stop to stop the server.
  • Invoke rabbitmqctl status to check whether it is running.

More info on rabbitmqctl.

 nginx worker_connections are not enough(错误) - CSDN博客 https://blog.csdn.net/m0_37263637/article/details/80813881

我们可以使用ulimit -a命令查看Linux相关限制 
可以看到open files (-n) 1024 
即linux 默认最大打开文件数为1024 
对于临时测试我们可以使用ulimit -n Number 修改最大文件句柄限制,但该种修改方式仅仅对当前session有效。

永久生效方案

 vi /etc/security/limits.conf
在limits.conf中添加以下参数
* soft   nofile   40960
* hard nofile 65536
  • 1
  • 2
  • 3
  • 4

参数:

* 代表所有用户有效
soft:软限制,超过会报warn
hard:实际限制
nofile:文件句柄参数
number:最大文件句柄数



阿里云服务器默认配置


[root@c ~]# cat /etc/security/limits.conf
# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.
#It does not affect resource limits of the system services.
#
#Also note that configuration files in /etc/security/limits.d directory,
#which are read in alphabetical order, override the settings in this
#file in case the domain is the same or more specific.
#That means for example that setting a limit for wildcard domain here
#can be overriden with a wildcard setting in a config file in the
#subdirectory, but a user specific setting here can be overriden only
#with a user specific setting in the subdirectory.
#
#Each line describes a limit for a user in the form:
#
#<domain> <type> <item> <value>
#
#Where:
#<domain> can be:
# - a user name
# - a group name, with @group syntax
# - the wildcard *, for default entry
# - the wildcard %, can be also used with %group syntax,
# for maxlogin limit
#
#<type> can have the two values:
# - "soft" for enforcing the soft limits
# - "hard" for enforcing hard limits
#
#<item> can be one of the following:
# - core - limits the core file size (KB)
# - data - max data size (KB)
# - fsize - maximum filesize (KB)
# - memlock - max locked-in-memory address space (KB)
# - nofile - max number of open files
# - rss - max resident set size (KB)
# - stack - max stack size (KB)
# - cpu - max CPU time (MIN)
# - nproc - max number of processes
# - as - address space limit (KB)
# - maxlogins - max number of logins for this user
# - maxsyslogins - max number of logins on the system
# - priority - the priority to run user process with
# - locks - max number of file locks the user can hold
# - sigpending - max number of pending signals
# - msgqueue - max memory used by POSIX message queues (bytes)
# - nice - max nice priority allowed to raise to values: [-20, 19]
# - rtprio - max realtime priority
#
#<domain> <type> <item> <value>
#

#* soft core 0
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#@student - maxlogins 4

# End of file
* soft nofile 65535
* hard nofile 65535
[root@c ~]# cat /proc/version
Linux version 3.10.0-862.11.6.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) ) #1 SMP Tue Aug 14 21:49:04 UTC 2018
[root@c ~]#

 Linux上修改open files数目_Linux教程_Linux公社-Linux系统门户网站 https://www.linuxidc.com/Linux/2013-07/86954.htm

Linux上修改open files数目

[日期:2013-07-06] 来源:Linux社区  作者:Linux [字体:  ]
 

Linux系统上默认的open files数目为1024, 有时应用程序会报Too many open files的错误,是因为open files 数目不够。

用 ulimit -a 命令可以查看 系统对各种参数的限制;
 
# ulimit -a
core file size          (blocks, -c) 0
data seg size          (kbytes, -d) unlimited
scheduling priority            (-e) 0
file size              (blocks, -f) unlimited
pending signals                (-i) 257648
max locked memory      (kbytes, -l) 64
max memory size        (kbytes, -m) unlimited
open files                      (-n) 4096
pipe size            (512 bytes, -p) 8
POSIX message queues    (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) unlimited
cpu time              (seconds, -t) unlimited
max user processes              (-u) unlimited
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
由上面可以知道 open files 当前限制为 4096,ok,我们可以修改稍微大一点;
当你把open files的值增大到一定程度,你的Too many open files就不会再出现了。
 
修改方法:
(1)ulimit -HSn 102400
这只是在当前终端有效,退出之后,open files 又变为默认值。
(2)将ulimit -HSn 102400写到/etc/profile中,因为每次登录终端时,都会自动执行/etc/profile。
(3)令修改open files的数值永久生效,则必须修改配置文件:/etc/security/limits.conf. 在这个文件后加上:
* soft nofile 102400
* hard nofile 102400
这种方法需要重启机器才能生效。
(4)为了让一个程序的open files数目扩大,可以在启动脚本前面加上(1)中的命令。当程序是一个daemon时,可能这种方法无效,没有终端了。 
 
影响open files数值的还有一个内核参数file-max,这是Linuxt系统的总限制。可以通过如下文式查看:
cat /proc/sys/fs/file-max
或者
sysctl -a | grep fs.file-max
 
对于服务器可以采用如下方法修改file-max:
(1)重启机器后恢复为默认值
echo 34166 > /proc/sys/fs/file-max
或者
sysctl -w "fs.file-max=34166"
(2)修改配置文件/etc/sysctl.conf, 在最后加上一行:
fs.file-max = 34166
然后sysctl -p 生效 或者 重启机器以后永久生效。

推荐阅读:

Linux系统文件查找命令find的基本使用及其高级用法 http://www.linuxidc.com/Linux/2013-05/84991.htm

 
 
 


原文地址:https://www.cnblogs.com/rsapaper/p/9628392.html