起因就是服务器(我使用的是腾讯云轻量应用服务器)访问GitHub太慢,即使在hosts文件添加了GitHub解析,下载速度也非常慢。我本地(mac)通过clash代理,访问GitHub较快并且稳定,于是想在服务器(Centos)上添加clash代理,一劳永逸解决问题。
1.下载客户端
wget https://github.com/Dreamacro/clash/releases/download/v0.15.0/clash-linux-amd64-v0.15.0.gz
如果服务器无法下载,可以在本地下载后,通过scp
命令上传至服务器。
2. 设置成服务
首先启动
clash
,会生成对应的配置文件config.yaml Country.mmdb
。将clash程序移动
/usr/local/bin/
,配置文件移动到/etc/clash/
。编写服务的配置。
vim /etc/systemd/system/clash.service
[Unit]
Description=Clash Daemon
[Service]
ExecStart=/usr/local/bin/clash -d /etc/clash/
Restart=on-failure
[Install]
WantedBy=multi-user.target
- 现在可以通过systemctl start clash`启动服务。(不用设置为开机启动,否则网络会很卡)
3. 导出clash配置文件
从你购买科学上网流量的网站导出对应文件,然后替换掉config.yaml。有少量需要修改的地方,参考我的配置文件。
mixed-port: 7890
socks-port: 7891
allow-lan: true
mode: rule
log-level: info
external-controller: '0.0.0.0:9090'
external-ui: dashboard
secret: xxx ##clash面板的密码
enhanced-mode: fake-ip
4. 修改系统代理
在.zshrc添加如下代码,以后可以通过proxy_on和proxy_off开关代理。
function proxy_off() {
unset http_proxy
unset https_proxy
unset no_proxy
echo -e "Proxy Off"
}
function proxy_on(){
export http_proxy="http://127.0.0.1:7890"
export https_proxy=$http_proxy
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
echo -e "Proxy On"
}
5.添加clash面板
- 下载面板文件。注意将面板文件移动到
/etc/clash/
。cd /etc/clash
wget https://github.com/haishanh/yacd/archive/gh-pages.zip
unzip gh-pages.zip
mv yacd-gh-pages/ dashboard/
- 访问
http://ip:9090/ui
。
Comments