systemd 서비스를 사용하여 서버를 실행한 후 서버에 액세스할 수 없습니다.

systemd 서비스를 사용하여 서버를 실행한 후 서버에 액세스할 수 없습니다.

VPS에서 NodeJs 서버를 지속적으로 실행하려고 하는데 systemd서비스를 생성하고 시작했습니다.

내 서버에 여전히 연결할 수 없습니다. 상태를 확인할 수 있으며 제대로 작동합니다.

서비스 상태:

Node.service - Runs the Node Server for Node API
   Loaded: loaded (/etc/systemd/system/Node.service; disabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-05-12 16:16:38 CEST; 2min 37s ago
 Main PID: 26697 (node)
    Tasks: 10
   Memory: 87.5M
      CPU: 2.734s
   CGroup: /system.slice/Node.service
           └─26697 /root/.nvm/versions/node/v9.11.1/bin/node www

May 12 16:16:38 vps543107 systemd[1]: Started Runs the Node Server for Node API.
May 12 16:16:41 vps543107 node[26697]: Listening on port 3000

제공하다:

[Unit]
Description=Runs the Node Server for Node API
Documentation="No Docs"
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/root/Node/bin
ExecStart=/root/.nvm/versions/node/v9.11.1/bin/node www
Restart=on-failure

[Install]
WantedBy=multi-user.target

HTTP 요청으로 서버에 연결할 수 없으며 모든 요청 시간이 초과됩니다.

내 서비스에 문제가 있나요?

답변1

다음을 시도해 보세요

[Unit]
Description="Runs the Node Server for Node API"
#Requires=After=mysql.service       # If you have any dependency then add it

[Service]
ExecStart=/root/.nvm/versions/node/v9.11.1/bin/node /root/Node/bin/www
Restart=always
# Restart service after 10 seconds if node service crashes
RestartSec=10

# Output to syslog
StandardOutput=syslog
StandardError=syslog
#Change this to find app logs in /var/log/syslog
SyslogIdentifier=nodejs-api
# Followig will require if you are using the PORT or Node from Envirnoment
Environment=NODE_ENV=production PORT=3000

[Install]
WantedBy=multi-user.target

서버 시스템이 가동되고 서버에 액세스할 수 없으면 다음 명령을 사용하여 /var/log/syslog의 로그를 확인하여 문제를 해결할 수 있습니다.

sudo cat /var/log/syslog | grep -r "nodejs-api"

신병:sudo systemctl 활성화 RocketChat

답변2

시작하기 전에 애플리케이션을 시작하여 After=network-online.target네트워크가 완전히 작동하는지 확인하세요.

"HTTP"를 통해 응용 프로그램을 사용할 수 없다고 언급하셨습니다. 서버 포트 80(기본 HTTP 포트)의 포트 3000에서 애플리케이션을 실행할 계획입니까? 실행 중인 것과 동일한 포트에서 테스트하고 있습니까?

애플리케이션을 실행하는 데 User=root보안 위험이 있습니다 . 웹 애플리케이션의 보안 결함으로 인해 VPS가 완전히 손상될 수 있습니다. 이러한 위험을 줄이려면 권한이 없는 사용자로 애플리케이션을 실행하는 것이 좋습니다.

애플리케이션이 부팅 시 시작되기를 원하는 경우 systemctl enable your-app부팅 시 시작되도록 활성화했는지 확인하세요.

또한 NVM을 사용하고 계신 것으로 보입니다. 귀하의 서비스 상태에 따라 작동하는 것 같지만 프로덕션 서비스에는 권장하지 않습니다. 환경 변수에 의존하므로 더욱 취약해집니다.

나는 사용하는 것이 좋습니다N대신 패키지 관리자는 환경 변수가 아닌 버전 전환을 위해 심볼릭 링크만 사용하는 프로덕션에 사용됩니다.

또한보십시오수동으로 시작할 때 시스템을 실행할 수 없는 이유에 대해 자주 묻는 질문(FAQ).

관련 정보