一世贪欢的私域

一世贪欢的私域

部署 mihomo

2025-10-01
部署 mihomo

部署mihimo

2025年10月23日修复失效的下载连接,因为之前Openlist链接中携带Github.com被Google封了域名,打开后直接全屏红色。

一、介绍

clash core 的衍生。新的代理内核。

mihomo官方仓库

二、环境准备

三、安装及部署

3.1 安装

3.1.1 debian系安装

  1. 下载
wget https://drive.bravexist.cn/d/gh/mihomo/v1.19.14/mihomo-linux-amd64-v3-v1.19.14.deb
  1. 安装
dpkg -i mihomo-linux-amd64-v3-v1.19.14.deb

3.1.2 redhat系安装

  1. 下载
wget https://drive.bravexist.cn/d/gh/mihomo/v1.19.14/mihomo-linux-amd64-v3-v1.19.14.rpm
  1. 安装
rpm -ivh mihomo-linux-amd64-v3-v1.19.14.rpm

3.1.3 通用安装(手动安装)

  1. 下载
  • amd64通用包(amd机器)
wget https://drive.bravexist.cn/d/gh/mihomo/v1.19.14/mihomo-linux-amd64-v3-v1.19.14.gz
  • arm64通用包
wget https://drive.bravexist.cn/d/gh/mihomo/v1.19.14/mihomo-linux-arm64-v1.19.14.gz
  1. 解压,之后以amd架构为例
gzip -d mihomo-linux-amd64-v3-v1.19.14.gz
  1. 重命名
mv mihomo-linux-amd64-v3-v1.19.14 mihomo
  1. 移动
mv mihomo /usr/bin/mihomo
  1. 添加可执行权限
chmod +x /usr/bin/mihomo
  1. 注册成服务
cat > /etc/systemd/system/mihomo.service << EOF
[Unit]
Description=Mihomo Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/mihomo -d /etc/mihomo
WorkingDirectory=/etc/mihomo
Restart=on-failure
User=root

[Install]
WantedBy=multi-user.target
EOF
  1. 下载 Country.mmdb
wget -O /etc/mihomo/Country.mmdb https://drive.bravexist.cn/d/gh/maxmind-geoip/20250912/Country.mmdb
  1. 创建工作目录
mkdir /etc/mihomo
  1. 重载systemd并启动服务
# 重新加载 systemd 配置
sudo systemctl daemon-reload

# 启动服务
sudo systemctl start mihomo.service

# 查看状态
sudo systemctl status mihomo.service

# 设置开机自启
sudo systemctl enable mihomo.service

3.2 配置

  1. 下载订阅文件到 /etc/mihomo ,并重命名为 config.yaml
wget -O /etc/mihomo/config.yaml 订阅链接

我的订阅链接

wget -O /etc/mihomo/config.yaml https://bravexist.cn/clash.gw
  1. 启动
systemctl --now enable mihomo.service
  1. 验证服务是否启动
systemctl status mihomo.service
netstat -tnlp | grep 789
  1. 验证代理是否成功
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
export all_proxy=http://127.0.0.1:7891
set |grep proxy
curl https://www.google.com

四、使用

4.1 设置代理密码

开启代理密码、放境内公网机器必须开密码;允许局域网访问。

http

port: 7890
authentication:
  - "username:password"
  - "username1:password1"

socks

socks-port: 7891
login:
  - "username:password"
  - "username2:password2"

allow-lan

allow-lan: true

4.2 使用代理

http

export http_proxy=http://username:password@127.0.0.1:7890
export https_proxy=http://username:password@127.0.0.1:7890

socks

export ALL_PROXY=socks5://username:password@127.0.0.1:7891

4.3 脚本化

  1. 通过 user.password文件,自动更新脚本。添加http、socks代理
  • user.password
http=username:password
http=username1:password1
socks=username:password
socks=username2:password2
  • update_config.sh
#!/bin/bash

CONFIG_FILE="/etc/mihomo/config.yaml"
PASSWORD_FILE="/etc/mihomo/user.password"
REMOTE_URL="https://bravexist.cn/clash.gw"

# 下载远程配置
curl -s "$REMOTE_URL" -o "$CONFIG_FILE"

# 读取密码
HTTP_AUTH=()
SOCKS_AUTH=()
while IFS='=' read -r type cred; do
  case "$type" in
    http) HTTP_AUTH+=("\"$cred\"") ;;
    socks) SOCKS_AUTH+=("\"$cred\"") ;;
  esac
done < "$PASSWORD_FILE"

# 删除旧的 authentication 和 login
sed -i '/^authentication:/,/^[^ ]/d' "$CONFIG_FILE"
sed -i '/^login:/,/^[^ ]/d' "$CONFIG_FILE"

# 在 port: 行后添加 authentication
if [ ${#HTTP_AUTH[@]} -gt 0 ]; then
  awk -v auths="${HTTP_AUTH[*]}" '
    /^port:/ {
      print
      split(auths, a, " ")
      print "authentication:"
      for(i in a) print "  - " a[i]
      next
    }1' "$CONFIG_FILE" > tmp.yaml && mv tmp.yaml "$CONFIG_FILE"
fi

# 在 socks-port: 行后添加 login
if [ ${#SOCKS_AUTH[@]} -gt 0 ]; then
  awk -v logins="${SOCKS_AUTH[*]}" '
    /^socks-port:/ {
      print
      split(logins, l, " ")
      print "login:"
      for(i in l) print "  - " l[i]
      next
    }1' "$CONFIG_FILE" > tmp.yaml && mv tmp.yaml "$CONFIG_FILE"
fi

# 修改 allow-lan 为 true
if grep -q '^allow-lan:' "$CONFIG_FILE"; then
  sed -i 's/^allow-lan:.*/allow-lan: true/' "$CONFIG_FILE"
else
  echo "allow-lan: true" >> "$CONFIG_FILE"
fi

echo "配置更新完成 ✅"

systemctl reload mihomo.service

echo "重载配置完成"
  1. 配置定时任务。
crontab -e
0 * * * * /bin/bash /etc/mihomo/update_config.sh &> /dev/null

4.4 在线脚本

wget -O /etc/mihomo/update_config.sh https://drive.bravexist.cn/d/scripts/mihomoScripts/update_config.sh
chmod +x /etc/mihomo/update_config.sh

wget -O /etc/mihomo/user.password https://drive.bravexist.cn/d/scripts/mihomoScripts/user.password

/etc/mihomo/update_config.sh

五、ALL IN

管那么多干嘛,一行梭哈就是了。

  • 用 curl
bash <(curl -sSL https://drive.bravexist.cn/d/scripts/mihomoScripts/install_mihomo_amd.sh)
  • wget
bash <(wget -qO- https://drive.bravexist.cn/d/scripts/mihomoScripts/install_mihomo_amd.sh)

卸载

rm -rf /etc/mihomo/ /usr/bin/mihomo /etc/systemd/system/mihomo.service

六、封面图

封面图