我正在运行 Ubuntu Server 22.04.1,并尝试使用 systemd 在启动时运行 ngrok,以创建 ssh 隧道。
当前状态:
- /etc/systemd/system/BWS_ngrok.service 下的 BWS_ngrok.service
- /home/ubuntu/server/bwsv4/ngrok.yml 下的 ngrok.yml
- ngrok 路径:/snap/bin/ngrok (根据
which ngrok
)
/etc/systemd/system/BWS_ngrok.service:
[Unit]
Description=Start Ngrok at boot
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service
[Service]
ExecStart=/snap/bin/ngrok start --config /home/ubuntu/server/bwsv4/ngrok.yml
[Install]
WantedBy=multi-user.target
/home/ubuntu/server/bwsv4/ngrok.yml:
authtoken: <Ngrok-Authtoken>
tunnels:
ssh:
proto: tcp
addr: 22
我在控制台中做了什么:
ubuntu@ubuntu:/etc/systemd/system$ sudo systemctl daemon-reload
ubuntu@ubuntu:/etc/systemd/system$ sudo systemctl restart BWS_ngrok.service
ubuntu@ubuntu:/etc/systemd/system$ sudo systemctl status
输出sudo systemctl status BWS_ngrok.service
:
BWS_ngrok.service
× BWS_ngrok.service - Start Ngrok at boot
Loaded: loaded (/etc/systemd/system/BWS_ngrok.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2022-09-13 19:27:11 UTC; 2s ago
Process: 4734 ExecStart=/snap/bin/ngrok start --config /home/ubuntu/server/bwsv4/ngrok.yml (code=exited, status=1/FAILURE)
Main PID: 4734 (code=exited, status=1/FAILURE)
CPU: 239ms
Sep 13 19:27:11 ubuntu systemd[1]: Started Start Ngrok at boot.
Sep 13 19:27:11 ubuntu systemd[1]: BWS_ngrok.service: Main process exited, code=exited, status=1/FAILURE
Sep 13 19:27:11 ubuntu systemd[1]: BWS_ngrok.service: Failed with result 'exit-code'.
到目前为止我已经尝试过:
- 在
.service
文件中:(ExecStart=/snap/bin/ngrok tcp 22
之前添加了Ngrok-Authtokenngrok config add-authtoken <Ngrok-Authtoken>
) - 使用 检查 ngrok 的配置文件的位置
ngrok config check
,它给了我Valid configuration file at /home/ubuntu/snap/ngrok/85/.config/ngrok/ngrok.yml
,所以我在这个文件中添加了以下内容:
authtoken: <Ngrok-Authtoken>
tunnels:
ssh:
proto: tcp
addr: 22
但我仍然无法让 Ngrok 在启动时启动。