ngrok/ngrokd设置开机自启动

 

建立服务启动文档:

vim /etc/init.d/ngrok

#!/bin/sh
### BEGIN INIT INFO
# Provides:            ngrok
# Required-Start:
# Required-Stop:
# Default-Start:       2 3 4 5
# Default-Stop:        0 1 6
# Short-Description: Start or stop the ngrok Proxy.
### END INIT INFO

ngrok_path=/root/ngrok/
case "$1" in
        start)
                 echo "start ngrok service.."
                 sh ${ngrok_path}/ngrok.sh &
                 ;;
        *)
        exit 1
        ;;
esac

设置启动:

systemctl enable ngrok

systemctl start ngrok

reboot

然后测试一下。就OK了

在Linux或macOS系统中,让Ngrok在每次系统启动时自动运行,可以利用系统级别的服务管理器。以下是两种常见的方法: **在Ubuntu和Debian系列(Systemd)**: 1. **安装ngrok**: 使用apt-get安装: ``` sudo apt-get install ngrok ``` 2. **创建systemd服务**: 编辑`/etc/systemd/system/ngrok.service`文件,添加以下内容: ```ini [Unit] Description=Ngrok HTTP/TLS Tunnel After=network.target [Service] ExecStart=/usr/local/bin/ngrok authtoken [YOUR_NGROK_API_TOKEN] http [YOUR_PORT] Restart=always User=<your-user> WorkingDirectory=<path-to-your-project> [Install] WantedBy=multi-user.target ``` 将`[YOUR_NGROK_API_TOKEN]`和`[YOUR_PORT]`替换为你实际的Ngrok API token和需要绑定的端口号。 3. **启用并启动服务**: ```sh sudo systemctl daemon-reload sudo systemctl enable ngrok sudo systemctl start ngrok ``` **在macOS(Homebrew)**: 1. **安装ngrok**: 执行: ```sh brew install ngrok ``` 2. **创建launchd守护进程**: 创建`~/Library/LaunchAgents/homebrew.ngrok.plist`文件,加入内容: ```xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>homebrew.ngrok</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/ngrok</string> <string>authtoken</string> <string>[YOUR_NGROK_API_TOKEN]</string> <string>http</string> <string>[YOUR_PORT]</string> </array> <!-- 其他选项如User等可选 --> </dict> </plist> ``` 3. **加载和启动守护进程**: ```sh launchctl load ~/Library/LaunchAgents/homebrew.ngrok.plist ``` 请注意替换`[YOUR_NGROK_API_TOKEN]`和`[YOUR_PORT]`为你的Ngrok API密钥和应用绑定的端口。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值