前言:
跑过代码的小伙伴都知道,有时候需要使用实验室或者公司的服务器跑一些代码,就需要远程连接服务器使用。然而代码经常需要从huggingface等加载一些模型或者数据,就需要配置一个clash。但是服务器又不会给sudo权限,所以只能在个人空间下配置一个clash。
本文以Ubuntu为例在远程Linux服务器上配置Clash。
下载clash
从Releases · doreamon-design/clash上下载一个适合自己的版本,我这里下载的是clash_2.0.24_linux_amd64.tar.gz,然后上传到服务器上。
解压
1 2
| tar -xvf clash_2.0.24_linux_amd64.tar.gz
|
将可执行文件移动到本地bin目录
注:下边的 ~是代表个人空间的根目录,这个目录下正常是有.local和".config"文件夹的
1 2 3 4 5 6 7 8
| mkdir -p ~/.local/bin echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc source ~/.bashrc
mv clash ~/.local/bin/clash
chmod +x ~/.local/bin/clash
|
按照上面步骤操作完毕后,检验安装
配置clash
准备配置目录
安装clash完毕后,要进行代理的配置
1 2 3 4 5
| mkdir -p ~/.config/clash cd ~/.config/clash
curl -o ~/.config/clash/Country.mmdb https://cdn.jsdelivr.net/gh/Dreamacro/maxmind-geoip@release/Country.mmdb
|
如果下载mmdb文件遇到问题,可以本地下载后上传到~/.config/clash文件夹。
下载配置文件
如果本地有代理的配置文件直接上传到~/.config/clash文件夹并命名为config.yaml即可,如果没有也可以使用订阅连接下载
1
| curl -o config.yaml "你的订阅链接"
|
启动Clash
如果上述过程都没问题就可以运行了
1 2 3 4 5 6 7 8
| clash -d ~/.config/clash
nohup clash -d ~/.config/clash > ~/.config/clash/clash.log 2>&1 &
pkill -x clash
|
代理成功启动后,需要设置代理
1 2 3 4 5 6
| export http_proxy=http://127.0.0.1:7890 export https_proxy=http://127.0.0.1:7890
curl -I http://www.google.com
|
如果不想每次都使用都设置代理,将以下内容添加到~/.bashrc中
1 2 3 4 5 6 7 8 9
| export http_proxy=http://127.0.0.1:7890 export https_proxy=http://127.0.0.1:7890 export HTTP_PROXY=http://127.0.0.1:7890 export HTTPS_PROXY=http://127.0.0.1:7890
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com" export NO_PROXY="localhost,127.0.0.1,localaddress,.localdomain.com"
|
创建更便捷的管理脚本
创建启动脚本~/start_clash.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| #!/bin/bash CLASH_DIR="$HOME/.config/clash" LOG_FILE="$CLASH_DIR/clash.log"
if pgrep -x "clash" > /dev/null; then echo "Clash 已经在运行" exit 1 fi
echo "启动 Clash..." nohup clash -d "$CLASH_DIR" > "$LOG_FILE" 2>&1 & echo "Clash 已启动,日志文件: $LOG_FILE" echo "控制面板: http://clash.razord.top (设置外部控制地址: 127.0.0.1:9090)"
|
创建停止脚本~/stop_clash.sh
1 2
| pkill -x clash echo "Clash 已停止"
|