目标操作系统:Ubuntu20.04。
安装
安装Go
Ubuntu20.04默认的Golang版本为1.13。要按照当前最新的1.16.5,如下所示:
wget https://dl.google.com/go/go1.16.4.linux-amd64.tar.gz
sudo tar -xvf go1.16.4.linux-amd64.tar.gz
sudo mv go /usr/local
在Shell的配置文件中设置以下:
export GOROOT=/usr/local/go
export GOPATH=$HOME/your/gopath
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
参考
编译Clash
参考https://github.com/Dreamacro/clash/wiki
go install github.com/Dreamacro/clash@latest
如果网络不好,可能会失败
下载Clash
从https://github.com/Dreamacro/clash/releases下载,然后使用gunzip -k
解压。
个人习惯是放到/opt/clash
下面
以systemd服务运行
参考clash as a daemon。设计一个clash.service文件:
[Unit]
Description=Clash daemon, A rule-based proxy in Go.
After=network.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/local/bin/clash -d /etc/clash
[Install]
WantedBy=multi-user.target
放置或者链接到/etc/systemd/system/clash.service
。
相关命令:
systemctl enable clash
systemctl start clash
systemctl stop clash
systemctl status clash
journalctl -xe
service clash start
service clash stop
service clash restart
service clash status
查看日志:
journalctl -e -u clash.service
如果想要将日志单独记录到文件,可以使用 systemd 的 StandardOutput 和 StandardError 将日志定向到文件中:
# Works only in systemd v240 and newer!
StandardOutput=append:/var/log/clash/log.log
StandardError=append:/var/log/clash/error.log
参考https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput=
如果之前运行过clash,那么在~/.config/clash
下会生成
- config.yaml
- Country.mmdb
将这两个文件拷到目前配置目录,比如/etc/clash
。
WebUI
可以使用:
需要在config.xml中设置external-ui到dashboard资源所在路径。
可以在/ui
路径下访问Web管理界面。直接访问根目录会告知{"hello": "clash"}
。
其他参考
- https://lancellc.gitbook.io/clash/
- https://github.com/Dreamacro/clash/wiki/configuration
- 如何在Linux中使用Clash(前提:在Windows中已经连接成功)——保姆级别教程
- 此文将clash服务放置在
/usr/lib/systemd/system/clash.service
- 此文将clash服务放置在
- 在 Linux 上使用 Clash 作代理
- https://github.com/Sitoi/SystemdClash
- Clash-Linux-折腾笔记
- Clash自动更新订阅配置
- ubuntu安装clash+yacd-gui
- https://github.com/SpongeNobody/Clashy
- https://github.com/haishanh/yacd
名词解释
TUN/TAP
TUN,即netowrk TUNnel,层3的隧道。 TAP,即network TAP吗,层2的隧道。
(未完待续)
2021-07-09更新
Clash的Web界面:
(更新完)