如何在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 目录下

  1. 安装docker
sudo curl -fsSL https://get.docker.com | bash -s docker
  1. 启动docker
sudo systemctl start docker
  1. 新建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
  1. 运行
cd ~/sing-box
docker-compose up -d
  1. 卸载
docker-compose down
rm -rf /etc/sing-box
Logo

更多推荐