如何在Linux上配置sing-box

扶苏如是 2024-06-26 10:37:02 阅读 55

如何在Linux上配置sing-box

安装方法:

Debian / DEB:

bash <(curl -fsSL [https://sing-box.app/deb-install.sh](https://sing-box.app/deb-install.sh))

Redhat / RPM

bash <(curl -fsSL [https://sing-box.app/rpm-install.sh](https://sing-box.app/rpm-install.sh))

Archlinux / PKGArchlinux / PKG操作系统

bash <(curl -fsSL [https://sing-box.app/arch-install.sh](https://sing-box.app/arch-install.sh)

启动

# 启动服务

systemctl start sing-box.service

# 查看启动状态

systemctl status sing-box.service

# 设置开机启动

systemctl enable sing-box.service

# 运行 -c 指定一个配置文件

sing-box run -c /etc/sing-box/config.json

项目 路径
程序 /usr/bin/sing-box
配置 /etc/sing-box/config.json
工作目录 /var/lib/sing-box
服务文件 /etc/systemd/system/sing-box.service
热载 systemctl reload sing-box
重启 systemctl restart sing-box
状态 systemctl status sing-box
查看日志 journalctl -u sing-box -o cat -e
实时日志 journalctl -u sing-box -o cat -f

卸载:

Debian/Ubuntu

# --purge会把配置也删除,保留配置请移除该参数

sudo systemctl stop sing-box.service

sudo systemctl disable sing-box.service

sudo dpkg --purge sing-box

CentOS/Fedora

# --allmatches会把配置也删除,保留配置请移除该参数

sudo systemctl stop sing-box.service

sudo systemctl disable sing-box.service

sudo rpm -e --allmatches sing-box

Archlinux

# -n参数会把配置也删除,保留配置请移除该参数

sudo systemctl stop sing-box.service

sudo systemctl disable sing-box.service

sudo pacman -Rn sing-box

通过docker安装:

配置目录映射到宿主机: /etc/sing-box 目录下

安装docker

sudo curl -fsSL https://get.docker.com | bash -s docker

启动docker

sudo systemctl start docker

新建docker-compose.yaml配置文件

mkdir ~/sing-box

cat <<EOF> ~/sing-box/docker-compose.yaml

version: "3.8"

services:

sing-box:

image: ghcr.io/sagernet/sing-box

container_name: sing-box

restart: always

volumes:

- /etc/sing-box:/etc/sing-box/

command: -D /var/lib/sing-box -C /etc/sing-box/ run

EOF

运行

cd ~/sing-box

docker-compose up -d

卸载

docker-compose down

rm -rf /etc/sing-box



声明

本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。