CentOS7配置Clash代理(docker)

clash 的 github 仓库已经挂掉了,作者删库了。只能找以前的版本还能继续用,找的过程中发现有打包好的 docker 版本,可以一键配置。

1
2
3
4
5
6
7
docker run -d \
--name clash \
--restart=always \
--log-opt max-size=1m \
-v /root/.config/clash/config.yaml:/root/.config/clash/config.yaml \
-p 7888:8080 -p 7890:7890 \
laoyutang/clash-and-dashboard:latest

需要把机场的 yaml 文件放到宿主机的/root/.config/clash/目录下,创建容器时挂载进去。
  运行成功后,访问宿主机7888端口即可进入 clash 控制面板,选择节点,开启代理。

  进入宿主机的~/.bashrc或者~/.zshrc

1
2
export http_proxy="http://127.0.0.1:7890"
export https_proxy="http://127.0.0.1:7890"

测试:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
☁  ~  curl -I https://www.google.com
HTTP/1.1 200 Connection established

HTTP/1.1 200 OK
Content-Type: text/html; charset=ISO-8859-1
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-AOy0_Lb_CokxfUGDy6DQ_g' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Date: Thu, 15 Feb 2024 04:54:50 GMT
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Transfer-Encoding: chunked
Expires: Thu, 15 Feb 2024 04:54:50 GMT
Cache-Control: private
Set-Cookie: 1P_JAR=2024-02-15-04; expires=Sat, 16-Mar-2024 04:54:50 GMT; path=/; domain=.google.com; Secure
Set-Cookie: AEC=Ae3NU9PkxZXsavIE1i87-bIS96xRW1GTL7sZcwHmIKL3WqKVCDteL_vKUbs; expires=Tue, 13-Aug-2024 04:54:50 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax
Set-Cookie: NID=511=svJ0Zakh7gQbZ_od1Mom5rEFyRtwmKP5na5-bwvWUu5Sced8AhXmC3hzJCyfmtPuwz0v9SIpeOJicYQdWneLn3wxffNoge90YzG6deCZlzpfGzBZEreX3AmxXpcym8lvyR7nkljLO02kefqX-oYlTSxjqPsOWPXIPrr3IkNzYiw; expires=Fri, 16-Aug-2024 04:54:50 GMT; path=/; domain=.google.com; HttpOnly
Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000

测试成功。然后配置一个自动任务进行定期更新机场 yaml 文件。

1
2
3
crontab -e
# 加入每日任务:更新机场文件,重启docker
0 0 * * 0 /usr/bin/curl -o /root/.config/clash/config.yaml 机场配置文件下载链接 && /usr/bin/docker restart clash

CentOS7配置Clash代理(docker)
http://sinlatansen.github.io/2024/02/15/CentOS7配置Clash代理(docker)/
作者
fugu
发布于
2024年2月15日
许可协议