我将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(Non-Sucking Service Manager)来说明如何操作。
运行以下命令:
nssm.exe install ngrok
在出现的窗口中选择ngrok可执行文件,并将以下内容添加到参数中,然后点击“安装服务”。
start --all --config="C:\path\to\my\config.yml"
现在可以从服务管理器中管理该服务。要启动它,请打开管理员终端并运行以下命令:
sc start ngrok
需要root权限。
进入 /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