我最近设置了一个基于Ubuntu 18.04的服务器,并为此目的安装了以下工具
主要问题与 socket.io
root@ubuntu:~# service socket-io status
● socket-io.service - Sellist Notification Service
Loaded: loaded (/etc/systemd/system/socket-io.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2019-11-05 07:14:58 UTC; 1h 0min ago
Process: 27489 ExecStart=/usr/bin/node /var/www/socket.io/server.js (code=exited, status=217/USER)
Main PID: 27489 (code=exited, status=217/USER)
Nov 05 07:14:58 ubuntu systemd[1]: socket-io.service: Service hold-off time over, scheduling restart.
Nov 05 07:14:58 ubuntu systemd[1]: socket-io.service: Scheduled restart job, restart counter is at 5.
Nov 05 07:14:58 ubuntu systemd[1]: Stopped Sellist Notification Service.
Nov 05 07:14:58 ubuntu systemd[1]: socket-io.service: Start request repeated too quickly.
Nov 05 07:14:58 ubuntu systemd[1]: socket-io.service: Failed with result 'exit-code'.
Nov 05 07:14:58 ubuntu systemd[1]: Failed to start Sellist Notification Service.
/etc/systemd/system/socket-io.service
[Unit]
Description=Sellist Notification Service
After=network.target
[Service]
User=minion
Group=minion
Restart=always
ExecStart=/usr/bin/node /var/www/socket.io/server.js
[Install]
WantedBy=default.target
(第1步)我这样安装
mkdir -p /var/www/socket.io
cd /var/www/socket.io
**These 2 files are perfect no errors**
1. nano server.js
2. nano package.json
npm install
(第2步)创建系统服务
vim /etc/systemd/system/socket-io.service
[Unit]
Description=Sellist Notification Service
After=network.target
[Service]
User=minion
Group=minion
Restart=always
ExecStart=/usr/bin/node /var/www/socket.io/server.js
[Install]
WantedBy=default.target
(第3步)启用并启动服务
systemctl enable socket-io && systemctl start socket-io
检查访问权限-Nginx错误的网关 但是如果我转到 /var/www/socket.io ,则可以使用 node server.js 运行 server.js >监听指定端口,完全可以避免浏览器检查中出现错误的网关,
但是当我退出在终端上监听或关闭时,不幸的是我看到了nginx网关错误。
但是我不能总是手动运行以在生产环境中提供套接字.io,因此请有人帮助我摆脱这个问题。基本上我发现了pm2之类的东西,但是没有pm2或其他任何工具,我们可以运行吗?