解决 unraid 关机重启后 zerotier 无法打开 Web UI 的方法

YeYo(博主) 随记杂谈评论362字数 3495阅读11分39秒阅读模式

前言

将 unraid 升级到 6.12.X 后,关机或重启 unraid 后 zerotier 就无法打开 Web UI 了,但是 Docker 加端口访问又是正常的,说明 zerotier 的网络通路是没问题的。查官方资料看到如下说明:

Network Improvements
We added a new section under Settings->Network Settings->Interface Extra, allowing users to define which interfaces the Unraid services use. By default, all standard interfaces with an IP address are included in the list of listening interfaces.文章源自《智享阁》智享阁-https://www.esnpc.com/solution-for-unraid-zerotier-unable-to-open-web-ui-after-shutdown-reboot/

The tunnels of the built-in WireGuard function of Unraid are automatically added or removed from the list when the Wireguard tunnels are activated or deactivated. The user may exclude these tunnels from the list of listening interfaces.文章源自《智享阁》智享阁-https://www.esnpc.com/solution-for-unraid-zerotier-unable-to-open-web-ui-after-shutdown-reboot/

To use the Tailscale or Zerotier interface, it is required to add the interface name or IP address of the communication to the list of included listening interfaces.文章源自《智享阁》智享阁-https://www.esnpc.com/solution-for-unraid-zerotier-unable-to-open-web-ui-after-shutdown-reboot/

Important: It is imperative that Tailscale or Zerotier container is running before the interface is added to the list. 文章源自《智享阁》智享阁-https://www.esnpc.com/solution-for-unraid-zerotier-unable-to-open-web-ui-after-shutdown-reboot/

简单来说,就是新版本对网络做了改进,允许用户定义 Unraid 服务使用的接口,告诉我们需要在“设置->网络设置->额外接口”中填入 zerotier 的网关,但是这样操作后,关机或重启 unraid 后 zerotier 就无法打开 Web UI 了,这里我们就不谈原因了,有兴趣的可以自己去网补。文章源自《智享阁》智享阁-https://www.esnpc.com/solution-for-unraid-zerotier-unable-to-open-web-ui-after-shutdown-reboot/

经过网络搜索找到了两种解决方法,一是修改 go 文件(由 unraid 简体中文论坛版主 JackieWu 提供),二是使用“User Scripts”插件加载脚本(由 unraid 论坛 SpaceinvaderOne、mauriceatkinson、btconnect 三位用户联合编写)文章源自《智享阁》智享阁-https://www.esnpc.com/solution-for-unraid-zerotier-unable-to-open-web-ui-after-shutdown-reboot/

第一种解决方法

这个比较简单,打开 go 文件,在末尾添加如下代码:文章源自《智享阁》智享阁-https://www.esnpc.com/solution-for-unraid-zerotier-unable-to-open-web-ui-after-shutdown-reboot/

# ZeroTier Net Fixer
echo "iptables -t nat -A PREROUTING -s 192.168.192.0/24 -p tcp --dport 80 -j DNAT --to-destination UNRAID_IP:80" >> /boot/config/go

注意,请将代码中的 192.168.192.0/24 改成你使用的 zerotier IP 网段,保存后就完成了。文章源自《智享阁》智享阁-https://www.esnpc.com/solution-for-unraid-zerotier-unable-to-open-web-ui-after-shutdown-reboot/

第二种解决方法

该脚本包含几个用户可配置的变量,以适应您的特定设置:
wait_time_docker_service:脚本等待 Docker 服务准备就绪的最长时间(以秒为单位)。默认值为 300 秒(5 分钟)。
zerotier_container:ZeroTier 容器的名称。如果容器的名称与默认名称不同,请更改它。
max_checks_zerotier:脚本尝试确认 ZeroTier 容器正在运行的最大检查次数。默认值设置为 10 次检查。
wait_time_zerotier_container:ZeroTier 容器每次检查之间的时间(以秒为单位)。默认值设置为 30 秒。文章源自《智享阁》智享阁-https://www.esnpc.com/solution-for-unraid-zerotier-unable-to-open-web-ui-after-shutdown-reboot/

安装与使用:
1、安装 User Scripts 插件:如果尚未安装,请从“应用”选项卡将 User Scripts 插件安装到 unraid 服务器。
2、创建新脚本:导航到 unraid 仪表板上的“插件-User Script”页面,单击:Add new script,为脚本命名,例如:ZeroTier-Nginx-Fixe,将脚本的全部内容复制并粘贴到脚本编辑器中。
3、配置脚本:根据服务器设置和首选项修改脚本顶部的用户变量。
4、将脚本设置为在首次阵列启动时运行:在 User Scripts 设置中,将启动方案设置为“First Array Start”。这样可以确保脚本在每次服务器启动时自动运行。
5、最后应用设置即可。文章源自《智享阁》智享阁-https://www.esnpc.com/solution-for-unraid-zerotier-unable-to-open-web-ui-after-shutdown-reboot/

需要输入的脚本代码如下:

#!/bin/bash
#set -x
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# #   Script for Fixing Issue with ZeroTier after Unraid Server Restart                                                                   # #
# #   (needs ZeroTier container)                                                                                                          # #
# #   by - SpaceInvaderOne                                                                                                                # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
#
# Main Variables
####################
#
# time to wait from array start for docker service to be running (script will exit if time exceeded)
wait_time_docker_service=300            # Docker 服务准备就绪的最大等待时间(以秒为单位)(默认为 300 秒或 5 分钟)
# container name
zerotier_container="ZeroTier"   # 如果您的 ZeroTier 容器有不同的名称,请更改该名称
# zero tier container wait times before running
max_checks_zerotier=10                   # 检查 zerotier 是否运行的最大次数
wait_time_zerotier_container=30          # 检查间隔时间(秒钟)
####################

# check if docker service is running before moving forward
check_docker() {
    timeout=$wait_time_docker_service
    elapsed=0
    interval=10  # check every 10 seconds

    while ! /etc/rc.d/rc.docker status &>/dev/null; do
        sleep $interval
        elapsed=$((elapsed + interval))
        if [ $elapsed -ge $timeout ]; then
            echo "Docker service did not start within $timeout seconds. Exiting"
            exit 1
        fi
    done
}
####################

# check if the ZeroTier container is running
check_zerotier_container() {
    count=0
    while [ $count -lt $max_checks_zerotier ]; do
        if docker ps | grep -q "$zerotier_container"; then
            return 0
        else
            sleep $wait_time_zerotier_container
        fi
        count=$((count + 1))
    done
    echo "ZeroTier container is not running after $max_checks_zerotier checks. Exiting"
    exit 1
}
####################

# validate and restart Nginx
validate_and_restart_nginx() {
    if nginx -t; then
        /etc/rc.d/rc.nginx restart
    else
        echo "Nginx test failed."
       
        exit 1
    fi
}
####################
## run functions
#
check_docker
check_zerotier_container
validate_and_restart_nginx

该脚本代码在 Github 上的项目地址:https://github.com/SpaceinvaderOne/Unraid-ZeroTier-Server-Restart-fix

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布、售卖本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

YeYo(博主)
  • 本文由 YeYo(博主) 发表于 2024年5月25日20:42:34
  • 转载请保留本文链接:https://www.esnpc.com/solution-for-unraid-zerotier-unable-to-open-web-ui-after-shutdown-reboot/

发表评论