Web Portal Linux Kernel Configuration

Sample InfraTrack Web portal Kernel configuration script for Linux kernels 3.0 and newer

This script is provided only as a sample and should be tested before production implementation!

#!/bin/sh

# are we running as root
CU=`whoami`

if [ "$CU" != "root" ]; then
    echo "This script must be executed as root"
    exit
fi

PAGE_SIZE=`getconf PAGESIZE`
RAM_SIZE_RAW=`cat /proc/meminfo | grep MemTotal | awk '{printf "%20.0f", $2*1024}'`
RAM_SIZE=`echo ${RAM_SIZE_RAW} | bc`
SHMALL=$(($RAM_SIZE/$PAGE_SIZE))
SHMALL1=`echo $SHMALL | bc`
SHMMAX=$(($RAM_SIZE/2))
SHMMAX1=`echo $SHMMAX | bc`

echo "###########################" > infratrack_sysctl.conf
echo "###   Kernel settings   ###" >> infratrack_sysctl.conf
echo "###########################" >> infratrack_sysctl.conf
echo "kernel.shmall=${SHMALL1}" >> infratrack_sysctl.conf
echo "kernel.shmmax=${SHMMAX1}" >> infratrack_sysctl.conf
echo "kernel.shmmni=4096" >> infratrack_sysctl.conf
echo "kernel.msgmnb=65536" >> infratrack_sysctl.conf
echo "kernel.msgmax=65536" >> infratrack_sysctl.conf
echo "kernel.sysrq=0" >> infratrack_sysctl.conf
echo "kernel.sem=250 32000 100 128" >> infratrack_sysctl.conf
echo "kernel.core_uses_pid=1" >> infratrack_sysctl.conf
echo "###########################" >> infratrack_sysctl.conf
echo "###     File System     ###" >> infratrack_sysctl.conf
echo "###########################" >> infratrack_sysctl.conf
echo "fs.file-max=65536" >> infratrack_sysctl.conf
echo "fs.aio-max-nr=1048576" >> infratrack_sysctl.conf
echo "###########################" >> infratrack_sysctl.conf
echo "###        IPV4         ###" >> infratrack_sysctl.conf
echo "###########################" >> infratrack_sysctl.conf
echo "net.ipv4.tcp_max_syn_backlog=4096" >> infratrack_sysctl.conf
echo "net.ipv4.tcp_syncookies=1" >> infratrack_sysctl.conf
echo "net.ipv4.conf.all.rp_filter=1" >> infratrack_sysctl.conf
echo "net.ipv4.conf.default.rp_filter=1" >> infratrack_sysctl.conf
echo "net.ipv4.conf.all.accept_source_route=0" >> infratrack_sysctl.conf
echo "net.ipv4.conf.default.accept_source_route=0" >> infratrack_sysctl.conf
echo "net.ipv4.conf.all.accept_redirects=0" >> infratrack_sysctl.conf
echo "net.ipv4.conf.default.accept_redirects=0" >> infratrack_sysctl.conf
echo "net.ipv4.conf.all.secure_redirects=1" >> infratrack_sysctl.conf
echo "net.ipv4.conf.default.secure_redirects=1" >> infratrack_sysctl.conf
echo "net.ipv4.icmp_echo_ignore_broadcasts=1" >> infratrack_sysctl.conf
echo "net.ipv4.ip_forward=0" >> infratrack_sysctl.conf
echo "net.ipv4.conf.all.send_redirects=0" >> infratrack_sysctl.conf
echo "net.ipv4.conf.default.send_redirects=0" >> infratrack_sysctl.conf
echo "net.ipv4.ip_local_port_range=9000 65500" >> infratrack_sysctl.conf
echo "net.ipv4.udp_wmem_min=3054240" >> infratrack_sysctl.conf
echo "net.ipv4.udp_wmem_max=4072320" >> infratrack_sysctl.conf
echo "net.ipv4.udp_mem=3054240 4072320 6108480" >> infratrack_sysctl.conf
echo "###########################" >> infratrack_sysctl.conf
echo "###        IPV6         ###" >> infratrack_sysctl.conf
echo "###########################" >> infratrack_sysctl.conf
echo "net.ipv6.conf.all.disable_ipv6=1" >> infratrack_sysctl.conf
echo "net.ipv6.conf.all.forwarding=0" >> infratrack_sysctl.conf
echo "###########################" >> infratrack_sysctl.conf
echo "###       Network       ###" >> infratrack_sysctl.conf
echo "###########################" >> infratrack_sysctl.conf
echo "net.core.netdev_max_backlog=300000" >> infratrack_sysctl.conf
echo "net.core.rmem_default=262144" >> infratrack_sysctl.conf
echo "net.core.rmem_max=4194304" >> infratrack_sysctl.conf
echo "net.core.wmem_default=262144" >> infratrack_sysctl.conf
echo "net.core.wmem_max=1048576" >> infratrack_sysctl.conf
echo "###########################" >> infratrack_sysctl.conf
echo "###    Other Settings   ###" >> infratrack_sysctl.conf
echo "###########################" >> infratrack_sysctl.conf
echo "vm.min_free_kbytes=102400" >> infratrack_sysctl.conf

CURRENT=$(date +%Y%m%d%H%M%S)
cp /etc/sysctl.conf /etc/sysctl.conf.$CURRENT
mv infratrack_sysctl.conf /etc/sysctl.conf

Save the content to kernel_size.sh, make the file executable and run it as root user. The original file will be backed up as /etc/sysctl.conf.<%Y%m%d%H%M%S>

Restart your machine