Skip to content

常用 Linux 运维脚本 🐧

本文档整理了一些常用的 Linux 服务器运维脚本,涵盖了系统重装、网络测试、系统优化和代理工具等。


💿 系统重装 (DD 脚本)

用于将当前 Linux 系统重装为指定的发行版。执行前请务必备份好所有重要数据!

1. Leitbogioro 脚本

bash
wget --no-check-certificate -qO InstallNET.sh 'https://raw.githubusercontent.com/leitbogioro/Tools/master/Linux_reinstall/InstallNET.sh' && chmod a+x InstallNET.sh && bash InstallNET.sh -debian 12 -pwd 'password'
  • 说明:
    • -debian 12: 指定重装为 Debian 12 系统。
    • -pwd 'password': 设置新系统的 root 密码为 password,请务必修改为您自己的强密码。

2. 萌咖 (MoeClub) 脚本

bash
bash <(wget --no-check-certificate -qO- 'https://raw.githubusercontent.com/MoeClub/Note/master/InstallNET.sh') -d 11 -v 64 -p 密码 -port 端口 -a -firmware
  • 说明:
    • -d 11: 指定 Debian 版本为 11。
    • -v 64: 指定系统架构为 64 位。
    • -p 密码: 设置 root 密码。
    • -port 端口: 设置 SSH 端口。
    • -a: 表示全盘自动分区。
    • -firmware: 表示包含额外的固件驱动。

🚀 网络与流媒体测试

用于测试服务器的网络性能和流媒体解锁情况。

1. 流媒体解锁测试

  • 功能: 检测服务器 IP 是否能解锁常见的流媒体服务(如 Netflix, YouTube Premium 等)。
bash
bash <(curl -L -s check.unlock.media)

2. 回程路由测试

  • 功能: 测试服务器到国内三网(电信、联通、移动)的回程路由路径。
bash
wget -N --no-check-certificate https://raw.githubusercontent.com/Chennhaoo/Shell_Bash/master/AutoTrace.sh && chmod +x AutoTrace.sh && bash AutoTrace.sh

⚡ 系统优化

开启 BBR

  • 功能: 在较新的 Debian 或 Ubuntu 系统上一键开启 Google BBR 拥塞控制算法,以优化 TCP 连接,提升网络速度。
  • 步骤:
    1. 依次执行以下命令,将 BBR 配置写入系统文件。
    2. 最后两条命令用于检查 BBR 是否成功开启。
bash
# 写入BBR配置
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf

# 应用配置
sysctl -p

# 检查BBR是否已启动
sysctl net.ipv4.tcp_available_congestion_control
lsmod | grep bbr
  • 验证: 如果执行 lsmod | grep bbr 后有输出结果,通常表示 BBR 已成功开启。

代理与隧道工具

一键安装常用的代理转发工具。

1. Realm

  • 功能: 一键安装 realm,一个高性能的端口转发工具。
bash
bash <(curl -L https://raw.githubusercontent.com/zhouh047/realm-oneclick-install/main/realm.sh) -i

2. Gost

  • 功能: 一键安装 gost,一个功能强大的瑞士军刀级隧道工具。
bash
wget --no-check-certificate -O gost.sh https://raw.githubusercontent.com/qqrrooty/EZgost/main/gost.sh && chmod +x gost.sh && ./gost.sh

服务器优化相关

bash
cat > /etc/sysctl.conf << EOF
fs.file-max = 6815744
net.ipv4.tcp_no_metrics_save=1
net.ipv4.tcp_ecn=0
net.ipv4.tcp_frto=0
net.ipv4.tcp_mtu_probing=0
net.ipv4.tcp_rfc1337=0
net.ipv4.tcp_sack=1
net.ipv4.tcp_fack=1
net.ipv4.tcp_window_scaling=1
net.ipv4.tcp_adv_win_scale=1
net.ipv4.tcp_moderate_rcvbuf=1
net.core.rmem_max=33554432
net.core.wmem_max=33554432
net.ipv4.tcp_rmem=4096 87380 33554432
net.ipv4.tcp_wmem=4096 16384 33554432
net.ipv4.udp_rmem_min=8192
net.ipv4.udp_wmem_min=8192
net.ipv4.ip_forward=1
net.ipv4.conf.all.route_localnet=1
net.ipv4.conf.all.forwarding=1
net.ipv4.conf.default.forwarding=1
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
net.ipv6.conf.all.forwarding=1
net.ipv6.conf.default.forwarding=1
EOF
sysctl -p && sysctl --system