2024如何在在linux安装和使用clashMeta

  • ~1.91K 字
  • 0 次阅读 次阅读
  • 0 评论 条评论
  1. 1. 下载并安装clashMeta
  2. 2. 下载Country.mmdb
  3. 3. 上传配置文件
  4. 4. 启动
    1. 4.1. 直接启动
    2. 4.2. 后台启动
      1. 4.2.1. PM2
      2. 4.2.2. systemd 服务
  5. 5. 使用
  6. 6. 查看代理
  7. 7. 参考资料

本文介绍如何在centos安装clash然后加速github等下载,适用于各种linux操作系统(如Centos、Ubuntu,Debian)
2024 PS:由于原版clash已删库跑路,故换成clashMeta,使用无差别

下载并安装clashMeta

前往release 页面下载相应的版本,对于 Centos 一般使用 mihomo-linux-amd64-vx.x.x.gz 版本,如:

1
2
3
mkdir /root/clash
cd /root/clash
wget https://github.com/MetaCubeX/mihomo/releases/download/v1.18.5/mihomo-linux-amd64-v1.18.5.gz

然后使用 gzip 命令解压,并重命名为 clash:

1
2
3
4
5

gzip -d ./mihomo-linux-amd64-v1.18.5.gz
mv mihomo-linux-amd64-v1.18.5 clashMeta #重命名
chmod u+x clashMeta #赋权
./clashMeta # 执行一次初始化

下载Country.mmdb

点击这里下载所需文件

1
wget https://github.com/Dreamacro/maxmind-geoip/releases/download/20240612/Country.mmdb

上传配置文件

请自行准备配置文件config.yaml上传到/root/clash
如果需要协议转换请可以使用以下链接

1
https://api.meaqua.fun/sub?target=clash&url=你的订阅链接或vmess

启动

直接启动

1
/root/clash/clashMeta -d /root/clash # 说明:可运行clash文件 -d 配置存放路径

后台启动

我是使用pm2管理的,所以需要安装nodejs

PM2

1
2
3
4
5
6
7
8
9
1、下载nvm脚本:wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh
2、重启:reboot
3、安装:nvm install --lts
4、安装pm2:npm install pm2 -g
5、启动:
pm2 start "/root/clash/clashMeta -d /root/clash" --name clash
pm2 save
pm2 startup
systemctl enable pm2-root

systemd 服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
sudo vim /etc/systemd/system/clashMeta.service
填入以下内容:
[Unit]
Description=ClashMeta daemon
After=network.target

[Service]
Type=simple
Restart=always
ExecStart=/root/clashMeta -d /root/clash #前面为clash路径 后面接配置路径

[Install]
WantedBy=multi-user.target

保存后执行:sudo systemctl start clashMeta启动
其他命令:
sudo systemctl enable clashMeta # 开机启动
sudo systemctl disable clashMeta # 禁用开机启动
sudo systemctl status clashMeta # 查询状态
sudo journalctl -xe # 日志

使用

临时设置:

1
2
3
4
5
export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
取消:
unset http_proxy https_proxy all_proxy
对于某些ip或域名可以设置不走代理,可以这样设置:
export no_proxy=127.0.0.1,.devops.com,localhost,local,.local,172.28.0.0/16

永久设置(开机自动设置):

1
2
vim ~/.bashrc
在最后一行添加上述export

查看代理

env|grep -i proxy

参考资料

在 Linux 中使用 Clash

打赏
打赏提示信息
分享
分享提示信息