如何永远运行流星?使用第三方数据库好吗? [英] How to run Meteor forever? And is it good using 3rd party database?

查看:125
本文介绍了如何永远运行流星?使用第三方数据库好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,当我运行 meteor 时,app工作正常。但是,当我关闭与云服务器的连接时,流星显然会关闭。我该怎么办才能永远运行流星?

So, when I run meteor, app works fine. However, when I close the connection to my cloud server, meteor obviously shuts down. What should I do to run meteor forever?

此外,使用第三方数据库服务有什么意义,例如 https:/ /mongolab.com/ ?它不会减慢网站的速度,因为现在应用程序必须连接到他们的数据库而不是本地数据库吗?

Also, what's the point of using 3rd party database service like https://mongolab.com/? Doesn't it slow down the website, because now application has to connect to their database instead of local database?

例如,我如何连接到mongolab?

And how exactly do I connect to mongolab for example?

推荐答案


所以,当我运行meteor时,app工作正常。但是,当我关闭与我的云服务器的
连接时,流星显然会关闭。

So, when I run meteor, app works fine. However, when I close the connection to my cloud server, meteor obviously shuts down.

你可以用<启动meteor code> nohup (没有挂断)用于此目的。

You could launch meteor with nohup (no hang-up) which serves this purpose.

nohup meteor --production &

但是无论如何使用流星运行生产网站并不是一个好主意。

But it's not a good idea to run a site in production with meteor anyway.


我该怎样做才能永远运行流星?

What should I do to run meteor forever ?

你可以使用 forever ,这是一个Node.js工具,用于运行节点应用程序作为服务。

You can use forever, a Node.js tool designed to run node apps as services.

我还想指出永远正在变老,我听说过最近的替代方案,但它似乎仍然是一个非常常见的工具。
您还可以使用 systemd ,它可以更好地与UNIX服务生态系统集成,但这是一个很好的故事。

I also want to point that forever is getting old and I've heard of better recent alternatives but it seems to still be a pretty common tool. You could also use systemd which integrates better with the UNIX service ecosystem but that's anoter story.

但首先,你必须像这样对你的流星应用程序demeteorize:

But first, you'll have to "demeteorize" your meteor application like this :

cd my-project-meteor
meteor bundle --directory ../my-project-node
# this is going to take some time
cd ../my-project-node/programs/server
npm install
# this is going to take some time too

所以现在你有一个普通的节点应用,您可以使用运行节点main.js

So now you have a plain node app, that you can run with node main.js

让我提一下,使用它可能是一个好主意meteor使用的节点版本,从流星开始是0.10.29 0.9.1
您可以传统安装它,也可以使用流星工具附带的节点版本。

Let me mention that it might be a good idea to use the node version used by meteor which is 0.10.29 as of meteor 0.9.1 You can install it traditionally or you could use the node version that is shipped with the meteor tool.

sudo ln -s ~/.meteor/packages/meteor-tool/1.0.27/meteor-tool-os.linux.x86_64/dev_bundle/bin/node /usr/bin/node
sudo ln -s ~/.meteor/packages/meteor-tool/1.0.27/meteor-tool-os.linux.x86_64/dev_bundle/bin/npm /usr/bin/npm

请注意,这种在系统上安装node + npm的方式存在问题,因为:

Note that this way of "installing" node + npm on your system is problematic because :


  • 它假设你只做流星相关的东西。

  • 它取决于流星工具的发布过程(如果流星工具更新,你需要重新运行这些赞誉)。

您可以使用npm安装 forever 工具:

You can install the forever tool using npm :

# -g means globally : give access to forever to all users on the system
sudo npm install -g forever

要将节点应用程序作为服务启动,可以使用以下命令,该命令正确设置一些环境变量并使用<运行应用程序code> forever :

To launch your node app as a service, you can use the following command, which sets correctly some environment variables and run the app using forever :

sudo PORT=80 MONGO_URL=mongodb://localhost/my-project-mongodb ROOT_URL=http://localhost forever start my-project-node/main.js

您可以使用监视它永远停止my-project-node / main.js


此外,使用第三方数据库服务有什么意义,例如
https://mongolab.com/

使用流星工具时,它会自动为您启动 mongod 进程,由代表您的应用程序的meteor执行的基础节点进程将连接到此mongo实例。

When using the meteor tool, it launches a mongod process automatically for you, and the underlying node process executed by meteor representing your app connects to this mongo instance.

当我们想要将我的流星应用程序作为节点应用程序启动时,我们必须自己处理mongo的东西,这有点回答这个问题:为什么不使用其他服务为我们处理它,他们知道的更好,对吧? / p>

When we want to launch our meteor app as a node app, we have to handle the mongo stuff ourself, which kinda answer the question : why not using another service to handle it for us, they know better, right ?


它不会减慢网站的速度,因为现在应用程序必须将
连接到他们的数据库而不是本地数据库?

Doesn't it slow down the website, because now application has to connect to their database instead of local database ?

当然,依靠第三方数据库服务有它的我nconvenients,这是其中之一。网络通信总是比本地主机上发生的进程间通信慢(这在现在可以找到的这些SSD支持的廉价VPS上尤其如此)。

Of course, relying on a 3rd party database service has its inconvenients, and this is one of them. Network communications will always be slower than interprocess communications taking place on localhost (this is especially true on these SSD backed cheap VPS you can find nowadays).


<例如,我如何连接到mongolab?

And how exactly do I connect to mongolab for example ?

通过为环境变量设置适当的值 MONGO_URL ,数据库服务提供商会给你一个与你的在线 mongodb 对应的网址,这是你需要传递给节点进程的在命令行中如果你想让meteor连接到你的远程数据库并照常工作。

By setting an appropriate value to the environment variable MONGO_URL, the database service provider will give you an url that corresponds to your online mongodb, this is what you need to pass to the node process in command line if you want meteor to connect to your distant database and work as usual.

如果你想启动一个专用的本地 mongod 实例让您的应用程序连接到它,这是另一个主题,但您必须按照以下步骤操作:

If you want to launch a dedicated local mongod instance to let your application connect to it, well this is another topic but you'll have to follow these steps :


  • 首先在服务器上正确安装 mongodb ,使用操作系统版本的参考文档。正确地说,我的意思是选择与meteor当前使用相同的版本(2.4.9)并让它作为服务运行,以便在服务器重新启动时实际重启。

  • 测试mongod通过使用 mongo 命令启动客户端来运行。

  • 在永久启动应用程序时传递正确的MONGO_URL(类似 mongodb:// localhost / my-project-mongodb

  • first install mongodb correctly on your server, using the reference documentation for the OS version. By correctly I mean choose the same version as meteor is using currently (2.4.9) and let it run as a service so that it will actually restart when your server reboots.
  • test that mongod is running by launching a client with the mongo command.
  • pass the correct MONGO_URL when launching your app with forever (something like mongodb://localhost/my-project-mongodb)

了解原因 meteor deploy 太棒了:D

这篇关于如何永远运行流星?使用第三方数据库好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