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

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

问题描述

所以,当我运行 meteor 时,应用程序运行良好.但是,当我关闭与云服务器的连接时,meteor 显然关闭了.我应该怎么做才能永远运行流星?

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/ 等 3rd 方数据库服务有什么意义?它不会减慢网站的速度,因为现在应用程序必须连接到他们的数据库而不是本地数据库吗?

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 时,应用程序运行良好.但是,当我关闭连接到我的云服务器,meteor 显然关闭了.

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

您可以使用用于此目的的 nohup(无挂机)启动 Meteor.

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

nohup meteor --production &

但是无论如何,使用meteor 运行一个生产站点并不是一个好主意.

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

我应该怎么做才能永远运行meteor?

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.

我还想指出 forever 已经过时了,我听说最近有更好的替代品,但它似乎仍然是一个非常常见的工具.您还可以使用 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.

但首先,您必须像这样消除"您的流星应用程序:

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

所以现在你有一个普通的节点应用程序,你可以用 node main.js

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

让我提一下,使用meteor 使用的node 版本可能是一个好主意,它是meteor 0.9.1 的0.10.29可以传统安装,也可以使用meteor工具自带的node版本.

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 :

  • 假设您只做与流星相关的事情.
  • 它取决于meteor工具的发布过程(如果meteor工具更新,您需要重新运行这些命令).

您可以使用 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

要将您的节点应用程序作为服务启动,您可以使用以下命令,正确设置一些环境变量并使用 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

你可以使用forever stop my-project-node/main.js

另外,使用 3rd 方数据库服务有什么意义,比如https://mongolab.com/?

Also, what's the point of using 3rd party database service like https://mongolab.com/?

使用meteor工具时,它会自动为你启动一个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 的东西,这有点回答了这个问题:为什么不使用其他服务来为我们处理它,他们更清楚,对吧?

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 ?

当然,依赖第三方数据库服务有其不便之处,这就是其中之一.网络通信总是比本地主机上发生的进程间通信慢(这在你现在可以找到的这些 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的url,这就是你需要的如果您希望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)相同的版本,并让它作为服务运行,以便在您的服务器重新启动时实际重新启动.
  • 通过使用 mongo 命令启动客户端来测试 mongod 是否正在运行.
  • 在永久启动您的应用程序时传递正确的 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

Understand now why meteor deploy is amazing :D

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

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