How to permanently set kernel parameters on Linux

Applies to:

Linux OS - Version Enterprise Linux 4.0 and later
Linux x86
Linux x86-64
***Checked for relevance on 23-Nov-2012***



Purpose

This article will assist you to set permanently the kernel parameters on Oracle Enterprise Linux OEL/ RedHat Advanced Server (RHEL) and on Suse SLES/United Linux

Scope

This is intended for Linux system administrators and Linux DBAs with sysadmin skills.

Details

Oracle uses UNIX resources such as shared memory, swap space, and semaphores extensively for interprocess communication. If your kernel parameter settings are insufficient for Oracle, you will experience problems during installation and/or instance startup.
Check on the Oracle� Database Installation Guide the Kernel Parameters requirement.

To temporarily 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. One 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


Oracle Enterprise Linux OEL - RedHat Linux Enterprise Server RHEL

Another way to setup permanently kernel parameter values on OEL/RHAS-RHEL  is to use '/etc/sysctl.conf' file.
Support engineers who are requested to perform system diagnoses are more likely to check this file for additions than look for undocumented customisations to startup scripts. 

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 -a command as root. This will create a large, comprehensive list.


For Enterprise Linux OEL and RHEL there is available the oracle-validated package that not only pre-configures systems e.g. kernel parameters and user limit settings, but also installs prerequisite packages required to satisfy the Oracle Universal Installer (OUI) as part of Oracle product installation.






SUSE SLES / United Linux

On SUSE SLES / United Linux another way to set kernel parameter modifications permanently is to use the '/etc/init.d/boot.local' file.

You can put in that file the commands setting the kernel parameters. At the boot time 'boot.local' is started and the these setting processed

Example:
#! /bin/sh
#
# Copyright (c) 2002 SuSE Linux AG Nuernberg, Germany. All rights reserved.
#
# Author: Werner Fink <werner@suse.de>, 1996
# Burchard Steinbild <feedback@suse.de>, 1996
#
# /etc/init.d/boot.local
#
# script with local commands to be executed from init on system startup
#
# Here you should add things, that should happen directly after booting
# before we're going to the first run level.
#
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

Again on SUSE SLES / United Linux (with orarun-XXXX.rpm) you can use '/etc/sysconfig/oracle' file to set kernel parameter modifications permanently.

Example:
SET_ORACLE_KERNEL_PARAMETERS="yes"
SHMMAX=3294967296
SHMMNI=4096
SHMALL=2097152
SEMMSL=1250
SEMMNS=32000
SEMOPM=128
SEMMNI=4096
IP_LOCAL_PORT_RANGE="1024 65000"
FILE_MAX_KERNEL=131072
FILE_MAX_SHELL=65536
PROCESSES_MAX_SHELL=16384

Note:
the orarun rpm places /etc/sysconfig/oracle file and could be over writing the parameters set by boot.sysctl on startup.

Comments

Popular posts from this blog

BMCs and the IPMI Protocol

Logical Domains Reference Manual

Understanding How ZFS Calculates Used Space