简体   繁体   English

Google Cloud / AWS:如何启动NodeJS服务器

[英]Google Cloud/AWS: How to start NodeJS server

I'm trying to deploy my NodeJS server on GCP and AWS. 我正在尝试在GCP和AWS上部署我的NodeJS服务器。 I have created instances with Bitnami Linux image and uploaded my files. 我已经用Bitnami Linux映像创建了实例并上传了文件。 I can SSH in to the instance and start the server by running node command. 我可以通过运行node命令通过SSH进入实例并启动服务器。 But how can I run the server permanently? 但是,如何才能永久运行服务器? I tried putting the process to background but it stopped soon as I logged off SSH. 我尝试将进程置于后台,但是当我注销SSH时它立即停止了。 What is the correct way to starting the server process. 什么是启动服务器进程的正确方法。

I added a script as follows: 我添加了一个脚本,如下所示:

key: startup-script
value: node /home/madu/nodeapp/bin/www

And restarted the VM. 并重启了VM。 But still doesn't look like it works. 但仍然看起来不起作用。 Thank you. 谢谢。

If you have the permission, install tmux, which is a terminal multiplexer. 如果获得许可,请安装tmux,它是终端多路复用器。 You can also use GNU screen, ect. 您也可以使用GNU屏幕等。 Do the following 请执行下列操作

ssh into the remote machine
start tmux by typing tmux into the shell
start node inside the started tmux session
leave/detach the tmux session by typing Ctrl+B and then D

You can now safely log off from the remote machine, your process will keep running inside tmux. 现在,您可以安全地从远程计算机注销,您的进程将继续在tmux中运行。 When you come back again and want to check the status of your process you can use tmux attach to attach to your tmux session. 当您再次回来并要检查过程状态时,可以使用tmux Attach附加到您的tmux会话。

If you want to have multiple sessions running side-by-side, you should name each session using Ctrl-B and $ . 如果要并行运行多个会话,则应使用Ctrl-B$命名每个会话。 You can get a list of the currently running sessions using tmux list-sessions. 您可以使用tmux list-sessions获得当前正在运行的会话的列表。

tmux can do much more advanced things https://tmux.github.io/ tmux可以做更高级的事情https://tmux.github.io/

I think you're trying on Compute Engine? 我认为您正在尝试使用Compute Engine? Why not use App Engine Flex? 为什么不使用App Engine Flex? It's much simpler than trying to install Node.js on your own on Compute Engine. 这比尝试在Compute Engine上自行安装Node.js要简单得多。 Here's how to deploy Node.js on App Engine: 以下是在App Engine上部署Node.js的方法:

https://cloud.google.com/nodejs/getting-started/hello-world#deploy_and_run_hello_world_on_app_engine https://cloud.google.com/nodejs/getting-started/hello-world#deploy_and_run_hello_world_on_app_engine

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM