一元网络论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 54|回复: 0

Sing-box 服务端安装指南:补充知识

[复制链接]

1万

主题

1万

帖子

5万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
54609
发表于 2024-8-21 20:51:42 | 显示全部楼层 |阅读模式
## sing-box 服务端安装指南
本文档旨在帮助新手安装 sing-box 服务端,并提供详细的步骤和代码示例。
**安装步骤:**
1. **下载安装程序包:** 从 GitHub releases 页面下载最新版本的 sing-box 程序包,并解压到 `/usr/local/bin` 目录。
2. **上传配置和证书:** 将配置文件、证书和私钥文件上传到 `/etc/sing-box` 目录。
3. **下载 systemctl 配置:** 将 systemctl 配置文件下载到 `/etc/systemd/system` 目录。
4. **启动程序:** 使用 `systemctl enable --now sing-box` 命令启动 sing-box 服务。
**卸载步骤:**
1. **停止服务:** 使用 `systemctl stop sing-box.service` 命令停止 sing-box 服务。
2. **删除程序和配置文件:** 删除 `/usr/local/bin/sing-box`、`/etc/systemd/system/sing-box.service`、`/var/lib/sing-box` 和 `/etc/sing-box` 目录。
3. **重新载入 systemctl:** 使用 `systemctl daemon-reload` 命令重新载入 systemctl。
**常用服务管理命令:**
* 自启+启动: `sudo systemctl enable sing-box.service --now`
* 查看状态: `systemctl status sing-box.service`
* 重启: `systemctl restart sing-box.service`
* 停止: `systemctl stop sing-box.service`
* 取消自启: `systemctl disable sing-box.service`
**查看日志:**
* 最新日志: `sudo journalctl -u sing-box --output cat -e`
* 滚动日志: `sudo journalctl -u sing-box --output cat -f`
**添加防火墙:**
```
ufw allow 37065,60316,61703,39720,61970,34927,46728,61728,21878,2514/tcp
ufw allow 37065,60316,61703,39720,61970,34927,46728,61728,21878,2514/udp
```
**代码示例:**
```yaml
# 下载并安装最新稳定版本的 sing-box 程序包
curl -Lo sing-box.tar.gz https://github.com/SagerNet/sing-box/releases/latest/download/$(curl https://api.github.com/repos/SagerNet/sing-box/releases|grep -E '"name": "sing-box-.*-linux-amd64.tar.gz"'|grep -Pv '(alpha|beta|rc)'|sed -n 's/.*"name": "\(.*\)".*/\1/p'|head -1) && tar -xzf sing-box.tar.gz && cp -f sing-box-*/sing-box . && rm -r sing-box.tar.gz sing-box-* && chown root:root sing-box && chmod +x sing-box && mv -f sing-box /usr/local/bin/
# 上传配置文件、证书和私钥文件
mkdir /etc/sing-box && curl -Lo /etc/sing-box/bing.com.crt https://gist.githubusercontent.com/surgepro/4c7e48a4ac1723e2c1dcd76721183862/raw/48463cb70eeeddab3c4b233a639aa64e4e23533b/bing.com.crt && curl -Lo /etc/sing-box/bing.com.key https://gist.githubusercontent.com/surgepro/f3b67a5a0d0cb0c122a89b78dc684a8a/raw/a64c17feb3605b1642eaa7fe082870321cce7adf/bing.com.key && curl -Lo /etc/sing-box/config.json https://gist.githubusercontent.com/surgepro/ca9bdceac0eb340caf373ff223330ca9/raw/03c4aea1cf221e95336036ebad28e5399e3f999d/config.json
# 下载 systemctl 配置文件
curl -Lo /etc/systemd/system/sing-box.service https://gist.githubusercontent.com/surgepro/e046e71dc08e69bfe81b70769558d286/raw/59d488f745b2c962d27dd37e4117a7844bcfe830/sing-box.service && systemctl daemon-reload
# 启动 sing-box 服务
systemctl enable --now sing-box
```
**注意:** 以上代码仅供参考,请根据实际情况进行调整。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|一元网络论坛

GMT+8, 2024-9-17 14:44 , Processed in 0.097407 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表