Linux OS Tuning Script Examples

The most important suggestions listed in the sectionLinux Operating System Configurationcan be easily applied by making use of a script and init.d.

This page includes script examples that can be used to tune theoperating 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 getsexecuted even after the machine reboots. Instructions on how toconfigure your system so that the script executes during theboot 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:

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

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

  • Set correct permission, to mark the file executable:

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

  • On Ubuntu, use the following command to configure your systemto 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.

CentOS

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:

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

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

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

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

  • On CentOS/RedHat, use the following commands to configure your systemto 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.