Linux中使用clash代理
- 你需要访问github
1. 下载软件
这里使用的是Clash Meta
发现有很多版本,需要找到对应版本(通常是amd64)
1
uname -m
输出:
x86_64
:表示 64 位 CPU 架构(适合amd64
)。i386
或i686
:表示 32 位 CPU 架构(适合386
)。arm*
:表示 ARM 架构:
发现还有别的版本:
- 普通版本:适合大多数现代系统,推荐首先尝试此版本。
go120
版本:使用 Go 1.20 编译的版本。如果你的系统有更高的要求(如高性能需求),可以选择这个版本。compatible
版本:提供对旧系统或依赖的兼容性支持。如果普通版本运行报错,可以尝试这个版本。
这里选择普通版本:
2. 运行
1 | gzip -d mihomo-linux-amd64-v1.19.1.gz #解压gz文件,注意文件名 |
出现错误:
1
2ERRO[2025-01-25T23:19:50.495547417-08:00] can't initial GeoIP: can't download MMDB: Get "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb": EOF
FATA[2025-01-25T23:19:50.495820572-08:00] Parse config error: rules[1475] [GEOIP,CN,DIRECT] error: can't download MMDB: Get "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb": EOF手动下载该文件,下载geoip.metadb放到
/opt/clash/conf
中再次运行即可:
1
./mihomo-linux-amd64-v1.19.1 -d ./conf
在终端设置代理
1
2export ALL_PROXY="http://127.0.0.1:7890"
curl huggingface.co #测试代理发现测试不成功(地址好像不对):
检查环境变量:
1
env | grep -i proxy
发现很多冲突的环境变量:
重新设置
1
2
3
4
5
6
7
8
9
10
11
12unset ALL_PROXY
unset all_proxy
unset HTTP_PROXY
unset http_proxy
unset HTTPS_PROXY
unset https_proxy
unset FTP_PROXY
unset ftp_proxy
unset NO_PROXY
unset no_proxy
unset all_PROXY
export ALL_PROXY="http://127.0.0.1:7890"
3. 创建服务
创建服务文件:
1
sudo vi /etc/systemd/system/clash.service
写入如下内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14[Unit]
Description=Clash Meta Proxy
After=network.target
[Service]
Type=simple
ExecStart=/opt/clash/mihomo-linux-amd64-v1.19.1 -d /opt/clash/conf
Restart=always
User=<用户名> #注意改成自己的用户名用户组
Group=<用户组>
LimitNOFILE=65535 # 设置文件描述符限制
[Install]
WantedBy=multi-user.target启动服务
1
2
3
4sudo systemctl daemon-reload #重新加载 Systemd 配置
sudo systemctl start clash #启动服务
sudo systemctl status clash #检查服务状态如果运行的时候发生
(code=exited, status=217/USER)
,可以看看是不是已经有了这个服务,先删除这个文件(/lib/systemd/system/clash.service
)停止服务
1
sudo systemctl stop clash
开机自启动
1
sudo systemctl enable clash
每次开机需要重新设置环境变量:
1
echo 'export ALL_PROXY=http://127.0.0.1:7890' >> ~/.bashrc #每次开启终端就会自动创建