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 $"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 $"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 $"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 $"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.conf will 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

Ramdev

Ramdev

I have started unixadminschool.com ( aka gurkulindia.com) in 2009 as my own personal reference blog, and later sometime i have realized that my leanings might be helpful for other unixadmins if I manage my knowledge-base in more user friendly format. And the result is today's' unixadminschool.com. You can connect me at - https://www.linkedin.com/in/unixadminschool/

2 Responses

  1. Ajay Malhotra says:

    Hi Team,

    I need to join your professional network to learn Unix, Linux and to receive job updates

What is in your mind, about this post ? Leave a Reply

Close
  Our next learning article is ready, subscribe it in your email

What is your Learning Goal for Next Six Months ? Talk to us