Search Posts

群晖添加clash.meta到自启动设置系统代理并自动更新订阅

内容纲要

原来用的https://github.com/412999826/clash-synology 这个方案里面使用的https://github.com/Dreamacro/clash ,但是不支持vless
最后替换使用 https://github.com/MetaCubeX/Clash.Meta/releases 这个内核,不部分步骤参考上面的git clash-synology说明
下载群晖处理器版本的 我的是intel cpu就下的clash.meta-linux-amd64-alpha开头的

下载地址:

https://github.com/MetaCubeX/mihomo/releases/download/v1.16.0/clash.meta-linux-amd64-v1.16.0.gz

到这个版本后,作者Clash.Meta改为mihomo内核未测试请使用上面最后一个版本的链接下载

教程

群晖>> File Station >> homes目录新建文件夹clash(自己建其他文件夹也可以)
也可以使用root用户ssh(下面的终端操作 我全部用的root用户)

mkdir -p  /volume1/homes/clash

然后File Station上传文件到/volume1/homes/clash

cd /volume1/homes/clash
chmod +x clash.meta-linux-amd64
mv clash.meta-linux-amd64 /usr/bin/clash

下载订阅配置文件

这个自己的订阅地址下载
需要是元数据格式的,自己手动浏览器测试打开如果是加密的(例如返回dmxlc3M6Ly9kOTcwMzk3Yy0wNjMzLTQ2ZDUtODBkNy1lOGM……)
需要到https://nexconvert.com/ 转换一下地址再打开 显示明文了,再wget

wget -O  /volume1/homes/clash/config.yaml "https://xxxxxx.xxx/api/v1/client/subscribe?token=xxxxxx&flag=meta"

测试启动

/usr/bin/clash -d /volume1/homes/clash/

会返回 Can’t find MMDB
https://github.com/Dreamacro/maxmind-geoip/releases/ 下载最新的Country.mmdb
File Station上传文件到/volume1/homes/clash
再次测试启动

/usr/bin/clash -d /volume1/homes/clash/

输出

INFO[2023-09-19T11:13:04.871965167+08:00] Initial configuration complete, total time: 11ms 
INFO[2023-09-19T11:13:04.873115238+08:00] RESTful API listening at: 127.0.0.1:9090     
INFO[2023-09-19T11:13:04.908862291+08:00] Sniffer is closed                            
INFO[2023-09-19T11:13:04.909201547+08:00] Mixed(http+socks) proxy listening at: [::]:7890

就算启动成功了

群晖配置系统代理

控制面板>>网络>>常规>>代理服务器
填写127.0.0.1 端口7890
应用 然后 curl 谷歌有返回就成功了

然后终端CTRL+C停止服务添加自启动

添加自启动

Systemd 配置文件
启动vi编辑器

vi /etc/systemd/system/clash.service

按I进入编辑模式,键入以下内容(-d 后面键入clash配置文件目录)

[Unit]
Description=Clash daemon, A rule-based proxy in Go.
After=network.target

[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/clash -d /volume1/homes/clash

[Install]
WantedBy=multi-user.target

按ESC,键入:wq退出
运行clash

systemctl start clash
systemctl enable clash

自动更新订阅

添加脚本
vi /volume1/homes/clash/update-subscribe.sh
按insert然后粘贴以下内容
wget -O  /volume1/homes/clash/config.file "https://xxxxxx.xxx/api/v1/client/subscribe?token=xxxxxx&flag=meta"
#如果下载的配置文件不为空 重命名为config.yaml覆盖
if [ $(cat /volume1/homes/clash/config.file|grep 7890|wc -l) -gt 0    ];then
/bin/mv /volume1/homes/clash/config.file /volume1/homes/clash/config.yaml
systemctl restart clash
fi
添加定时任务
vim /etc/crontab

*/4每4小时更新一次 多久更新一次 自己定义…

* */4 * * * root /volume1/homes/clash/update-subscribe.sh >/dev/null 2>&1

大功告成

记录备忘

8 comments on 群晖添加clash.meta到自启动设置系统代理并自动更新订阅

  1. 大佬你好,我的群晖是DSM7.2的,按照你的方式添加自启动无效,每次开机都要手动shh:systemctl start clash才能启动服务,在日志中心也没有相关日志,尝试给予777权限和删除过clash.service,按流程再次从新创建clash.service也是一样问题,我的步骤和文件夹都是按照你的流程设置的,求解答,谢谢

      1. 感谢回复,使用ssh:root账户输入systemctl enable clash之后重启依然不能自动启动,而且以前可以输入systemctl start clash手动启动9090可以看到hello字样,现在显示无法显示此网站了,有时systemctl start clash后还会提示Warning: clash.service changed on disk. Run ‘systemctl daemon-reload’ to reload units.使用systemctl daemon-reload后依然无效,在资源管理进程中又能看到它的ID时启动状态,我要怎么样才能完整删除然后按流程从新在安装一遍,不想重装系统了

        1. 感谢感谢,上一条留言作废,是我的错误,自动脚本更新了config.ymal文件,external-controller: ‘127.0.0.1:9090’被引号标注了,我把引号删除就正常了,现在已经实现开机自动启动了,再次感谢

      2. 感谢感谢,上一条留言作废,是我的错误,自动脚本更新了config.ymal文件,external-controller: ‘127.0.0.1:9090’被引号标注了,我把引号删除就正常了,现在已经实现开机自动启动了,再次感谢

  2. 纯萌新,请教一下大佬。下载clash内核,deb,gz,rpm三种格式后缀都行吗?还是说是要解压好的,再上传到群晖?

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注