Loading... 如果在线下载文件失效请,直接网盘下载,我放到下面了。 <div class="hideContent">此处内容需要评论回复后(审核通过)方可阅读。</div> ## 1.安装 Clash 1.下载当前操作系统与 CPU 架构对应的包文件,我用的是 `X86_64` 平台下 Ubuntu 22.04 LTS 所以对应的使用 [clash-linux-amd64-v1.11.12.gz](https://github.com/Dreamacro/clash/releases/download/v1.11.12/clash-linux-amd64-v1.11.12.gz) 包即可 ```bash wget https://github.com/Dreamacro/clash/releases/download/v1.11.12/clash-linux-amd64-v1.11.12.gz ``` 2.下载好后解压安装包中 clash 到 `/usr/local/bin/` 目录下,并删除压缩包文件 ```bash gzip -dc clash-linux-amd64-v1.11.12.gz > /usr/local/bin/clash chmod +x /usr/local/bin/clash rm -f clash-linux-amd64-v1.11.12.gz ``` 3.创建配置文件目录,并下载 MMDB 文件 ```bash mkdir /etc/clash wget -O /etc/clash/Country.mmdb https://www.sub-speeder.com/client-download/Country.mmdb ``` 4.创建 `systemd` 脚本,脚本文件路径为 `/etc/systemd/system/clash.service`,内容如下: ```bash vim /etc/systemd/system/clash.service ``` ```bash [Unit] Description=clash daemon [Service] Type=simple User=root ExecStart=/usr/local/bin/clash -d /etc/clash/ Restart=on-failure [Install] WantedBy=multi-user.target ``` 5.重载 `systemctl daemon` ```bash systemctl daemon-reload ``` ## 2.配置代理上网 1.导入已有的科学上网`订阅链接` ```bash wget -O /etc/clash/config.yaml [你的订阅链接] ``` 注意这里查看一下config.yaml是不是yaml格式如果不是,那么你需要使用其他工具导入然后查看yaml配置,然后吧config.yaml配置放到我们`/etc/clash/config.yaml`路径下。我这里遇到的问题就是config.yaml不是yaml格式,而是一串很长的字符。 我的解决方式是先导入到clash for window,再复制config.yaml粘贴到`/etc/clash/config.yaml`。 ![](https://blog.fivk.cn/usr/uploads/2023/11/3147127617.png) 2.设置系统代理,添加配置文件 `/etc/profile.d/proxy.sh` 并在其中写入如下内容: ```bash vim /etc/profile.d/proxy.sh ``` ```bash export http_proxy="127.0.0.1:7890" export https_proxy="127.0.0.1:7890" export no_proxy="localhost, 127.0.0.1" ``` 3.重载 `/etc/profile` 配置 ```bash source /etc/profile ``` 4. `clash` 服务命令 ```bash # 启动 systemctl start clash # 启动并开机自启 systemctl enable clash # 查看clash状态 systemctl status clash # 停止 systemctl stop clash # 重启 systemctl restart clash ``` 5.测试 `goolge.com` 访问 ```bash # curl google.com <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="http://www.google.com/">here</A>. </BODY></HTML> ``` ## 3.配置 yacd dashboard 1. 下载yacd dashboard项目到本地 ```bash wget https://github.com/haishanh/yacd/releases/download/v0.3.8/yacd.tar.xz -O /opt/dashboard ``` 2.修改 `clash` 配置文件中 `external-ui` 的值为 `/opt/clash-dashboard` ```bash sed -i "s/^#\{0,1\} \{0,1\}external-ui.*/external-ui: \/opt\/dashboard/" /etc/clash/config.yaml ``` 或者手动添加 ```yaml port: 7890 socks-port: 7891 allow-lan: true mode: Rule log-level: info secert: 123456 # 增加这一行, 如果你希望你的clash web要密码访问可以在这块配置密码, 如果不需要直接注释掉即可 external-ui: /opt/dashboard # 增加这一行 external-controller: 0.0.0.0:9090 ``` 3.停止`clash` 服务 ```bash systemctl stop clash ``` 4.接下来验证你的操作是否有效可以执行 ```bash ./clash -d . ``` ## 4.配置定时更新订阅 使用如下脚本填写相关配置项目并放入 `/etc/cron.weekly` 目录下,每周自动更新订阅配置文件即可 ```bash vim /etc/cron.weekly/clash.sh ``` ```bash #!/usr/bin/env bash SUBSCRIBE="" WEB_UI="" CONTROLLER_API_PROT="" SECRET="" CLASH_CONFIG="/etc/clash/config.yaml" if [ -z "${SUBSCRIBE}" ]; then echo "Subscription address cannot be empty" exit 1 fi systemctl stop clash wget --no-proxy -O ${CLASH_CONFIG} ${SUBSCRIBE} if [ -n "${WEB_UI}" ]; then sed -i "s?^#\{0,1\} \{0,1\}external-ui.*?external-ui: ${WEB_UI}?" ${CLASH_CONFIG} fi if [ -n "${CONTROLLER_API_PROT}" ]; then sed -i "s?^external-controller.*?external-controller: '0.0.0.0:${CONTROLLER_API_PROT}'?" ${CLASH_CONFIG} fi if [ -n "${SECRET}" ]; then sed -i "s?^secret.*?secret: '${SECRET}'?" ${CLASH_CONFIG} fi systemctl start clash ``` 上述脚本写入 `/etc/cron.weekly/clash.sh` 并配置好相关变量后,保存退出并赋予可执行权限 ```bash chmod 0755 /etc/cron.weekly/clash.sh ``` 至此,`Linux` 下 `clash` 配置完成,可以愉快的上外网拉包了 最后修改:2024 年 01 月 08 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏
10 条评论
您好,wget https://github.com/Dreamacro/clash/releases/download/v1.11.12/clash-linux-amd64-v1.11.12.gz
这个链接下的文件不存在了,好像仓库不公开了,请问怎么获取这个文件(╯°A°)╯
你是从那里找到我的博客的ヾ(≧∇≦*)ゝ
哈哈我在谷歌搜索“ubuntu运行clash”,然后时间设置成一周内就搜到了
好兄弟特意为了你去上传了一下,好像也被封了,还好我本地存储了一份,这应该是被封前最新版本了
链接:https://pan.baidu.com/s/1DW0bodIf2lboHVBE1NSp-Q
提取码:fivk
woc感动...但这个百度云链接也被封了OωO,要不发邮箱?weijieyue@outlook.com
更新到正文了,你刷新就能看到了
看到啦,提取到123网盘了,但压缩包的解压密码好像不对,不是122333
好兄弟重新上传了![](https://blog.fivk.cn/usr/themes/handsome/assets/img/emotion/aru/cryingface.png)
ok了没问题 谢谢兄弟 配置好了
好像确实是,奇怪