Giter VIP home page Giter VIP logo

linux-optimizer's Introduction

Linux Optimizer

This Bash script automates the optimization of your Linux server.

Notes:

  1. This script is designed for execution on Linux server environments, including VPS, VDS, Dedicated, and Bare Metal systems. It is not recommended for use on Linux desktop environments.
  2. Modifying the kernel (options 1 and 2) may result in removing or resetting some GPU drivers.
  3. Some VMs do not support kernel changes (options 1 and 2). Installing XanMod could cause the VM to break. Please be cautious and test beforehand.

It performs the following tasks:

  1. Fix hosts file and DNS (temporarily):

    • Check and add 127.0.1.1 and server hostname to /etc/hosts.

    Original hosts file is backed up at /etc/hosts.bak.

    • Add 1.1.1.2, 1.0.0.2 nameservers to /etc/resolv.conf.

    Original dns file is backed up at /etc/resolv.conf.bak.

  2. Update, Upgrade, and Clean the server:

    • Update
    • Upgrade
    • Full-Upgrade
    • AutoRemove
    • AutoClean
    • Clean
  3. Disable Terminal Ads (Only on Ubuntu).

  4. Install XanMod Kernel (Only on Ubuntu & Debian):

  5. Install Useful Packages:

    apt-transport-https apt-utils autoconf automake bash-completion bc binutils binutils-common binutils-x86-64-linux-gnu build-essential busybox ca-certificates cron curl dialog epel-release gnupg2 git haveged htop jq keyring libssl-dev libsqlite3-dev libtool locales lsb-release make nano net-tools packagekit preload python3 python3-pip qrencode socat screen software-properties-common ufw unzip vim wget zip

  6. Enable Packages at Server Boot.

  7. Set the server TimeZone to the VPS IP address location.

  8. Create & Enable SWAP File:

    • Swap Path: "/swapfile"
    • Swap Size: 2Gb
  9. Enable IPv6 Support.

  10. Optimize the SYSCTL Configs:

    • Optimize File System Settings.
    • Optimize Network Core Settings.
    • Optimize SWAP.
    • Optimize TCP and UDP Settings.
    • Optimize UNIX Domain Sockets Settings.
    • Optimize Virtual memory (VM) Settings.
    • Optimize Network Configuration Settings.
    • Optimize the Kernel.
    • Activate BBR (BBRv3 with XanMod).

    Original file is backed up at /etc/sysctl.conf.bak.

  11. Optimize SSH:

    • Disable DNS lookups for connecting clients.
    • Remove less efficient encryption ciphers.
    • Enable and Configure TCP keep-alive messages.
    • Allow agent & TCP forwarding.
    • Enable gateway ports, Tunneling and compression.
    • Enable X11 Forwarding.

    Original file is backed up at /etc/ssh/sshd_config.bak.

  12. Optimize the System Limits:

    • Soft and Hard ulimit -c -d -f -i -l -n -q -s -u -v -x optimizations.
  13. Optimize UFW and open Common Ports:

    • Open Ports SSH, 80, 443.
    • With IPv6, TCP & UDP.

Reboot at the end is Recommended.

Prerequisites

Ensure that the sudo and wget packages are installed on your system:

  • Ubuntu & Debian:
sudo apt update -q && sudo apt install -y sudo wget
  • CentOS & Fedora:
sudo dnf up -y && sudo dnf install -y sudo wget

Run

Tested on: Ubuntu 20+, Debian 11+, CentOS Stream 8+, AlmaLinux 8+, Fedora 37+

Root Access is Required. If the user is not root, first run:

sudo -i

Then:

wget "https://raw.githubusercontent.com/hawshemi/Linux-Optimizer/main/linux-optimizer.sh" -O linux-optimizer.sh && chmod +x linux-optimizer.sh && bash linux-optimizer.sh 

Menu Image

Debian & Ubuntu:

debian-based-menu

CentOS, AlmaLinux & Fedora:

rhel-based-menu

Disclaimer

This script is provided as-is, without any warranty or guarantee. Use it at your own risk.

License

This script is licensed under the MIT License.

linux-optimizer's People

Contributors

hawshemi avatar samsesh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

linux-optimizer's Issues

[SUGGESTION] unInstall XanMod Kernel

Is your feature request related to a problem? Please describe.
for any reason a user might want to remove the installation. For example I tested on Debian 11 and 12. Later for any apt update -y it hangs

Describe the solution you'd like
Adding a remove/uninstall option to the bash script

