Windows 配置 mihomo

https://github.com/MetaCubeX/mihomo/releases 下载mihomo,选择Latest版本里的 mihomo-linux-amd64-compatible-版本号.gz

https://github.com/winsw/winsw/releases 下载WinSW,选择Latest版本里的 WinSW-x64.exe

mihomo安装于C:\mihomo 目录,先创建此文件夹。

mihomo-linux-amd64-compatible-版本号.gz解压,解压后将mihomo-windows-amd64-compatible.exe改命为mihomo.exe,并移动到C:\mihomo目录。

C:\mihomo目录创建clash配置文件config.yaml,内容如下:

ipv6: false
external-controller: 0.0.0.0:9090
external-ui: ui
geodata-mode: true  # 开启 dat 模式 面板可显示规则数量
geo-auto-update: true
geo-update-interval: 24
geox-url:
  geoip: "https://fastly.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geoip-lite.dat"  # lite 版本 GEOIP 体积小
tun:
  enable: true
  auto-route: true
  auto-detect-interface: true
  strict-route: true
  stack: system
  dns-hijack:
    - 0.0.0.0:53
dns:
  enable: true
  listen: 0.0.0.0:53
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  fake-ip-filter:
    - '*.lan'
    - localhost.ptlogin2.qq.com
    - +.msftconnecttest.com
    - +.msftncsi.com
  nameserver:
    - system  # 调用系统 DNS 兼容性和速度最佳
proxies:
  - 代理A
  - 代理B

# ========== Proxy Groups ==========
proxy-groups:
  - name: "PROXY"
    type: select
    proxies:
      - "代理A"
      - "代理B"
      - DIRECT
rule-providers:
  global:
    type: http
    path: ./global.yaml
    url: "https://fastly.jsdelivr.net/gh/ACL4SSR/ACL4SSR@master/Clash/Providers/ProxyLite.yaml"
    interval: 86400
    proxy: DIRECT
    behavior: classical
    format: yaml
  china:
    type: http
    path: ./china.yaml
    url: "https://fastly.jsdelivr.net/gh/ACL4SSR/ACL4SSR@master/Clash/Providers/ChinaDomain.yaml"
    interval: 86400
    proxy: DIRECT
    behavior: classical
    format: yaml
rules:
  - GEOIP,private,DIRECT,no-resolve  # GEOIP 规则前加入 no-resolve 不提前解析 DNS
  - RULE-SET,global,PROXY,no-resolve
  - RULE-SET,china,DIRECT,no-resolve
  - GEOIP,cn,DIRECT
  - MATCH,PROXY

WinSW-x64.exe移动到C:\mihomo目录,重命名为mihomo-service.exe

C:\mihomo目录创建WinSW配置文件mihomo-service.xml,内容如下:

<service>
  <!-- 服务基础信息 -->
  <id>mihomo</id>
  <name>mihomo</name>
  <description>MetaCubeX mihomo service (run: mihomo.exe -f config.yaml)</description>

  <!-- 运行程序 -->
  <executable>%BASE%\mihomo.exe</executable>
  <arguments>-f "%BASE%\config.yaml"</arguments>

  <!-- 工作目录 -->
  <workingdirectory>%BASE%</workingdirectory>

  <!-- 日志目录 -->
  <logpath>%BASE%\logs</logpath>

  <!-- 输出日志 -->
  <log mode="roll-by-size">
    <sizeThreshold>10485760</sizeThreshold> <!-- 10MB -->
    <keepFiles>10</keepFiles>
  </log>

  <!-- 崩溃/退出自动拉起 -->
  <onfailure action="restart" delay="5 sec"/>

  <!-- 优雅停止:发送 Ctrl+C -->
  <stopparentprocessfirst>true</stopparentprocessfirst>
  <stoptimeout>10 sec</stoptimeout>

  <!-- 以自动启动运行 -->
  <startmode>Automatic</startmode>

</service>

以管理员身份运行CMD,cd到C:\mihomo目录,运行mihomo-service install mihomo-service.xml

至此,Windows服务中就有了mihomo,运行服务后,浏览器访问 http://127.0.0.1:9090/ui 是管理UI。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注