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:
#!/bin/bash
### BEGIN INIT INFO
# Provides: arangodb-memory-configuration
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Set arangodb kernel parameters
# Description: Set arangodb kernel parameters
### END INIT INFO
# 1 - Raise the vm map count value
sudo sysctl -w "vm.max_map_count=2048000"
# 2 - Disable Transparent Huge Pages
sudo bash -c "echo madvise > /sys/kernel/mm/transparent_hugepage/enabled"
sudo bash -c "echo madvise > /sys/kernel/mm/transparent_hugepage/defrag"
# 3 - Set the virtual memory accounting mode
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 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:
#!/bin/bash
### BEGIN INIT INFO
# Provides: arangodb-memory-configuration
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Set arangodb kernel parameters
# Description: Set arangodb kernel parameters
### END INIT INFO
# 1 - Raise the vm map count value
sysctl -w "vm.max_map_count=2048000"
# 2 - Disable Transparent Huge Pages
bash -c "echo madvise > /sys/kernel/mm/transparent_hugepage/enabled"
bash -c "echo madvise > /sys/kernel/mm/transparent_hugepage/defrag"
# 3 - Set the virtual memory accounting mode
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 system to execute the script during the boot process. As root:
chkconfig --add /etc/init.d/arangodb-os-optimization 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.