Describe alternatives you've considered
otherwise a user has to do it manually

Additional context
A software without a Ctrl-Z option is incomplete

Regards

Xanmod install

نصب xanmod کلا سرور هامو کند کرده و غیرقابل استفاده

[SUGGESTION]

درود

بنظرم اگه برای هر مرحله If قرار بدید خیلی بهتر میشه چون ی سری هاشو شاید یکی نخواد بزنه رو سرورش

مثلا قسمت اخر که میشه پورت ها رو من یکی به شخصه استفاده نمیکنم حالا باید وقت بزارم همه پورت هایی که باز کرده رو دونه دونه ببندم.

ممنون بابت اسکریپ

Loop with ubuntu user[BUG]

When i run it with this command on my server which is not root user by default, it falls in to a Loop.
sudo bash< <(curl -s https://raw.githubusercontent.com/hawshemi/Linux-Optimizer/main/linux-optimizer.sh)

It give me this error and contiue showing the menu.
[*] ----- Wrong input!

  • OS: Ubuntu
  • Version: 22

BBR VS hybla[SUGGESTION]

سلام و خسته نباشید - بین hybla و BBr فرقی هست و اگر هست توی سرور از hybla استفاده بشه نسبت به BBR تاثیری بر روی سرور احساس میشه . مثلا = پینگ .. یا پکت لاس ...

Adding Selective WARP [SUGGESTION]

Thanks for Linux-Optimizer
Would be wonderful if you could add selective WARP to your wonderful script in the next update

Thank you in advance and keep up the good work✌🏽

[BUG]آیا راهی برای پاک کردن و برگشت به حالت قبل هست

سلام وقت بخیر
آیا راهی برای پاک کردن و برگشت به حالت قبل هست
از وقتی روی سروری که پنل هدیفای نصب بوده ، اسکریپت نصب کردم cpu از 75درصد پایین تر نمیاد و در روز چندبازی سرور دان میشه مجبور می شوم سرور از پنل ریبوت کنم
سرور 4هسته 3gh و 8گیگ ram دارد
متشکر می شوم راهنمایی بفرمایید

Could you please add a resolution for audio and video call issues (UDPGW)

sudo wget -O /usr/bin/badvpn-udpgw "https://raw.githubusercontent.com/daybreakersx/premscript/master/badvpn-udpgw64"

apt install screen

sudo touch /etc/rc.local

echo -e '#!/bin/sh -e\nscreen -dmS udpvpn /bin/badvpn-udpgw --listen-addr 127.0.0.1:7300 --max-clients 1000 --max-connections-for-client 10\nscreen -AmdS badvpn badvpn-udpgw --listen-addr 127.0.0.1:7300\nscreen -dmS udpvpn /bin/badvpn-udpgw --listen-addr 127.0.0.1:2097 --max-clients 1000 --max-connections-for-client 10\nscreen -AmdS badvpn badvpn-udpgw --listen-addr 127.0.0.1:2097\nexit 0' >> /etc/rc.local

ufw allow 7300
ufw allow 2097
sudo chmod +x /etc/rc.local
sudo chmod +x /usr/bin/badvpn-udpgw
sudo chmod +x /bin/badvpn-udpgw

reboot
sudo systemctl status rc-local.service
sudo lsof -i -P -n | grep LISTEN

Install the "screen" so that all users can access UDPGW
The 2097 port should be added if the 7300 fails to respond

[SUGGESTION] A menu item for every option

Some users have already done their own tweaks and don't want the script to modify everything.
We need a menu item for every single option.
Thanks much for the great work.

bpfilter read fail 0

Describe the bug
bpfilter read fail 0

Logs
If applicable, could you add a log to help explain your problem?

Linux (please complete the following information):

  • OS: Ubuntu
  • Version: 20.04

Additional context
Please feel free to add any other context about the problem here.

[SUGGESTION]

سلام خواستم تشکر کنم بابت این اسکرپیت خفنتون ...

و اینکه دیگه اپدیت نمیکنید برای اوبنتو های بالای 22 ؟ و چیز های دیگه ای اضافه بشه ؟

[suggestion / feature request] Menu or optional arguments for installation.

Hey there!
before moving on, i wanna thank you for this awesome script, it saves so much time setting up a new server.

so i'm wondering if it will be possible for you to include either a menu to select installation options ( eg. i don't wanna install "Useful Packages" so i de-select that ) or optional arguments to scripts ( eg. --no-packages to avoid installing "Useful Packages" ).

