Skip to content

VPS 常用脚本及配置

软件包

https://www.nodeseek.com/post-35937-2#14

txt
wget curl nano vim sudo unzip mtr-tiny iputils-ping bind9-host dnsutils net-tools lsb-release ca-certificates bash-completion fail2ban dialog netbase iproute2 whois ssh dbus systemd systemd-sysv ifupdown locales apt-utils gnupg2 apt-transport-https rsyslog logrotate less rsync haveged systemd-timesyncd iperf3

强迫症必备

https://www.nodeseek.com/post-284926-1

  • touch ~/.hushlogin 让当前用户登录 Linux 时,不再显示 MOTD(Message of the Day)和一些欢迎提示信息
  • sed -i '/unset HISTFILE/d; $a\unset HISTFILE' /root/.bashrc Bash 不再把历史记录写入文件(但会保留在内存中,退出 Shell 后丢失)
  • rm -f /root/.bash_history 删除 root 用户的 Bash 历史记录文件
  • history -c 清空当前 Shell 会话里的命令历史(内存中的部分)

清理日志

单次清理

查看日志大小

sh
journalctl --disk-usage

保留最近 30 天日志

sh
journalctl --vacuum-time=30d

限制最大占用 500MB

sh
journalctl --vacuum-size=500M

长期设置

/etc/systemd/journald.conf 中直接设置最大占用

/etc/systemd/journald.conf
txt
SystemMaxUse=500M
MaxRetentionSec=30day

重启服务

sh
systemctl restart systemd-journald

美化 SSH

sh
echo "alias ls='ls --color=auto'" >>/root/.bashrc
echo "alias ll='ls --color=auto -lAF'" >>/root/.bashrc
echo "PS1='\[\033[01;31m\]\u\[\033[01;33m\]@\[\033[01;36m\]\h \[\033[01;33m\]\w \[\033[01;35m\]\$ \[\033[00m\]'" >>/root/.bashrc
source /root/.bashrc

Docker

sh
curl -sSL https://get.docker.com/ | sh

YABS

https://github.com/masonr/yet-another-bench-script

sh
# 完整测试(系统信息 + 硬盘测试 + iPerf3 + GeekBench5 + GeekBench6)
curl -sL yabs.sh | bash -s -- -r -5 -6

# 系统信息
curl -sL yabs.sh | bash -s -- -i -d -g

# 磁盘测速
curl -sL yabs.sh | bash -s -- -i -g

# GeekBench 5
curl -sL yabs.sh | bash -s -- -i -d -5

# GeekBench 6"
curl -sL yabs.sh | bash -s -- -i -d

路由追踪

NextTrace

https://github.com/nxtrace/NTrace-core

安装

sh
# /usr/local/bin/nexttrace
curl nxtrace.org/nt |bash

使用

sh
# 基本使用
nexttrace ip/domain

# 快速测试
nexttrace --fast-trace

# 自定义测试
nexttrace --file /path/to/your/iplist.txt

BackTrace

https://github.com/zhanghanyun/backtrace

安装

sh
# 三网回程直接显示
# /usr/bin/backtrace
curl https://raw.githubusercontent.com/zhanghanyun/backtrace/main/install.sh -sSf | sh

使用

sh
backtrace

流媒体解锁

https://github.com/lmc999/RegionRestrictionCheck

sh
bash <(curl -L -s check.unlock.media)

MTProto

https://github.com/cutelua/mtg-dist

安装

sh
bash <(wget -qO- https://git.io/mtg.sh)

卸载

sh
systemctl disable mtg
systemctl stop mtg
rm -f /usr/local/bin/mtg /etc/systemd/system/mtg.service /etc/mtg.toml

时间同步

systemd-timesyncd

启用

sh
timedatectl set-ntp true

查看状态

sh
timedatectl status

Chrony

安装

sh
apt-get install chrony

使用

ini
# /etc/chrony/chrony.conf
# 添加 NTP 服务器
server ntp.aliyun.com minpoll 4 maxpoll 10 iburst
server us.pool.ntp.org minpoll 4 maxpoll 10 iburst

启动

sh
systemctl start chronyd
systemctl enable chronyd

验证

sh
chronyc tracking
chronyc -n sources -v

BBR

旧版

直接修改 /etc/sysctl.conf

sh
# Linux 内核版本大于 4.9
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -p
sysctl net.ipv4.tcp_available_congestion_control
lsmod | grep bbr

新版

创建 /etc/sysctl.d/*.conf 来单独配置

sh
tee /etc/sysctl.d/99-bbr.conf >/dev/null <<EOF
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
EOF
sysctl --system
sysctl net.ipv4.tcp_congestion_control
lsmod | grep bbr

Last updated:

经典款
RackNerd

RackNerd

新手入门首选

洛杉矶 DC3 机房 | 3T 大流量

1C / 1GB / 20GB SSD / 3TB 流量

$21.99/年
欧洲优化
V.PS

V.PS

可选荷兰 / 德国

欧洲三网优化 | 电信 GIA + 联通 9929 + 移动 CMIN2

2C / 1GB / 20GB NVMe / 1TB 流量

€6.95/月
关注微信公众号
优化线路
Evoxt

Evoxt

最便宜的亚太优化线路

马来西亚 电信 GIA / 联通 9929
优惠码:AFF2377-DEV

1C / 512MB / 5GB SSD / 150GB 流量

$3.32/月
优化线路
搬瓦工

搬瓦工

15 个机房自由切换

洛杉矶 DC6 机房
电信 / 联通 GIA + 移动 CMIN2

2C / 2GB / 40GB SSD / 2.5TB 流量

$49.99/季