在Debian11上安装clash
安装go环境
为依赖包设置代理
终端窗口输入如下命令:1
2
3
4# 其用Go Modules功能
go env -w GO111MODULE=on
# 配置 GOPROXY 环境变量
go env -w GOPROXY=https://goproxy.cn
安装clash
终端窗口输入如下命令:1
go install github.com/Dreamacro/clash@latest
修改clash配置
默认配置目录是 $HOME/.config/clash,下载订阅配置:1
wget -O config.yaml https://你得到的订阅网址/Clash.yml
配置文件的名称是config.yaml,如果要使用其他目录,可以使用 -d 控制配置目录。
例如,您可以使用当前目录作为配置目录,命令:1
clash -d . # 注意“.”
在默认配置目录启动命令:
1 | clash |
下载.mmdb
如果安装完后没有提示下载mmdb,则需要手动下载。Country.mmdb为全球IP库,可以实现各个国家的IP信息解析和地理定位,没有这个文件clash是无法运行的。1
wget -O Country.mmdb https://www.sub-speeder.com/client-download/Country.mmdb
附config.yaml的订阅地址:
如果无法下载可选择加速镜像站。
可参考:Github加速的10种方式
设置开机启动
移动clash到/usr/bin/文件夹下并赋予可执行权限
也可以链接到程序而不移动,但是注意设置程序路径为clash所在路径。1
2
3sudo chmod +x ~/gopath/bin/clash
sudo mv ~/gopath/bin/clash /usr/bin/
# sudo ln -s /home/username/gopath/bin/clash /usr/bin/
创建clash@.service文件
在/lib/systemd/system/目录下创建clash@.service文件1
sudo vim /lib/systemd/system/clash@.service
写入以下内容(不用修改)并保存:1
2
3
4
5
6
7
8
9
10
11
12[Unit]
Description=A rule based proxy in Go for %i.
After=network.target
[Service]
Type=simple
User=%i
Restart=on-abort
ExecStart=/usr/bin/clash
[Install]
WantedBy=multi-user.target
重新加载systemd模块
1 | systemctl daemon-reload |
启动clash服务
user 表示的是当前用户名1
systemctl start clash@user
设置开机自启
user 表示的是当前用户名1
2systemctl enable clash@user
Created symlink /etc/systemd/system/multi-user.target.wants/clash@user.service → /lib/systemd/system/clash@.service.