Created
November 10, 2023 09:25
-
-
Save GhaziTriki/41c576ca086e4c1a3231df22d27f7917 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Ensure the script is run with superuser privileges | |
if [ "$EUID" -ne 0 ] | |
then echo "Please run as root" | |
exit | |
fi | |
# Update packages and the system | |
apt update && apt upgrade -y | |
# File system parameter optimization | |
echo 'fs.file-max = 2097152' >> /etc/sysctl.conf | |
# User limits optimization | |
echo '* soft nofile 1048576' >> /etc/security/limits.conf | |
echo '* hard nofile 1048576' >> /etc/security/limits.conf | |
# Network parameter optimization | |
cat >> /etc/sysctl.conf <<EOL | |
# TCP improvements to enhance network performance | |
net.core.wmem_max = 12582912 | |
net.core.rmem_max = 12582912 | |
net.ipv4.tcp_rmem = 10240 87380 12582912 | |
net.ipv4.tcp_wmem = 10240 87380 12582912 | |
net.ipv4.tcp_window_scaling = 1 | |
net.ipv4.tcp_max_syn_backlog = 8096 | |
net.ipv4.tcp_slow_start_after_idle = 0 | |
net.ipv4.tcp_tw_reuse = 1 | |
net.ipv4.ip_local_port_range = 10240 65535 | |
EOL | |
# Apply sysctl settings without rebooting | |
sysctl -p | |
# Enable BBR for TCP congestion control | |
echo 'net.core.default_qdisc=fq' >> /etc/sysctl.conf | |
echo 'net.ipv4.tcp_congestion_control=bbr' >> /etc/sysctl.conf | |
sysctl -p | |
echo "Optimizations complete. Please reboot your server to apply all changes." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment