Linux how to set kernel parameters

Source: Internet
Author: User
Tags message queue semaphore

Linux ways to set kernel parameters

1 How to view kernel parameters

Use the "sysctl-a" command to view all kernel parameters that are in use. Kernel parameters are more (generally up to 500 items), according to the prefix is divided into the following major categories: Net.ipv4, Net.ipv6, Net.core, VMS, FS, Dev.parport, Dev.cdrom, Dev.raid, kernel and so on. The same Linux, the installed components and the use of different ways, the kernel parameters are used is not the same.

The documentation for all kernel parameters is placed in/usr/src/linux/documentation/sysctl, and if you want to know the description of the kernel parameters, you can view the corresponding documentation in that directory.

2 How to set the kernel parameters

Because Linux kernel parameter information is in memory, it can be directly modified by the command, and the modification will take effect directly. It can also be set by file. The two methods of modification are described below.

2.1 How the command is set

Can be implemented in two ways.

1, using "sysctl-w parameter name = value" Way

Suppose we change the value of Net.ipv4.ip_forward to 1, using the command "Sysctl-w net.ipv4.ip_forward=1".

2, modify the kernel parameters corresponding to the proc file

The kernel parameter is located under/proc/sys/, and the parameter name is the path where the file resides, and the "/" to "." To replace. For example, the/proc/sys/net/ip_forward parameter name is Net.ipv4.ip_forward.

Also change the value of Net.ipv4.ip_forward to 1, using the command "echo" 1 ">/proc/sys/net/ipv4/ip_forward".

Note that the proc file here is not the same as the normal file. Typically a file becomes a text file after it is written with Echo, but Echo modifies the proc file to be an empty file.

2.2 How files are set

The changed kernel parameters are saved by default in the/etc/sysctl.conf file. Modify the time can be directly with the VI edit sysctl.conf file, add the kernel parameters to modify the content, the format is: parameter name = value. For example, to change the value of Net.ipv4.ip_forward to 1, add the following line to the sysctl.conf:

Net.ipv4.ip_forward=1

Once the file has been modified, save it. Then use "Sysctl-p profile name" to make the configuration effective, if the profile is the default, you can not lose the configuration file name, that is, use "sysctl-p".

The kernel parameters that are modified by the file settings are invalidated after the system restarts (I previously thought the modified kernel parameters are placed in the file, the system will read the file when it is started, and the settings should not expire after the reboot.) However, it is generally invalid if it is verified, but if the default Boot.sysctl service is turned on, the setting of this file will be executed when the system starts. The command that modifies our parameters is written to the/etc/rc.local in the Startup execution script file, so that the configuration is not invalidated after the system restarts.

The advantage of file mode is that the value of the kernel parameter setting can be preserved with the file, and calling "Sysctl-p" can make all the configured values in the file take effect immediately.

3 actual application of kernel parameter settings 3.1 file and network class parameters

The kernel parameters of the file classes we generally need to focus on are Fs.file-max and FILE-NR. Fs.file-max is the maximum number of file handles that a system can request; File-nr is read-only and is related to File-max and is used only to show the number of allocated file handles, the number of file handles used, and the maximum number of file handles, as shown in.

Suse11lwb:/home/zxin10/steven # Sysctl-a|grep Fs.file-nr

Fs.file-nr = 5152 0 6815744

For a file handle problem, for the interface to handle a lot of files note that the system's file handle is sufficient. There was a problem with file handles in the previous SMS Network project, the site is the Solaris system, and the home test is on HP-UX, because the Solaris default support for file handles is much less than HP-UX (as shown), home tests are not found, resulting in a failure to leak to the scene.

Operating system name

Default system handle number

Solaris

256

Aix

2000

Suse Linux

1024

HP-UX

2000

Nt

10000

Here's how to modify file handle restrictions.

1. Set the kernel parameters according to the maximum number of open files, and verify that the maximum number of open files has been set correctly by checking the/proc/sys/fs/file-max file.

# Cat/proc/sys/fs/file-max

If the setting value is too small, modify the file/etc/sysctl.conf variable to the appropriate value.

2, set the maximum number of open files in the/etc/security/limits.conf file, the following is a line of hints:

# Add the following line.

*-Nofile 2048

This line sets the default number of open files per user to 2048. Note There are two possible restrictions on the "Nofile" item. Is the hard and soft under the term. These two restrictions must be set for the maximum number of open files that have been modified to take effect. If you use the "-" character setting, the hard and soft settings will be set at the same time. The hard limit indicates the maximum value that can be set in the soft limit. The soft limit refers to the setting value that the current system is in effect. Hard limit values can be reduced by ordinary users. But cannot be increased. The soft limit cannot be set higher than the hard limit. Only the root user can increase the hard limit value.

3. Use "Ulimit-n 2048" to limit the maximum number of files opened by users to 2048. Ulimit-n is limited to non-root users, and there is no limit to the root user to enjoy the benefits of the number of files that the system can open simultaneously.

When the number of handles is set, the default value is restored after the system restarts. If you want to save it permanently, you can modify the. bash_profile file to add the above command to the last.

3.2 Platform Kernel parameters

During the installation process, the platform invokes a dedicated shell that is responsible for setting the kernel parameters of the system. This shell is checkkernel and can be found in the/home/zxin10/bin directory on the platform. For Linux, the Check_linux_kernel function is one of the things to be concerned about. The following is the main code to set the kernel parameters, except for some platform-related kernel parameters, in addition to the Oracle database has been set up, you can analyze together.

##### settings for Message Queuing

if! Grep-q "/proc/sys/kernel/shmmax"/etc/rc.d/rc.local

Then

