直接安装clash

clash网址:Releases · Dreamacro/clash (github.com)。树莓派4B对应的是armv7。

1
wget https://github.com/Dreamacro/clash/releases/download/v1.4.2/clash-linux-armv7-v1.4.2.gz
  1. 安装clash

    1
    2
    3
    4
    5
    6
    //解压并移动到合适的文件夹
    gzip clash-linux-armv7-v1.4.2.gz -d /usr/local/bin/clash
    //如果下载的是二进制文件直接移动
    sudo mv clash-linux-armv7-vv1.4.2 /usr/local/bin/clash
    //权限
    sudo chmod a+x /usr/local/bin/clash
  2. 运行并配置clash

    1. cd到某个你喜欢的位置
    2. 添加配置文件.(配置文件可以直接从mac中复制过去)
    3. 执行命令clash
  3. 测试:

    1
    2
    3
    4
    5
    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"

    curl google.com
  4. 配置系统代理(本机可以跳过)

    1
    2
    cd /etc/apt/apt.conf.d
    vim proxy

    代理的格式:

    1
    2
    3
    4
    //无密码:
    Acquire::http::Proxy "http://192.168.2.107:9090";
    //有密码:
    Acquire::http::Proxy "http://admin:123456@192.168.2.107:9090";

    修改后保存退出,重启clash看看能不能使用。

  5. 配置ui,暂且配置一个方便的

    1
    2
    3
    git clone https://github.com/Dreamacro/clash-dashboard.git
    cd clash-dashboard
    git checkout -b gh-pages origin/gh-pages

    修改配置信息:

    1. 将config.ymal文件中external-controller修改为127.0.0.1或0.0.0.0,并修改密码.如果想要外部访问,修改为对应的ip号码。比如192.168.2.107
    2. 添加配置external-ui: /home/pi/.config/clash/clash-dashboard
    3. 输入ip:9090,应该得到clash的欢迎信息
      我们可以通过访问:ip:9090/ui 去访问clash的控制网页了,另外代理服务也同时开始运行了。
      如果都可以那就大功告成了
  6. 开机自启动等(我觉得没必要,我直接挂screen后台运行即可)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    sudo vi /etc/systemd/system/clash.service

    //修改配置
    [Unit]
    Description=Clash Service
    After=network.target

    [Service]
    ExecStart=/usr/local/bin/clash -d /home/pi/app/clash
    Restart=on-abort
    LimitNOFILE=1048576

    [Install]
    WantedBy=multi-user.target

    开启开机自启动

    1
    2
    3
    systemctl start clash
    systemctl enable clash
    systemctl status clash

    检查无误即可。

    • 配置文件保存在pi/.config/clash而不是/pi/clash,不要改错了
    • 系统问题:只支持utf-8,中文备注也会报错,最好手动改一下配置,把奇怪的字符都删掉。
    • 记得修改配置文件的ip和端口号,我日常忘记改。
  7. 更新订阅

    1
    2
    sudo wget -O config.yaml [订阅链接]
    sudo wget -O Country.mmdb https://www.sub-speeder.com/client-download/Country.mmdb

使用docker

确保 allow-lan 的值为 trueexternal-controller 的值为 0.0.0.0:9090,否则搭起来也连不上。最后将这个文件重命名为 config.yaml

1
docker run -d --name=clash -v "$PWD/config.yaml:/root/.config/clash/config.yaml" -p "7890:7890" -p "9090:9090" --restart=unless-stopped dreamacro/clash