[i=s] 本帖最后由 baiy316 于 2025-1-7 11:06 编辑 [/i]<br />
<br />
一、前言
首先感谢 windowbr 大佬提供的教程。大佬的教程里mihomo的部分是通过页面安装,无法使用 TUN 模式来接管所有设备流量。MetaCubeX/metacubexd 的讨论区有帖子compose安装mihomo的方法,因此汇总整理方便记忆。
二、准备工作
1、拉取mihomo镜像

2、准备config.yaml文件
创建config.yaml文件,粘贴下方代码;在proxy-providers处替换自己的订阅名称、链接、前缀<记得删括号!>
(再次感谢 windowbr 大佬提供的模板,yaml文件我完全不懂,还好大佬提供的模板非常便捷)
mixed-port: 7890
allow-lan: true
bind-address: '*'
mode: rule
log-level: info
external-controller: '0.0.0.0:9090'
tun:
enable: true
stack: mixed
dns-hijack:
- "any:53"
- "tcp://any:53"
auto-route: true
auto-redirect: true
auto-detect-interface: true
proxy-providers:
<节点提供者名称,记得删括号>:
url: "<节点订阅链接,记得删括号>"
type: http
interval: 86400
health-check: {enable: true,url: "https://www.gstatic.com/generate_204", interval: 300}
override:
additional-prefix: "<节点名称前缀,记得删括号>"
proxies:
- name: "直连"
type: direct
udp: true
geodata-mode: true
geox-url:
geoip: "https://**ror.ghproxy.com/https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip-lite.dat"
geosite: "https://**ror.ghproxy.com/https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat"
mmdb: "https://**ror.ghproxy.com/https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country-lite.mmdb"
asn: "https://**ror.ghproxy.com/https://github.com/xishang0128/geoip/releases/download/latest/GeoLite2-ASN.mmdb"
dns:
enable: true
ipv6: true
respect-rules: true
enhanced-mode: fake-ip
fake-ip-filter:
- "*"
- "+.lan"
- "+.local"
- "+.**.xiaomi.com"
nameserver:
- https://120.53.53.53/dns-query
- https://223.5.5.5/dns-query
proxy-server-nameserver:
- https://120.53.53.53/dns-query
- https://223.5.5.5/dns-query
nameserver-policy:
"geosite:cn,private":
- https://120.53.53.53/dns-query
- https://223.5.5.5/dns-query
"geosite:geolocation-!cn":
- "https://dns.cloudflare.com/dns-query"
- "https://dns.google/dns-query"
proxy-groups:
- name: 默认
type: select
proxies: [自动选择,直连,**,**,日本,新加坡,美国,其它地区,全部节点]
- name: Google
type: select
proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Telegram
type: select
proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Twitter
type: select
proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 哔哩哔哩
type: select
proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 巴哈姆特
type: select
proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: **
type: select
proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: NETFLIX
type: select
proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Spotify
type: select
proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: Github
type: select
proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
- name: 国内
type: select
proxies: [直连,默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择]
- name: 其他
type: select
proxies: [默认,**,**,日本,新加坡,美国,其它地区,全部节点,自动选择,直连]
#分隔,下面是地区分组
- name: **
type: select
include-all: true
filter: "(?i)港|hk|hongkong|hong kong"
- name: **
type: select
include-all: true
filter: "(?i)台|tw|**"
- name: 日本
type: select
include-all: true
filter: "(?i)日|jp|japan"
- name: 美国
type: select
include-all: true
filter: "(?i)美|us|unitedstates|united states"
- name: 新加坡
type: select
include-all: true
filter: "(?i)(新|sg|singapore)"
- name: 其它地区
type: select
include-all: true
filter: "(?i)^(?!.*(?:🇭🇰|🇯🇵|🇺🇸|🇸🇬|🇨🇳|港|hk|hongkong|台|tw|**|日|jp|japan|新|sg|singapore|美|us|unitedstates)).*"
- name: 全部节点
type: select
include-all: true
- name: 自动选择
type: url-test
include-all: true
tolerance: 10
rules:
- GEOIP,lan,直连,no-resolve
- GEOSITE,github,Github
- GEOSITE,twitter,Twitter
- GEOSITE,**,**
- GEOSITE,google,Google
- GEOSITE,telegram,Telegram
- GEOSITE,netflix,NETFLIX
- GEOSITE,bilibili,哔哩哔哩
- GEOSITE,bahamut,巴哈姆特
- GEOSITE,spotify,Spotify
- GEOSITE,CN,国内
- GEOSITE,geolocation-!cn,其他
- GEOIP,google,Google
- GEOIP,netflix,NETFLIX
- GEOIP,telegram,Telegram
- GEOIP,twitter,Twitter
- GEOIP,CN,国内
- MATCH,其他
3、下载文件
从 该仓库 下载:GeoIP.dat、geoid.metadb、geosite.dat三个文件;
将下载的三个文件以及config.yaml文件放进任意目录中(例:/vol1/1000/docker/mihomo)
至此所有准备工作全部完成。
三、安装
1、打开docker-compose,点击新增项目

2、项目名称可以随意填写;路径填写保存yml文件的目录;来源选择创建

3、在文本框内粘贴下方代码
# version: '3'
services:
mihomo:
container_name: mihomo
image: metacubex/mihomo
restart: always
pid: host
ipc: host
network_mode: host
cap_add:
- ALL
security_opt:
- apparmor=unconfined
volumes:
- /vol1/1000/docker/mihomo:/root/.config/mihomo
- /dev/net/tun:/dev/net/tun
# 共享host的时间环境
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
metacubexd:
container_name: metacubexd
image: ghcr.io/metacubex/metacubexd
restart: always
network_mode: bridge
ports:
- '9097:80'
volumes:
- /vol1/1000/docker/mihomo/metacubexd:/config/caddy
# 共享host的时间环境
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
其中:
/vol1/1000/docker/mihomo 需要保持与第二节第3点的目录一致
/vol1/1000/docker/mihomo/metacubexd 是metacube的配置目录
倒数第五行的 9097 是web访问端口,可随意修改
四、使用
浏览器地址栏输入 "IP:9097",可访问metacube(XD)管理界面,后端地址填写 "http://设备IP:9090",密钥为空即可。