【发布时间】:2018-11-13 20:28:50
【问题描述】:
我有ngrok 在我远程连接的服务器上运行。
我首先使用显而易见的 ngrok.exe http 80。问题是当我在该特定服务器上注销时,ngrok 将关闭,我将失去我的隧道。即使我已经注销了机器,有没有办法让 ngrok 隧道继续运行?我知道如果机器关闭,我无法保持隧道运行,这是显而易见的。有什么想法吗?
提前致谢。
【问题讨论】:
我有ngrok 在我远程连接的服务器上运行。
我首先使用显而易见的 ngrok.exe http 80。问题是当我在该特定服务器上注销时,ngrok 将关闭,我将失去我的隧道。即使我已经注销了机器,有没有办法让 ngrok 隧道继续运行?我知道如果机器关闭,我无法保持隧道运行,这是显而易见的。有什么想法吗?
提前致谢。
【问题讨论】:
正如您所说,如果机器关闭,则无法保持进程运行。有很多方法可以做到这一点。在每种方法中,我假设您已经拥有以下配置文件:
config.yml
authtoken: <your-auth-token>
tunnels:
default:
proto: http
addr: 80
使用 ngrok 链接只需运行以下命令:
ngrok service install -config /path/to/your/config.yml
ngrok service start
然后,您应该能够像管理给定操作系统上运行的任何其他服务一样管理 ngrok。
nohup 命令通常默认安装在 mac os 和 linux 上。像这样运行命令:
nohup ngrok start --all --config="path/to/config.yml" &
在屏幕中运行在这里也应该达到同样的效果。
要创建服务,您需要下载用于从非服务可执行文件创建服务的程序。在这里,我将介绍如何使用 NSSM(非吸吮服务管理器)来做到这一点。
运行以下命令:
nssm.exe install ngrok
在出现的窗口中选择 ngrok 可执行文件并将以下内容添加到参数中,然后按“安装服务”。
start --all --config="C:\path\to\my\config.yml"
现在可以从服务管理器管理该服务。要启动它,请打开一个管理终端并运行以下命令:
sc start ngrok
需要根。
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
【讨论】: