【Clash】CentOS9安装部署Clash

下载Clash CLI

打开Mihomo / Clash Release 页面

下载 Linux CLI 版本 .gz 文件,例如:

mihomo-linux-amd64-v1-v1.19.18.gz

在 Mac 上解压:

1
2
cd ~/Downloads
gunzip mihomo-linux-amd64-v1-v1.19.18.gz

检查可执行性

1
2
3
file mihomo-linux-amd64-v1-v1.19.18
# 输出应为:
# ELF 64-bit LSB executable, x86-64, statically linked, stripped

可选:重命名为 clash,便于管理:

1
mv mihomo-linux-amd64-v1-v1.19.18 clash

上传到CentOS9服务器

创建目录

1
mkdir -p /opt/clash

上传可执行文件

1
scp ~/Downloads/clash root@10.10.xx.xx:/opt/clash/clash

授权可执行:

1
chmod +x /opt/clash/clash

准备配置文件(机场订阅)

在内网服务器创建配置目录:

1
mkdir -p /root/.config/mihomo

上传机场订阅yaml文件

1
scp ~/Downloads/config.yaml root@10.10.xx.xx:/root/.config/mihomo/config.yaml

启动 Clash CLI

1
/opt/clash/clash -d /root/.config/mihomo

成功启动后,日志会显示:

1
2
Mixed(http+socks) proxy listening at: 127.0.0.1:7890
DNS server(UDP) listening at: 127.0.0.1:1053

解决 GeoIP / GeoSite 提示

首次启动可能看到:

1
Can't find MMDB, start download
  • 这是正常提示,Clash CLI 会生成本地 geoip.metadb,不影响代理使用
  • 可选:在有外网的 Mac 上下载 GeoIP/GeoSite .mmdb 文件,并上传到服务器 /root/.config/mihomo/,以完整支持 GEO 策略

设置系统代理

临时生效(当前 shell):

1
2
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890

永久生效(开机后自动生效):

1
sudo vim /etc/profile.d/clash.sh

内容:

1
2
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890

生效:

1
source /etc/profile

验证代理:

1
2
curl http://ip.sb
curl --socks5 127.0.0.1:7890 http://ip.sb

后台运行 & 开机自启

nohup 后台运行

1
2
nohup /opt/clash/clash -d /root/.config/mihomo > /root/clash.log 2>&1 &
tail -f /root/clash.log

systemd 服务(推荐)

创建服务文件 /etc/systemd/system/clash.service:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
[Unit]
Description=Clash Meta CLI
After=network.target

[Service]
Type=simple
ExecStart=/opt/clash/clash -d /root/.config/mihomo
Restart=on-failure
User=root
WorkingDirectory=/root/.config/mihomo

[Install]
WantedBy=multi-user.target

启动服务并开机自启:

1
2
3
4
sudo systemctl daemon-reload
sudo systemctl enable clash
sudo systemctl start clash
sudo systemctl status clash

查看实时日志:

1
journalctl -u clash -f
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计