gpt4 book ai didi

tunnel - 即使在注销服务器时如何保持 ngrok 运行

转载 作者:行者123 更新时间:2023-12-03 15:20:58 37 4
gpt4 key购买 nike

我有 ngrok在我远程访问的服务器上运行。

我通过使用明显的开始,ngrok.exe http 80 .问题是当我在那个特定的服务器上签字时,ngrok 会关闭,我会失去我的隧道。有没有办法让 ngrok 隧道在我注销机器后继续运行?我知道如果机器关闭,我将无法保持隧道运行,这很明显。有什么想法吗?

提前致谢。

最佳答案

正如您所说,如果机器关闭,则无法保持进程运行。有多种方法可以做到这一点。在这些方法中的每一个中,我假设您已经拥有以下配置文件:

config.yml

authtoken: <your-auth-token>
tunnels:
default:
proto: http
addr: 80

Ngrok 链接(Windows/Mac OS/Linux,商业)

使用 ngrok 链接只需运行以下命令:
ngrok service install -config /path/to/your/config.yml
ngrok service start

然后,您应该能够像管理在给定操作系统上运行的任何其他服务一样管理 ngrok。

Nohup (Maco OS/Linux)

nohup 命令通常默认安装在 mac os 和 linux 上。像这样运行命令:
nohup ngrok start --all --config="path/to/config.yml" &

在屏幕中运行也应该达到相同的效果。

创建 Windows 服务 (Windows)

要创建服务,您需要下载用于从非服务可执行文件创建服务的程序。在这里,我将介绍如何使用 NSSM(Non-Sucking Service Manager)来做到这一点。
  • 下载可执行文件
  • 打开 CMD 和 cd 进入与 nssm.exe 相同的目录
  • 运行以下命令:
    nssm.exe install ngrok
  • 在出现的窗口中选择 ngrok 可执行文件并将以下内容添加到参数中,然后按“安装服务”。
    start --all --config="C:\path\to\my\config.yml"
  • 现在可以从服务管理器管理该服务。要启动它,请打开管理终端并运行以下命令:
    sc start ngrok

  • 创建 systemd 服务(仅限 Linux - systemd)

    需要root。
  • cd 进入/etc/systemd/system/
  • 创建以下文件:

    ngrok.service
    [Unit]
    Description=Ngrok
    After=network.service

    [Service]
    type=simple
    User=<your_user_name>
    WorkingDirectory=/home/<your_user_name>
    ExecStart=/usr/bin/ngrok start --all --config="/path/to/config.yml"
    Restart=on-failure

    [Install]
    WantedBy=multi-user.target
  • 然后运行以下命令启动并启用服务
    systemctl enable ngrok.service && systemctl start ngrok.service

  • 来源:

    https://ngrok.com/docs/ngrok-link#service

    https://www.freedesktop.org/software/systemd/man/systemd.unit.html

    https://nssm.cc/commands

    关于tunnel - 即使在注销服务器时如何保持 ngrok 运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50681671/

    37 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com