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

 
 
 

 

 



 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM