Basic Centos performance tuning policy settings

Source: Internet
Author: User
Ulimitulimit-a is used to display various current user process restrictions. Linux limits the maximum number of processes for each user. To improve performance, you can set the maximum number of processes for each linux user based on the device resources. below I will set the maximum number of processes for a linux user to 10000: ulimit-u10000 is better for Java applications that require many socket connections and make them open by using

About ulimit

Ulimit-a is used to display various current user process restrictions.
Linux limits the maximum number of processes for each user. To improve performance, you can set the maximum number of processes for each linux user based on the device resources. below I will set the maximum number of processes for a linux user to 10000:
Ulimit-u 10000
For Java applications that require a lot of socket connections and make them open, it is best to use ulimit-n xx to modify the number of files that can be opened by each process. The default value is 1024.
Ulimit-n 4096 increases the number of files that each process can open to 4096. the default value is 1024.
Other important settings recommended for 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, it is applicable when logging on to a shell session through the ulimit command.
Permanently, add a corresponding ulimit statement to the file read by the logon shell, that is, the shell-specific user resource file, such:

1) remove the maximum number of processes and maximum number of files opened in Linux:
Vi/etc/security/limits. conf
# Add the following rows
* Soft noproc 11000
* Hard noproc 11000
* Soft nofile 4100
* Hard nofile 4100

Note: * represents all users
Noproc indicates the maximum number of processes.
Nofile indicates the maximum number of opened files.


2) enable SSH to accept Login program Login, so that you can view the ulimit-a resource restrictions on the ssh client:
A, vi/etc/ssh/sshd_config
Change the UserLogin value to yes and remove the # comment.
B. restart the sshd service:
/Etc/init. d/sshd restart
3) modify the environment variable files of 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 you need to open multiple files in the program for analysis. the default number of files in the system is 1024 (as you can see from ulimit-a). This is enough for normal use, but for the program, that's too little.

Modify two files.
1./etc/security/limits. conf
Vi/etc/security/limits. conf
Add:
* Soft nofile 8192
* Hard nofile 20480
2./etc/pam. d/login
Session required/lib/security/pam_limits.so
**********
Make sure that the/etc/pam. d/system-auth file contains the following content:
Session required/lib/security/$ ISA/pam_limits.so
This line ensures that the system executes this restriction.
***********
3. the. bash_profile of a general user
# Ulimit-n 1024
Log on again. OK.
-------------
For solaris

In fact, there is such a command ulimit in the system, the following is the result of ulimit-a execution:

Time (seconds) unlimited
File (blocks) unlimited
Data (kbytes) unlimited
Stack (kbytes) 8192
Coredump (blocks) unlimited
Nofiles (descriptors) 1024
Memory (kbytes) unlimited
Nofiles is the variable value of the file descriptor. this value is affected by the rlim_fd_cur parameter and can be modified using the ulimit-n number command. However, no matter how it is modified, the program still cannot exceed the limit of fd = 256. The following information can be found in the Solaris Tunable Parameters Reference Manua book:

A 32-bit program using standard I/O is limited to 256 file descriptors.
A 64-bit program using standard I/O can use up to 2 billion descriptors.
This means that 32-bit programs cannot break through this restriction. only 64-bit programs can use up to 0.2 billion file descriptors, SUN's software and hardware have implemented a 64-bit architecture a long time ago. now the only solution is to compile the program into a 64-bit program. in order to generate a 64-bit program, A 64-bit compiler is required. if you go to www.sunfreeware.com to download the 64-bit compiler gcc, the website does not specifically indicate that it is a 64-bit gcc, however, there will be an unexpected result, that is, the description of the software indicates that as long as the-m64 option is added during gcc compilation, the 64-bit program can be generated.

Therefore, after a 64-bit program is compiled using gcc-m64 and set the number of fd to a large value using ulimit-n 102400, all problems can be solved, there is no insufficient file descriptor.

Set the formats of rlimi_fc_max and rlim_fd_cur in the/etc/system file as follows:

* Set hard limit on file descriptors
Set rlim_fd_max = 4096
* Set soft limit on file descriptors
Set rlim_fd_cur = 1024
The ulimit command format is as follows:

Usage: ulimit [-HSacdfnstv] [limit]
Ulimit-a is used to display the setting values of each parameter, and ulimit-n is used to set the maximum value of fd.
**************************************** *********

Modify file descriptor limits

Solaris has two file descriptors that can be opened by the control process: rlim_fd_max and rlim_fd_cur. The former is a hard setting, and the modification requires permissions. The latter is a soft setting. you can modify it by using limit or setrlimit (). The maximum value of this parameter cannot exceed the former. Generally, we modify these two parameters in/etc/system.

Set rlim_fd_max = 65535

Set rlim_fd_cur = 65535

======================================

Ulimit is used for the resources occupied by shell startup processes.

You can use this command to view the resource usage of a process.

Usage: ulimit [-acdfHlmnpsStvw] [size]

-H: Set hardware resource limits.
-S: Set software resource limits.
-A: displays all current resource limits.
-C size: sets the maximum value of the core file. unit: blocks
-D size: sets the maximum value of the data segment. unit: kbytes
-F size: sets the maximum value of the file to be created. unit: blocks
-L size: sets the maximum value of the locked process in the memory. unit: kbytes
-M size: sets the maximum value of resident memory that can be used. unit: kbytes
-N size: sets the maximum value of the file descriptor that the kernel can open at the same time. unit: n
-P size: sets the maximum value of the MPs queue buffer. unit: kbytes
-S size: sets the maximum value of the stack. unit: kbytes
-T size: sets the maximum CPU usage time. unit: seconds
-V size: sets the maximum value of virtual memory. unit: kbytes 5
1] In the RH8 environment file/etc/profile, we can see how the system configures ulimit:

# Grep ulimit/etc/profile
Ulimit-S-c 0>/dev/null 2> & 1 (output redirection, normal output and abnormal output are ignored)

This statement sets the software resources and core file size.
2] if we want to limit the file size created by shell, for example:

# Ll h
-Rw-r -- 1 lee 150062 July 22 02:39 h
# Ulimit-f 100 # set the maximum size of the file to be created (one block = 512 bytes)
# Cat h> newh
File size limit exceeded
# Ll newh
-Rw-r -- 1 lee 51200 November 8 11:47 newh
The file h size is 150062 bytes, and the size of the file we set to create is 512 bytes X 51200 bytes = bytes
Of course, the system will generate a 51200-byte newh file based on your settings.
3] put the ulimit you want to set in the environment file/etc/profile, just like instance 1.
If you set the parameters for all users, you can set the parameters in/etc/security/limits. conf.

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.