文件
scripts/singbox
2026-04-26 18:51:31 +08:00
..
2026-04-26 18:51:31 +08:00
2026-04-26 18:51:31 +08:00

singbox.sh

基于 sing-box 的一键安装与管理脚本,提供交互式菜单来搭建、管理多种代理协议节点。

脚本作者Mr. xiao原项目地址)。本目录用于本地保存与备份,便于在不同 VPS 上快速部署。

本仓库地址:https://git.suhang.me/suhang/scripts,下方所有 wget / curl 命令均从该仓库直接拉取。

功能概览

支持的入站协议:

  • SOCKS / HTTP / Direct
  • VMess / VLESS含 Reality/ Trojan
  • Hysteria / Hysteria2
  • TUIC / Juicity
  • ShadowTLS / NaiveProxy / Shadowsocks
  • WireGuard出站,用于解锁流媒体等

管理功能:

  • 查看已搭建节点信息(含分享链接 / Clash 配置)
  • 更新内核Latest / Beta / 编译安装完整功能版)
  • 更新脚本自身
  • 申请 / 续签 TLS 证书(基于 acme.sh,支持 Let's Encrypt、ZeroSSL,HTTP-01 与 Cloudflare DNS-01
  • 重启 / 卸载服务
  • 节点管理(添加 / 删除单个用户或入站)
  • 自动配置防火墙ufw / iptables / firewalld
  • 自动开启 BBR

系统要求

  • Linux x86_64 / ARMv7 / ARM64 / AMD64v3 / s390x
  • 使用 systemd 的发行版Debian 10+ / Ubuntu 20.04+ / CentOS 8+ / Rocky / AlmaLinux 等)
  • 需要 root 权限
  • 公网 IPv4 或 IPv6部分协议要求 80/443 端口可用于证书签发)

依赖安装

脚本运行时会调用以下命令,请先确保已安装(多数发行版默认包含 bash tar systemctl iptables 等):

依赖 用途
curl / wget 下载内核、调用 GitHub / Cloudflare API
jq 解析 GitHub Release / Cloudflare API 的 JSON
openssl 生成随机密钥、自签证书、TLS 探测
tar 解压内核压缩包
systemd 管理 sing-box / juicity 服务
cron (cronie / crontabs) 自动续签证书的定时任务

Debian / Ubuntu

apt update
apt install -y curl wget jq openssl tar cron

CentOS / RHEL / Rocky / Alma

dnf install -y curl wget jq openssl tar cronie
systemctl enable --now crond

Arch Linux

pacman -Sy --noconfirm curl wget jq openssl tar cronie
systemctl enable --now cronie

选择「编译安装 sing-box完整功能版本」时,脚本会自动下载并安装 Go 编译器,无需额外安装。

申请证书时若系统未安装 acme.sh,脚本会自动通过 curl https://get.acme.sh | sh 安装。

使用方式

1. 下载脚本

从本仓库直接下载到服务器(推荐放到 /root/

# 方式一:直接下载脚本
wget -O /root/singbox.sh https://git.suhang.me/suhang/scripts/raw/branch/main/singbox/singbox.sh
chmod +x /root/singbox.sh

# 方式二:克隆整个仓库
git clone https://git.suhang.me/suhang/scripts.git /root/scripts
chmod +x /root/scripts/singbox/singbox.sh

也可以使用 curl

curl -fsSL -o /root/singbox.sh https://git.suhang.me/suhang/scripts/raw/branch/main/singbox/singbox.sh && chmod +x /root/singbox.sh

2. 运行交互式菜单

bash /root/singbox.sh

进入菜单后按编号选择操作:

[1]  SOCKS                [2]  Direct
[3]  HTTP                 [4]  VMess
[5]  VLESS                [6]  TUIC
[7]  Juicity              [8]  Trojan
[9]  Hysteria             [10] Hysteria2
[11] ShadowTLS            [12] NaiveProxy
[13] Shadowsocks          [14] WireGuard
[15] 查看节点信息          [16] 更新内核
[17] 更新脚本              [18] 更新证书
[19] 重启服务              [20] 节点管理
[21] 卸载                  [0]  退出

3. 命令行参数

目前脚本仅支持一个非交互参数,用于定时任务续签证书:

bash /root/singbox.sh 18    # 等同于菜单 [18] 更新证书

脚本会自动写入 crontab,每周一凌晨 2 点执行该命令续签:

0 2 * * 1 /bin/bash /root/singbox.sh >> /usr/local/etc/certificate.log 2>&1

路径与文件

路径 说明
/usr/local/bin/sing-box sing-box 主程序
/usr/local/bin/juicity-server Juicity 主程序(仅 Juicity 模式)
/usr/local/etc/sing-box/config.json sing-box 配置文件
/usr/local/etc/sing-box/clash.yaml 自动生成的 Clash 订阅
/usr/local/etc/juicity/config.json Juicity 配置文件
/etc/ssl/private/ TLS 证书与私钥
/etc/systemd/system/sing-box.service systemd 服务单元
/usr/local/etc/certificate.log 续签日志

常见问题

  • 菜单乱码:终端使用 UTF-8export LANG=en_US.UTF-8zh_CN.UTF-8)。
  • 证书申请失败:检查 80 端口是否被占用HTTP-01,或使用 Cloudflare DNS API需 API Token + Zone ID + Email
  • 节点不通:脚本已自动放行所选端口,如使用云厂商安全组,请同步在面板放行 TCP/UDP。
  • 内核更新后无法启动journalctl -u sing-box -n 100 --no-pager 查看日志,多数为配置与新版内核字段不兼容,可重新搭建或回退版本。

卸载

菜单选择 [21] 卸载,会停止并移除 sing-box / juicity 的二进制、配置目录与 systemd 服务。