linux环境(rocky)搭建clash用于学研
1、安装clash无gui版本。
https://github.com/MetaCubeX/mihomo/releases下下载符合自己发行版本的压缩包,我下载的是
mihomo-linux-amd64-compatible-v1.19.14.gz,解压后文件mihomo-linux-amd64-compatible上传至源服务器目录/usr/local/bin/下 改名为clash-mate,
执行如下命令
chmod +x clash-mate
2、导入配置文件
创建文件夹 mkdir -p /root/clash-config,从github下载两个文件
https://github.com/MetaCubeX/meta-rules-dat/releases/latest/download/geoip.dat
https://github.com/MetaCubeX/meta-rules-dat/releases/latest/download/geosite.dat
放入 /root/clash-config下,
在 /root/clash-config下创建config.yaml,将自己的订阅地址的配置明文导入。
如下结构
/root/clash-config/
├── config.yaml
├── geoip.dat
└── geosite.dat
3、配置节点
编辑 config.yaml,proxies下是所有节点列表。
proxy-groups下查找type为select的配置,追加你要使用的节点比如selected: "你要使用的节点名称",整体如下
proxy-groups:
- { name: xx机场, type: select, proxies: [自动选择],selected: "你要使用的节点名称" }
保存 config.yaml
4、启动clash
任意目录下运行如下命令
clash-mate -d /root/clash-config 出现如下命令表示成功启动
INFO[2025-10-29T11:43:00.155812438+08:00] Start initial configuration in progress
INFO[2025-10-29T11:43:00.166024754+08:00] Geodata Loader mode: memconservative
INFO[2025-10-29T11:43:00.166041518+08:00] Geosite Matcher implementation: succinct
WARN[2025-10-29T11:43:00.166300090+08:00] replace fallback-filter.geosite with nameserver-policy, it will be removed in the future
INFO[2025-10-29T11:43:00.166312922+08:00] Load GeoSite rule: cn
INFO[2025-10-29T11:43:00.349694301+08:00] Load GeoSite rule: gfw
INFO[2025-10-29T11:43:00.360537067+08:00] Finished initial GeoSite rule gfw => dns.fallback-filter.geosite, records: 5855
INFO[2025-10-29T11:43:00.360645295+08:00] Initial configuration complete, total time: 204ms
INFO[2025-10-29T11:43:00.360853544+08:00] RESTful API listening at: 127.0.0.1:9090
INFO[2025-10-29T11:43:00.361724280+08:00] Sniffer is closed
INFO[2025-10-29T11:43:00.361731454+08:00] Use tcp concurrent
INFO[2025-10-29T11:43:00.361788824+08:00] Mixed(http+socks) proxy listening at: 127.0.0.1:7890
5、开启系统代理
#设置 HTTP 和 HTTPS 代理
当前会话开启:
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
永久设置(对所有用户有效):
echo "export http_proxy=http://127.0.0.1:7890" | sudo tee -a /etc/profile
echo "export https_proxy=http://127.0.0.1:7890" | sudo tee -a /etc/profile
#让配置立即生效
source /etc/profile
6、测试
curl https://www.google.com 成功访问即为成功。
curl -x http://127.0.0.1:7890 https://ipinfo.io可查看当前节点ip等信息。
7、配置开机自启动
创建服务nano /etc/systemd/system/clash-mate.service
复制如下内容:
[Unit]
Description=Clash-Mate Service
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/root/clash-config
ExecStart=clash-mate -d /root/clash-config
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
保存文件后重载:
systemctl daemon-reload
验证是否成功:
sudo systemctl start clash-mate
sudo systemctl status clash-mate
Active: active (running)即为服务可用。
设置开机自启:
systemctl enable clash-mate
注意:切记开启系统代理
- 本文标签: Linux
- 本文链接: https://www.kxop.top/article/49
- 版权声明: 本文由王开心原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权