Linux tuning scheme, modify maximum number of connections (ulimit command) "Go"

Source: Internet
Author: User
Tags posix

Transferred from: http://blog.csdn.net/liangxiaozhang/article/details/8363435

Linux for each user, the system limits its maximum number of processes. To improve performance, the maximum number of processes per Linux user can be set according to the device resource situation

You can use Ulimit-a to display the current various user process limits.
Below I set the maximum number of processes for a Linux user to 10,000:
Ulimit-u 10240
For Java applications that need to do many socket connections and leave them open,
It is best to modify the number of files that each process can open by using Ulimit-n xx, which is the default value of 1024.
Ulimit-n 4096 increase the number of files that can be opened by each process to 4096, with a default of 1024
Some of the important settings that other recommendations are set to unrestricted (unlimited) 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, applies to a shell session that is logged on through 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), the maximum number of processes to unlock Linux system and the maximum file opening limit:
Vi/etc/security/limits.conf
# Add the following line
* Soft Noproc 11000
* Hard Noproc 11000
* Soft Nofile 4100
* Hard Nofile 4100
Description: * Represents for all users, Noproc is the maximum number of processes, Nofile is the maximum number of open files
2), let SSH accept login program login, easy to view ulimit-a resource limit in 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

Run #source/etc/profile after saving to make it effective

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

Sometimes in the program need to open multiple files for analysis, the system is generally the default number is 1024, (with ULIMIT-A can see) for normal use is enough, but for the program, it is too little.
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 that 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 restriction.


/***********
3. Bash_profile for general users.
#ulimit-N 1024
Re-login OK

The role of Ulimit
=======================

Ulimit: Displays (or sets) the limits of the resources that the user can use, which are limited to soft limits (current limit) and hard limits (caps), where the hard limit is the upper limit of the soft limit, and the system resources used by the application do not exceed the corresponding soft limit in the run process. Any transcendence leads to the termination of the process.


Parameter description
Ulimited does not restrict the resources that users can use, but this setting sets the maximum number of files that can be opened (max Open file)
And the maximum number of processes that can run concurrently (max user processes) is invalid
-A lists all current resource limits
-C Sets the maximum value of the core file. Unit: Blocks
-D sets the maximum value of the data segment for a process. Unit: Kbytes
-F Shell The maximum file size of the created file, in: Blocks
-h Specifies to set the hard limit for a given resource. If the user has root user rights, the hard limit can be increased. Any user can reduce the hard limit
Maximum number of physical memory that can be locked by-l
The maximum number of resident memory that can be used by-M, in: Kbytes
-N Maximum number of files per process that can be opened at the same time
-P Sets the maximum value of the pipe in block,1block=512bytes
-s Specifies the maximum value of the stack: unit: Kbytes
-s specifies to set the soft limit for a given resource. The soft limit can be increased to the value of the hard limit. If the-H and-s flag are not specified, the limit applies to both
-t specifies the number of seconds to use per process, in units: seconds
The maximum number of concurrent processes that can be run by-u
The maximum amount of virtual memory that the-V shell can use, in units: Kbytes
-X

Example 1:

[[email protected] proc]# ulimit-a
Core file size (blocks,-c)
Data seg size (Kbytes,-D) Unlimited
File size (blocks,-f) Unlimited
Pending signals (-i) 2047
Max locked Memory (Kbytes, L),
Max memory size (kby TES,-m) unlimited
Open files (-N) 1024x768
Pipe Size (bytes,-p) 8
POSIX message queues (bytes,-q) 819200
St Ack Size (Kbytes,-s) 8192
CPU time (seconds,-T) unlimited
MAX user Processes (-u) 2047
Virtual memory (Kbytes, -V) Unlimited
File Locks (-X) unlimited
[[email protected] proc]#

Each line of the output is composed of a resource name, (units, parameters of the Ulimit command), and soft limits. Detailed Explanation:
Parameter description
The maximum value for core file size core files is blocks,
Data seg size process can be arbitrarily large
File size files can be arbitrarily large
Pending signals up to 2047 signals to be processed
Max locked memory A task with a maximum of 32kB of physical RAM locked
Max memory Size The maximum number of resident physical memory for a task
Open files a task can be opened at the same time 1024 of the file
Pipe size pipes with a maximum space of 4096 bytes
The maximum value for the POSIX message queues POSIX messages queue is 819200 bytes
Stack size process stacks have a maximum value of 8192 bytes
CPU time used by CPUs
Max User processes the maximum number of simultaneous open processes (including threads) for the current user is 2047
Virtual memory does not limit the maximum address space for a process
There is no limit to the maximum number of files that file locks can lock

Example 2: Limit the size of a file with the Ulimit command, resulting in a failed copy command

[[Email Protected]]ls temp.txt
Ls:temp.txt: No file or directory
[[Email protected]]ulimit-f 1 #设置创建文件的最大块 (piece = 512 bytes)
[[Email Protected]]cat a.c > Temp.txt
File size exceeded limit

The size of the file a.c is 5002 bytes, and the size of the created file we set is 512 bytes x1 Block = 512 bytes

Linux tuning scheme, modify maximum number of connections (ulimit command) "Go"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.