Linux OS Tuning Script Examples

The most important suggestions listed in the section Linux Operating System Configuration can be easily applied by making use of a script and init.d.

This page includes script examples that can be used to tune the operating system (OS) in case you are using Debian or CentOS, along with instructions on how to install the scripts.

It is important that the script is set up in a way that it gets executed even after the machine reboots. Instructions on how to configure your system so that the script executes during the boot process can be found below.

Debian

Script:

  1. #!/bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides: arangodb-memory-configuration
  4. # Required-Start:
  5. # Required-Stop:
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Set arangodb kernel parameters
  9. # Description: Set arangodb kernel parameters
  10. ### END INIT INFO
  11. # 1 - Raise the vm map count value
  12. sudo sysctl -w "vm.max_map_count=2048000"
  13. # 2 - Disable Transparent Huge Pages
  14. sudo bash -c "echo madvise > /sys/kernel/mm/transparent_hugepage/enabled"
  15. sudo bash -c "echo madvise > /sys/kernel/mm/transparent_hugepage/defrag"
  16. # 3 - Set the virtual memory accounting mode
  17. sudo bash -c "echo 0 > /proc/sys/vm/overcommit_memory"

Installation Instructions:

  1. Create the file inside the /etc/init.d/ directory, e.g.

    /etc/init.d/arangodb-os-optimization

  2. Set correct permission, to mark the file executable:

    sudo chmod 755 /etc/init.d/arangodb-os-optimization

  3. On Ubuntu, use the following command to configure your system to execute the script during the boot process:

    sudo update-rc.d arangodb-os-optimization defaults

Note:

You might need the package sysfsutils. If this is the case, please install it via:

sudo apt install sysfsutils

Important:

To optimize the OS “now”, without having to restart the system, the script must also be directly executed once.

RedHat / CentOS / SUSE

Script:

  1. #!/bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides: arangodb-memory-configuration
  4. # Required-Start:
  5. # Required-Stop:
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Set arangodb kernel parameters
  9. # Description: Set arangodb kernel parameters
  10. ### END INIT INFO
  11. # 1 - Raise the vm map count value
  12. sysctl -w "vm.max_map_count=2048000"
  13. # 2 - Disable Transparent Huge Pages
  14. bash -c "echo madvise > /sys/kernel/mm/transparent_hugepage/enabled"
  15. bash -c "echo madvise > /sys/kernel/mm/transparent_hugepage/defrag"
  16. # 3 - Set the virtual memory accounting mode
  17. bash -c "echo 0 > /proc/sys/vm/overcommit_memory"

Installation Instructions:

  1. Create the file inside the /etc/init.d/ directory. e.g.

    /etc/init.d/arangodb-os-optimization

  2. Set correct permission, to mark the file executable. As root:

    chmod 755 /etc/init.d/arangodb-os-optimization

  3. On CentOS/RedHat, use the following commands to configure your system to execute the script during the boot process. As root:

    1. chkconfig --add /etc/init.d/arangodb-os-optimization
    2. chkconfig arangodb-os-optimization on

Note:

You might need the package sysfsutils. If this is the case, please install it, as root, via:

yum install sysfsutils

Important:

To optimize the OS “now”, without having to restart the system, the script must also be directly executed once.