another thing that i thought it'd be better to ask here to avoid creating multiple issues is changing dns servers in /etc/resolv.conf to one of popular dns servers.

Thanks in advance, good luck. <3

TCP packet sending algorithm

سلام و خسته نباشید. ما ی سورسی تازه ای برای بهینه سازی تر کردن سرور پیدا کردیم. خواستم به اشتراک بزارم واسمون

TCP packet sending algorithm that strives to maintain throughput (effective bandwidth)

https://github.com/marywangran/pixie

[BUG] netplan not found ubuntu 18.04

سلام رو ابونتو 18 ران شد
نتورک دیگه بعد ریست بالا نیومد و سیستم عامل دیگه netplan رو نمیشناخت

افزایش مقذار سوآپ

سلام و خسته نباشید
من شنیدم مقدار سوآپ باید 2 برابر رم باشه
اگر ممکنه چند حالت سوآپ داشته باشیم بجای اینکه فقط 2 گیگ باشه خیلی خوبه

با تشکر

[BUG]

Describe the bug
the customization is quite nice but it thuroughly and agressively disables my nvidia gpu card (3060) can u modify the code so it doesnt touch the gpu?

Expected behaviour
optimize network and base system, leave gpu configuration intact

Logs

Linux (please complete the following information):

  • OS:
    ubuntu lts 24.02

Additional context
sudo apt install -f nvidia550firmware
sudo apt install -f nvidia550generic.driver
sudo apt install -f nvidia550kernel
install but do not switch to the proper driver

changing the ubuntu "additional driver" gui back and forth from x.org do not succeed

forcing a system update is not possible as im running the latest version

seriously tho wonderfull optimizations, my only recommendations would be to disable auto tuning and pin it to maximum speed for network and use ctcp congestion control provider, cubic is newer but worse.

After each login to Ubuntu Machine, I encounter the following errors:

-bash: ulimit: pending signals: cannot modify limit: Operation not permitted
-bash: ulimit: max locked memory: cannot modify limit: Operation not permitted
-bash: ulimit: POSIX message queues: cannot modify limit: Operation not permitted
unlimited
-bash: ulimit: max user processes: cannot modify limit: Operation not permitted

TCP_Burtal

سلام و خسته نباشید - من میخواستم این cp-brutal نصب کنم ولی ی مشکلی هست این اسکریپت از

Kernel version 4.9 or above is required, and kernel version 5.8 or above is recommended. For kernels less than 5.8, only IPv4 is supported. (missing export symbol tcpv6_prot)

⚠️Note: For systems with kernel versions lower than 4.13, fq pacing ( tc qdisc add dev eth0 root fq pacing) must be manually enabled, otherwise TCP Brutal will not work properly.
ساپورت میکنه

  • اینه که اسکریپت شما xanmod رو به صورت پیش فرض نصب میکنه

پاکسازی اسکریپت

سلام خسته نباشید برای پاک کردن اسکریپت باید چیکار کرد rm -rf کافیه یا نه؟

[SUGGESTION] sysctl options descriptions

Is your feature request related to a problem? Please describe.
there is no problem, when sysctl.conf is updated it is better to see description of each item has been added

Describe the solution you'd like
items added can be categorized and a short title for each can be added

Describe alternatives you've considered
here is an example I use

# Enable TCP BBR
# https://www.linuxbabe.com/ubuntu/enable-google-tcp-bbr-ubuntu
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr

# Protect from IP Spoofing  
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1

# Ignore ICMP broadcast requests
net.ipv4.icmp_echo_ignore_broadcasts = 1

# Protect from bad icmp error messages
net.ipv4.icmp_ignore_bogus_error_responses = 1

# Disable source packet routing
net.ipv4.conf.all.accept_source_route = 0
net.ipv6.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv6.conf.default.accept_source_route = 0

# Turn on exec shield
kernel.exec-shield = 1
kernel.randomize_va_space = 1

# Block SYN attacks
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 5

# Log Martians  
net.ipv4.conf.all.log_martians = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1

# Ignore send redirects
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0

# Ignore ICMP redirects
net.ipv4.conf.all.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0

the above is much more readable and easy to update comparing to the same but without titles

net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.all.accept_source_route = 0
net.ipv6.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv6.conf.default.accept_source_route = 0
kernel.exec-shield = 1
kernel.randomize_va_space = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 5
net.ipv4.conf.all.log_martians = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0

BASH VERSION

سلام خسته نباشید امکان داره این سورس رو ورژن BASH ش ساخته بشه تا فایلی توی سرور سیو نشه؟

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.