在centos安装clash


本文介绍如何在centos安装clash然后加速github等下载

下载并安装clash

在 Clash release 页面下载相应的版本,对于 Centos 一般使用 clash-linux-amd64-vX.X.X.gz 版本:

1
wget https://github.com/Dreamacro/clash/releases/download/v1.11.4/clash-linux-amd64-v1.11.4.gz

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

1
2
3
4
gzip -d ./clash-linux-amd64-v1.11.4.gz
mv clash-linux-amd64-v1.11.4 clash #重命名
chmod u+x clash #赋权
./clash # 执行一次初始化

下载Country.mmdb

点击这里下载所需文件

1
2
cd /root/.config/clash
wget https://github.com/Dreamacro/maxmind-geoip/releases/download/20220612/Country.mmdb

上传配置文件

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

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

启动

这里使用pm2挂后台,所以需要安装nodejs

安装nodejs

1
wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh

重启

1
nvm install stable
1
npm install pm2 -g

启动

1
2
3
4
pm2 start ./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
sudo vim /etc/systemd/system/clash.service
填入以下内容:
[Unit]
Description=Clash daemon, A rule-based proxy in Go.
After=network.target

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

[Install]
WantedBy=multi-user.target

使用 systemctl

1
2
3
4
5
sudo systemctl enable clash # 开机启动
sudo systemctl disable clash # 禁用开机启动
sudo systemctl start clash # 启动
sudo systemctl status clash # 查询状态
sudo journalctl -xe # 日志

pm2安装教程请自行搜索,实在不行请搜索其他教程

使用代理

临时设置:

1
2
3
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

永久设置:

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

参考资料

在 Linux 中使用 Clash