|
Recently, I came across similar posts from experienced users but felt there were more efficient ways to configure certain settings. Here, I'll share my optimization strategy (I'll update this if I find improvements).
Note: Most of my systems run Debian or similar distributions, so if any commands don't work for you, feel free to ask in the comments.
System Configuration
Update Software Repositories
apt update -y && apt upgrade -y
Install Essential Software
apt install sudo curl wget nano
Set System Time Zone to Shanghai
sudo timedatectl set-timezone Asia/Shanghai
To view the current time zone:
timedatectl
To list all available time zones:
timedatectl list-timezones
System Parameter Optimization
This involves adjusting various system and network parameters to improve server performance.
Implementation Methods:
Kernel Parameter Tuning: Increase TCP buffer sizes, modify system queue lengths, etc., to enhance network throughput and reduce latency.Performance Optimization: Install and configure tools like Tuned to automatically adjust and optimize the server's operating state.Resource Limitations: Set limits on the number of open files to prevent resource exhaustion attacks.
These optimizations help manage resources more effectively and protect against external threats, ensuring stable system operation.
bash
Better Bandwidth and RTT (BBR)
BBR is a congestion control algorithm developed by Google designed to optimize network performance and reduce latency.
Enable BBRX Acceleration
bash
Restart the VPS to apply kernel updates and BBR settings:
sudo reboot
To verify BBR is enabled:
lsmod | grep bbr
The output should include:
tcp_bbrx
tcp_bbr
If only tcp_bbr appears, wait a few minutes and reboot again.
Add SWAP Space
SWAP space is a designated disk area used as additional memory when RAM is low. This can significantly boost performance on servers with limited RAM.
Here's how to add SWAP using a script:
wget -O swap.sh https://raw.githubusercontent.com/eros520/Script/main/swap.sh && chmod +x swap.sh && ./swap.sh
To check current memory usage:
free -m
Install Docker and Docker Compose
Docker Installation
Non-Mainland Servers
wget -qO- get.docker.com | bash
Alternatively:
curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh
Mainland Servers
curl -sSL https://get.daocloud.io/docker | sh
Verify Docker Version
docker -v
Enable Auto Start at Boot
systemctl enable docker
Uninstall Docker
sudo apt-get purge docker-ce docker-ce-cli containerd.io
sudo apt-get remove docker docker-engine
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
Docker Compose Installation
Download Docker Compose
For non-mainland servers:
curl -L "https://github.com/docker/compose/releases/download/v2.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
For mainland servers:
curl -L https://get.daocloud.io/docker/compose/releases/download/v2.1.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
Grant Permissions to Docker Compose
chmod +x /usr/local/bin/docker-compose
Check Docker Compose Version
docker-compose --version
|
|