소개 · Clash 문서

Clash를 서비스로 실행

Clash 바이너리와 config.yaml을 systemd 서비스로 배포하고 daemon-reload, 부팅 시 자동 시작, 서비스 시작, 상태 확인을 수행하는 방법과 Docker 이미지의 기본 실행 방식을 설명합니다.

  • systemd
  • Docker
  • config.yaml
  • 데몬
  • journalctl
소개

Clash는 백그라운드에서 실행되어야 하지만 현재 Golang에는 적절한 데몬 구현이 없으므로 서드파티 도구를 사용해 Clash 데몬을 만드는 것이 좋습니다.

systemd

다음 명령으로 Clash 바이너리를 /usr/local/bin에, 구성 파일을 /etc/clash에 복사하세요:

shell
cp clash /usr/local/bin
cp config.yaml /etc/clash/
cp Country.mmdb /etc/clash/

systemd 구성 파일을 만드세요: /etc/systemd/system/clash.service

ini
[Unit]
Description=Clash 守护进程, Go 语言实现的基于规则的代理.
After=network-online.target

[Service]
Type=simple
Restart=always
ExecStart=/usr/local/bin/clash -d /etc/clash

[Install]
WantedBy=multi-user.target

이어서 아래 명령으로 systemd를 다시 로드해야 합니다:

shell
systemctl daemon-reload

다음 명령을 사용해 시스템 시작 시 Clash를 실행하세요:

shell
systemctl enable clash

다음 명령을 사용해 Clash를 즉시 실행하세요:

shell
systemctl start clash

다음 명령으로 Clash 실행 상태와 로그를 확인하세요:

shell
systemctl status clash
journalctl -xe

이 가이드는 ktechmidas님이 기여했습니다(#754).

Docker

이 프로젝트는 Clash 및 Clash Premium용 사전 빌드 Docker 이미지를 제공합니다. 따라서 Linux에서는 Docker Compose 기반으로 Clash를 배포할 수 있습니다. 다만 컨테이너에서 Clash Premium 실행은 권장되지 않습니다.

경고

Mac용 Docker에는 호스트 네트워크와 TUN 지원이 없으므로 이 설정은 macOS에서 작동하지 않습니다.

yaml
services:
  clash:
    image: ghcr.io/dreamacro/clash
    restart: always
    volumes:
      - ./config.yaml:/root/.config/clash/config.yaml:ro
      # - ./ui:/ui:ro # 仪表盘 Volume 映射
    ports:
      - "7890:7890"
      - "7891:7891"
      # - "8080:8080" # 外部控制 (RESTful API)
    network_mode: "bridge"
yaml
services:
  clash:
    image: ghcr.io/dreamacro/clash-premium
    restart: always
    volumes:
      - ./config.yaml:/root/.config/clash/config.yaml:ro
      # - ./ui:/ui:ro # 仪表盘 Volume 映射
    ports:
      - "7890:7890"
      - "7891:7891"
      # - "8080:8080" # 外部控制 (RESTful API)
    cap_add:
      - NET_ADMIN
    devices:
      - /dev/net/tun
    network_mode: "host"

파일 이름을 docker-compose.yaml로 저장한 뒤 config.yaml 파일을 같은 디렉터리에 두세요.

계속하기 전에 플랫폼의 시간 동기화 문서를 확인하세요. 시간이 동기화되지 않으면 일부 프로토콜이 정상적으로 작동하지 않을 수 있습니다.

준비가 끝나면 다음 명령을 실행해 Clash를 시작하세요:

shell
docker-compose up -d

다음 명령으로 로그를 확인할 수 있습니다:

shell
docker-compose logs

다음 명령으로 Clash를 중지합니다:

shell
docker-compose stop