在 Alpine Container 里使用 Mihomo

纯折腾

最近新版本 Debian 发布,所以各种东西全都重新来过。正好想到 Alpine 要求极低,所以魔法上网这件事儿就不想用 Debian 来做了(Debian 要 80MB 的镜像,但 Alpine 只要 4MB)。

下面记录一下过程。

创建 Container

在 PVE 里,正常创建一个 Alpine 的 Container(CT)。特权容器啊啥的似乎可以随意。

然后先不要开机,编辑一下 CT 的配置(/etc/pve/nodes/pve/lxc/xxx.conf),加入下面这些东西:

lxc.cgroup2.devices.allow: c 10:200 rwm
lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file

Container 设置

开启内核转发。在/etc/sysctl.conf 里面加入

net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1

    然后用下面这两句应用配置,并把 sysctl 加入开机启动

    sysctl -p
    rc-update add sysctl

    创建 Mihomo 服务

    编辑/etc/init.d/mihomo 文件:

    #!/sbin/openrc-run
    command="/usr/local/bin/mihomo"
    command_args="-d /etc/mihomo"
    command_background="yes"
    command_user="root"
    respawn="true"
    pidfile="/var/run/mihomo.pid"
    
    depend() {
        need net
    }

    然后同样用下面两句,加入自动启动

    chmod +x /etc/init.d/mihomo
    rc-update add mihomo default

    配置 Mihomo

    然后去下载 Mihomo 的最新版,解压缩到/usr/local/bin/mihomo

    最后把配置文件放在/etc/mihomo/config.yaml

    最最后,还可以提前把 geox 里面的东西手工下载一下,避免自动下载出错。也可以把 UI 给下载一下。