Pages

Friday 16 September 2011

Redhat Linux : Setting Kernel Parameter


Redhat Linux : Setting Kernel Parameter


To modify kernel parameters a common way is to change /proc file system:
1. Log in as root user.
2. Change to the /proc/sys/kernel directory.
3. echo <desired list of values> > <group of parameters>

But this update is not permanent and after system reboot, your kernel parameters’s values will be the same as before. A way to set kernel parameter modifications permanently, on Linux, is to include them in a shell script. This could be run as root user, or in an automatic way at startup process
- Create file /etc/init.d/set_kernel_parameters


#!/bin/sh
#
#
echo -n quot;Start Setting kernel parameters on "
echo 250 32000 100 128 > /proc/sys/kernel/sem #This sets SEMMSL, SEMMNS, SEMOPM, SEMMNI
echo 2097152 > /proc/sys/kernel/shmall
echo 2147483648 > /proc/sys/kernel/shmmax
echo 4096 > /proc/sys/kernel/shmmni
#
echo 65536 > /proc/sys/fs/file-max
#
echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range
#
echo 4194304 > /proc/sys/net/core/rmem_default
echo 4194304 > /proc/sys/net/core/rmem_max
echo 262144 > /proc/sys/net/core/wmem_default
echo 262144 > /proc/sys/net/core/wmem_max
#
ulimit -n 65536 >/dev/null 2>&1
ulimit -u 16384 >/dev/null 2>&1
#
echo -n quot;End Setting kernel parameters on "
echo

- grant execute rights on this file
$ chmod 755 /etc/init.d/set_kernel_parameters

- create symbolic link to run at startup
$ ln -s /etc/init.d/set_kernel_parameters /etc/rc.d/rc5.d/S55kernel
$ ln -s /etc/init.d/set_kernel_parameters /etc/rc.d/rc3.d/S55kernel


- make the kernel parameters active by running as root
$ /etc/init.d/set_kernel_parameters









Second Procedure to modify kernel parameters a common way is to change /proc file system:
1. Log in as root user.
2. Change to the /proc/sys/kernel directory.
3. echo <desired list of values> > <group of parameters>

But this update is not permanent and after system reboot, your kernel parameters’s values will be the same as before. A way to set kernel parameter modifications permanently, on Linux, is to include them in a shell script. This could be run as root user, or in an automatic way at startup process

- Create file /etc/init.d/set_kernel_parameters
#!/bin/sh
#
#
echo -n quot;Start Setting kernel parameters on "
echo 250 32000 100 128 > /proc/sys/kernel/sem #This sets SEMMSL, SEMMNS, SEMOPM, SEMMNI
echo 2097152 > /proc/sys/kernel/shmall
echo 2147483648 > /proc/sys/kernel/shmmax
echo 4096 > /proc/sys/kernel/shmmni
#
echo 65536 > /proc/sys/fs/file-max
#
echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range
#
echo 4194304 > /proc/sys/net/core/rmem_default
echo 4194304 > /proc/sys/net/core/rmem_max
echo 262144 > /proc/sys/net/core/wmem_default
echo 262144 > /proc/sys/net/core/wmem_max
#
ulimit -n 65536 >/dev/null 2>&1
ulimit -u 16384 >/dev/null 2>&1
#
echo -n quot;End Setting kernel parameters on "
echo

- grant execute rights on this file
$ chmod 755 /etc/init.d/set_kernel_parameters

- create symbolic link to run at startup
$ ln -s /etc/init.d/set_kernel_parameters /etc/rc.d/rc5.d/S55kernel
$ ln -s /etc/init.d/set_kernel_parameters /etc/rc.d/rc3.d/S55kernel


- make the kernel parameters active by running as root
$ /etc/init.d/set_kernel_parameters



Every time the system boots, the ‘/etc/rc.d/rc.sysinit‘ script is executed by init process. This shell script contains a call to sysctl command and reads the values from /etc/sysctl.conf file as the ones to be set . Therefore, any values added to /etc/sysctl.confwill take effect after the system boot or without downtime using “sysctl -p” command



sysctl.conf is a simple file containing sysctl values to be read in and set by sysctl (see man 8 sysctl).

The syntax is simply as follows:
# comment
; comment



token = value

Note that blank lines are ignored, and whitespace before and after a token or value is ignored, although a value can contain whitespace within. Lines which begin with a # or ; are considered remarks / comments and ignored.

Example:
# sysctl.conf sample
#
kernel.sysrq = 1
kernel.sem = 250 32000 100 128 #This sets SEMMSL, SEMMNS, SEMOPM, SEMMNI
kernel.shmmax = 2147483648
kernel.shmall = 2097152
kernel.shmmni = 4096
;
fs.file-max = 65536
;
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.ip_local_port_range = 1024 65000
;
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 262144


The sysctl command is used to view, set, and automated kernel settings in the /proc/sys/ directory. To get a quick overview of all settings configurable in the /proc/sys/ directory, type the sysctl -acommand as root

No comments:

Post a Comment

Twitter Bird Gadget