Appearance
AlmaLinux 安装 Mihomo
这篇文档面向有 Linux 基础的读者,覆盖 Mihomo 在 AlmaLinux 上的安装、配置、自启动与排错流程。
前置要求
- 已具备 root 权限或可用
sudo。 - 服务器可访问 GitHub Releases(或你自己的下载镜像)。
- 已明确代理配置来源(手写节点或订阅配置)。
1. 选择正确的 RPM 包
Mihomo Releases:
text
https://github.com/MetaCubeX/mihomo/releasesAlmaLinux 属于 RHEL 系,安装包优先选择 .rpm。
常见选择策略:
- 普通 x86_64/amd64 服务器:
mihomo-linux-amd64*.rpm - 不确定 CPU 指令集时:优先普通 amd64,不要先选
v2/v3
不要选:
*.deb(Debian/Ubuntu)*.pkg.tar.zst(Arch)*v3*(需要 AVX2,部分 VPS 不支持)
2. 安装 Mihomo
下载 RPM 后进入文件目录安装:
bash
cd /root
dnf install -y ./mihomo-linux-amd64*.rpm验证安装结果:
bash
mihomo -v
which mihomo常见安装路径为:
text
/usr/bin/mihomo3. 准备配置目录和配置文件
bash
mkdir -p /etc/mihomo
vi /etc/mihomo/config.yaml你可以使用订阅配置直接生成:
bash
curl -L -o /etc/mihomo/config.yaml "你的订阅链接"或使用最小结构示例(需自行补全节点与分组):
yaml
mixed-port: 7890
allow-lan: false
mode: rule
log-level: info
external-controller: 127.0.0.1:9090
dns:
enable: true
listen: 127.0.0.1:1053
enhanced-mode: fake-ip
nameserver:
- 1.1.1.1
- 8.8.8.8
proxies:
# 在这里填写代理节点
proxy-groups:
# 在这里填写分组
rules:
- MATCH,DIRECT⚠️ 上述 YAML 只是结构示例。如果
proxies/proxy-groups为空,服务通常无法按预期启动。
⚠️
allow-lan: true会把代理端口暴露给局域网,请同时配置防火墙与访问控制。
4. 测试配置是否可用
bash
mihomo -d /etc/mihomo -t出现类似输出表示配置通过:
text
configuration file test is successful5. 配置 systemd 自启动
创建服务文件:
bash
vi /etc/systemd/system/mihomo.service写入以下内容:
ini
[Unit]
Description=Mihomo Proxy Service
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/mihomo -d /etc/mihomo
Restart=always
RestartSec=5
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target加载并启动:
bash
systemctl daemon-reload
systemctl enable mihomo
systemctl start mihomo查看状态与日志:
bash
systemctl status mihomo
journalctl -u mihomo -f6. 连通性测试
本机代理测试:
bash
curl -x http://127.0.0.1:7890 https://ipinfo.io返回公网 IP 信息通常表示代理已工作。
7. 常用运维命令
bash
systemctl start mihomo
systemctl stop mihomo
systemctl restart mihomo
systemctl status mihomo
journalctl -u mihomo -f8. 常见问题排查
8.1 服务启动失败
优先检查:
bash
mihomo -d /etc/mihomo -t
journalctl -u mihomo -n 100 --no-pager高频原因:
- YAML 缩进或语法错误。
proxies/proxy-groups未正确配置。- 端口被占用(如
7890或9090)。
8.2 开机未自动启动
检查服务是否已启用:
bash
systemctl is-enabled mihomo如返回 disabled,重新执行:
bash
systemctl enable mihomo8.3 配置更新后不生效
每次修改 config.yaml 后建议先测试,再重启服务:
bash
mihomo -d /etc/mihomo -t && systemctl restart mihomo