ulimit modification

The ulimit -n command can be used to view the maximum open file descriptor in the Linux system. The general default value is 1024. For a busy server, this value is too small, so it is necessary to reset the open file descriptor in the Linux system. the maximum value of the character. So where should it be set?

The most correct way is to set in /etc/security/limits.conf:

[root@localhost security]# 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) 30518
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
[root@localhost security]# ulimit -n 10240
[root@localhost security]# 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) 30518
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 10240
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

1. Command usage

Command: ulimit
Function: Control the resource of the shell program
Syntax: ulimit [-aHS][-c <core file upper limit>][-d <data section size>][-f <file size>][- m <memory size>][-n <number of files>][-p <buffer size>][-s <stack size>][-t <CPU time>][-u <number of programs>][-v <virtual memory size>] 
  
    Supplementary note: ulimit is a built-in command of the shell, which can be used to control the resources of the shell execution program. 
    parameter: 

    -a  显示目前资源限制的设定。  
    
    -c <core文件上限>  设定core文件的最大值,单位为区块。  
    
    -d <数据节区大小>  程序数据节区的最大值,单位为KB。  
    
    -f <文件大小>  shell所能建立的最大文件,单位为区块。  
    
    -H  设定资源的硬性限制,也就是管理员所设下的限制。  
    
    -m <内存大小>  指定可使用内存的上限,单位为KB。  
    
    -n <文件数目>  指定同一时间最多可打开的文件数。  
    
    -p <缓冲区大小>  指定管道缓冲区的大小,单位512字节。  
    
    -s <堆栈大小>  指定堆叠的上限,单位为KB。  
    
    -S  设定资源的弹性限制。  
    
    -t <CPU时间>  指定CPU使用时间的上限,单位为秒。  
    
    -u <进程数目>  用户最多可启动的进程数目。 
  
    -v <虚拟内存大小>  指定可使用的虚拟内存上限,单位为KB。


2. System tuning

    As mentioned earlier, ulimit -a is used to display the current various user process limits. 
    Linux for each user, the system limits its maximum number of processes. In order to improve performance, you can set the maximum number of processes for each linux user according to the device resources
    . Below I set the maximum number of processes for a linux user to 10,000: 
    ulimit -u 10000 
     For many socket connections that need to be made and kept open For Java applications,
     it is best to modify the number of open files per process by using ulimit -n xx, which defaults to 1024. 
     ulimit -n 4096 Increase the number of files that each process can open to 4096, the default is 1024. 
     Other recommended settings to be unlimited (unlimited) Some important settings are: 

     data segment length: ulimit -d unlimited 
     Maximum memory size: ulimit -m unlimited 
     stack size: ulimit -s unlimited 
     CPU time: ulimit -t unlimited 
     virtual memory: ulimit -v unlimited 
  
     Temporarily, for the duration of a login shell session via the ulimit command.
     Permanently, by adding a corresponding ulimit statement to the file read by the login shell, the shell-specific user resource file, such as: 

1) Unlock the Linux system's maximum number of processes and maximum number of file open limits:
        vi /etc/security/limits.conf
        # Add the following lines
        * soft noproc 11000
        * hard noproc 11000
        * soft nofile 4100
        * hard nofile 4100 
       Description: * means for all users
            noproc means the maximum number of processes
            nofile means the maximum number of open files 
2) Let SSH accept the login of the Login program, which is convenient for viewing the ulimit -a resource limit on the ssh client:
        a. vi /etc/ssh/sshd_config 
             Change the value of UserLogin to yes, and remove the # comment
        b. Restart the sshd service:
              /etc/init.d/sshd restart
3) Modify the environment variable files for all linux users:
vi /etc/profile 
ulimit -u 10000
ulimit -n 4096
ulimit -d unlimited 
ulimit -m unlimited 
ulimit -s unlimited 
ulimit -t unlimited 
ulimit -v unlimited 

/**************************************

Sometimes in The program needs to open multiple files for analysis. The default number of the system is generally 1024, (you can see it with ulimit -a), which is enough for normal use, but too little for the program.
Modify 2 files.
1) /etc/security/limits.conf
vi /etc/security/limits.conf
plus:
* soft nofile 8192
* hard nofile 20480
2) /etc/pam.d/login
session required /lib/security/pam_limits.so
**********
Also make sure the /etc/pam.d/system-auth file has the following content
session required /lib/security/$ISA/pam_limits.so
This line ensures that the system will enforce this limit.
**********
3) General user's .bash_profile
#ulimit -n 1024
re-login ok

3.  /proc directory:
1) The /proc directory contains many parameters of the current state of the system, such as: reference
/proc/sys/fs/file-max
/proc/sys/fs/inode-max
 


It is a restriction on the entire system, not for users;
2) The values ​​in the proc directory can be dynamically set. If you want to take effect permanently, you can modify the /etc/sysctl.conf file and use the following command to confirm:

# sysctl -p


For example adding:

reference
fs.file-max=xxx
fs.inode-max=xxx

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324910674&siteId=291194637