Clash 内核部署与 API 集成
Clash 开发者文档 — 内核部署、RESTful API、配置语法详解,支持 Docker、OpenWrt、自定义策略组开发。
Clash 内核部署方式
🚀 Docker 部署 Clash
docker run -d --name clash -v ./config.yaml:/root/.config/clash/config.yaml -p 7890:7890 dreamacro/clash
一行命令即可启动 Clash 容器,支持配置映射与端口绑定。
📡 OpenWrt 安装 Clash
opkg update && opkg install luci-app-clash
Clash 适配软路由,支持 luci 图形界面和 ShellClash 脚本。
🖥️ 二进制部署
wget https://github.com/Dreamacro/clash/releases/download/v1.18.0/clash-linux-amd64-v1.18.0.gz
下载 Clash 二进制文件,解压后直接运行,适合服务器使用。
⚙️ Clash Meta 内核
./clash-meta -f config.yaml
Clash Meta 分支支持更多协议和性能优化,推荐生产环境使用。
Clash RESTful API 文档
GET /configs
curl -X GET http://127.0.0.1:9090/configs
获取 Clash 当前配置信息,包括模式、规则数量等。
PUT /configs
curl -X PUT http://127.0.0.1:9090/configs -d '{"path":"new.yaml"}'
动态重载 Clash 配置文件,无需重启进程。
GET /proxies
curl http://127.0.0.1:9090/proxies
获取 Clash 所有代理节点及策略组状态。
PUT /proxies/{name}
curl -X PUT http://127.0.0.1:9090/proxies/GLOBAL -d '{"name":"🇺🇸 US Node"}'
实时切换 Clash 策略组选中的节点。
Clash 配置语法示例
Clash 基础配置文件结构
proxies:
- {name: "US-01", type: ss, server: us.example.com, port: 443, cipher: aes-256-gcm, password: "password"}
proxy-groups:
- {name: "PROXY", type: select, proxies: ["US-01", "HK-01"]}
rules:
- DOMAIN-SUFFIX,google.com,PROXY
- GEOIP,CN,DIRECT
- {name: "US-01", type: ss, server: us.example.com, port: 443, cipher: aes-256-gcm, password: "password"}
proxy-groups:
- {name: "PROXY", type: select, proxies: ["US-01", "HK-01"]}
rules:
- DOMAIN-SUFFIX,google.com,PROXY
- GEOIP,CN,DIRECT
Clash 配置分为 proxies、proxy-groups、rules 三大部分,支持丰富规则类型。
Clash 社区与生态
Clash GitHub 仓库拥有 50k+ Stars,全球开发者持续贡献。Clash 衍生项目包括 Clash Meta、Clash Verge、Clash for Windows、ClashX 等,形成了完整的代理生态。