echo "echo $ShmMaxSizecfg >/proc/sys/kernel/shmmax" >>/etc/rc.d/rc.local

Fi

if! Grep-q "/proc/sys/kernel/msgmni"/etc/rc.d/rc.local

Then

echo "Echo >/proc/sys/kernel/msgmni" >>/etc/rc.d/rc.local

Fi

if! Grep-q "/PROC/SYS/KERNEL/MSGMNB"/etc/rc.d/rc.local

Then

echo "echo 163840 >/proc/sys/kernel/msgmnb" >>/etc/rc.d/rc.local

Fi

if! Grep-q "/proc/sys/kernel/msgmax"/etc/rc.d/rc.local

Then

echo "echo 56383 >/proc/sys/kernel/msgmax" >>/etc/rc.d/rc.local

Fi

########## settings for some kernel parameters for Oralce

# # 2007.01.10 Add for oracle10g

If ["$db _version" = "oracle10g"]

Then

if! Grep-q "/proc/sys/net/core/rmem_max"/etc/rc.d/rc.local

Then

echo "echo \" 32000 128\ ">/proc/sys/kernel/sem" >>/etc/rc.d/rc.local

echo "echo" 1024x768 65000\ ">/proc/sys/net/ipv4/ip_local_port_range" >>/etc/rc.d/rc.local

echo "Echo 1048576 >/proc/sys/net/core/rmem_max" >>/etc/rc.d/rc.local

echo "Echo 1048576 >/proc/sys/net/core/rmem_default" >>/etc/rc.d/rc.local

echo "Echo 262144 >/proc/sys/net/core/wmem_max" >>/etc/rc.d/rc.local

echo "Echo 262144 >/proc/sys/net/core/wmem_default" >>/etc/rc.d/rc.local

Fi

Fi

The following is an online section of the Redhat Linux as 4.7 silent installation of Oracle 10g, which involves the kernel parameter setting, which is roughly the same as the content of the platform settings above.

Check kernel parameters

Checking semmsl=250;        SEMMSL=250 has been found. Pass

Checking semmns=32000;    semmns=32000 has been found. Pass

Checking semopm=100;        SEMOPM=100 has been found. Pass

Checking semmni=128;        SEMMNI=128 has been found. Pass

Checking shmmax=536870912;   shmmax=2147483648 has been found. Pass

Checking shmmni=4096;      shmmni=4096 has been found. Pass

Checking shmall=2097152;        SHMALL=2097152 has been found. Pass

Checking file-max=65536;        file-max=65536 has been found. Pass

Checking version=2.6.9;    Version=2.6.9-78.el has been found. Pass

Checking ip_local_port_range=1024-65000;    ip_local_port_range=1024-65000 has been found. Pass

Checking rmem_default=262144;     rmem_default=1048576 has been found. Pass

Checking rmem_max=262144;     rmem_max=1048576 has been found. Pass

Checking wmem_default=262144;      WMEM_DEFAULT=262144 has been found. Pass

Checking wmem_max=262144;      WMEM_MAX=262144 has been found. Pass

Check complete. The overall result of this check is: through

The following is a description of the kernel parameters involved.

Shmmax: The maximum number of bytes in a shared memory segment, it is recommended to set large points, or even larger than the number of bytes in physical memory. This parameter defines the maximum size, in bytes, of a shared memory segment. The default is 32M, which is too low for Oracle, usually set to 2G.

Shmmin: The minimum size of the shared memory segment. The settings for this parameter are generally not problematic.

Shmmni: The maximum number of shared memory segments. This kernel parameter is used to set the maximum number of shared memory segments within a system range. The default value for this parameter is 4096. It is not usually necessary to change.

SHMSEG: The maximum number of shared memory segments that can be allocated per process

Shmall: The maximum number of concurrent shared memory segments, larger than the SGA. This parameter represents the total amount of shared memory that the system can use at one time (in pages, a page size of 4KB). The default value is 2097152, which is usually not required for modification.

SEM: is an abbreviation for semaphores, which represents the semaphore set. It consists of four values: SEMMSL, Semmns, SEMOPM, Semmni.

suse11lwb:~ # Sysctl-a|grep SEM

Kernel.sem = 250 32000 100 128

Semmns: The maximum number of semaphores associated with Oracle's process count. SEMMSL * Semmni

SEMOPM: Maximum number of semaphores allowed for system calls. At least 100; or equal to SEMMSL.

Semmni: The maximum number of system semaphore set. Minimum 128

SEMMSL: The maximum number of semaphores in each semaphore set. Minimum 250, the system recommended for processes parameter setting is set to processes+10.

Msgmni: Specifies the maximum number of message queue identities. Default setting: 16

Msgmax: The maximum length of messages sent from one process to another. Inter-process messaging is done in the kernel's memory and is not swapped to disk, so increasing the value increases the amount of memory used by the operating system. Default setting: 8192

MSGMNB: The maximum number of bytes in a message queue. Default setting: 16384

Optmem_max: Maximum cache size per socket

Rmem_default: Default cache Size (bytes) for receiving sockets

Rmem_max: Maximum cache Size (bytes) for receive sockets

Wmem_default: Socket default cache Size sent (bytes)

Wmem_max: Socket Maximum cache size sent (bytes)

P_local_port_range: Represents the range of ports used for an outward connection. Small by default: 32768 to 61000, 10000 to 65000. (Note: Do not set the minimum value too low, otherwise it may take off the normal port!)

File-max: Represents the maximum number of file handles. The file handle setting indicates the number of files that can be opened on a Linux system. If the settings are too small, Oracle will not start or run abnormally.

Linux how to set kernel parameters

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.