66

如何将流星应用程序部署到我自己的服务器?

风味1:开发和部署服务器是一样的;

风味2:开发服务器是一个(可能是我的本地主机),部署服务器是另一个(可能是云中的VPS);

风味3:我想做一个“流星托管”域,就像“meteor.com”一样。可能吗?如何?

更新

我正在运行 Ubuntu,我不想“demeteorize”应用程序。谢谢你。

4

6 回答 6

87

Meteor 文档目前说:

“[...] 您需要提供 Node.js 0.8 和 MongoDB 服务器。然后您可以通过调用节点、指定应用程序要侦听的 HTTP 端口以及 MongoDB 端点来运行应用程序。”


因此,在安装 Node.js的几种方法中,我按照我找到的最佳建议启动并运行它,这基本上是解压Node.JS 官方网站上直接可用的最新版本,已经为 Linux 编译(64 位,在我的情况下):

# Does NOT need to be root user:

# create directory
mkdir -p ~/.nodes && cd ~/.nodes

# download latest Node.js distribution
curl -O http://nodejs.org/dist/v0.10.13/node-v0.10.13-linux-x64.tar.gz

# unpack it
tar -xzf node-v0.10.13-linux-x64.tar.gz

# discard it
rm node-v0.10.13-linux-x64.tar.gz

# rename unpacked folder
mv node-v0.10.13-linux-x64 0.10.13

# create symlink
ln -s 0.10.13 current

# add path to PATH
export PATH="~/.nodes/current/bin:$PATH"

# check
node --version
npm --version


安装 MongoDB,我只需按照其官方网站文档部分中的 MongoDB 手册中的说明进行操作

# Needs to be root user (apply "sudo" if not at root shell)

apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/10gen.list
apt-get update
apt-get install mongodb-10gen



服务器已准备好运行 Meteor 应用程序!对于部署,主要的“问题”是捆绑操作发生的地方。我们需要meteor bundle从应用程序源文件树中运行命令。例如:

cd ~/leaderboard
meteor bundle leaderboard.tar.gz


如果部署将在另一台服务器(风格 2sftp )中进行,我们需要使用、ftp或任何其他文件传输方法将 bundle tar.gz 文件上传到它。一旦文件在那里,我们将遵循 Meteor 文档README 文件,该文件神奇地包含在捆绑树的根目录中:

# unpack the bundle
tar -xvzf leaderboard.tar.gz

# discard tar.gz file
rm leaderboard.tar.gz

# rebuild native packages
pushd bundle/programs/server/node_modules
rm -r fibers
npm install fibers@1.0.1
popd

# setup environment variables
export MONGO_URL='mongodb://localhost'
export ROOT_URL='http://example.com'
export PORT=3000

# start the server
node main.js


如果部署将在同一台服务器(风味 1)中,则捆绑 tar.gz 文件已经存在,我们不需要重新编译本机包。(直接跳到上面对应的部分。)



凉爽的!通过这些步骤,我将“排行榜”示例部署到我的自定义服务器,而不是“meteor.com”......(只是为了学习和重视他们的服务!)

我仍然必须让它在端口 80 上运行(我计划为此使用NginX),持久化环境变量,启动从终端分离的 Node.JS,等等......我知道这个设置是“几乎赤裸裸”的一个。 ..只是基础,第一步,基础基石。

该应用程序已“手动”部署,没有利用所有meteor deploy命令魔术功能...我看到人们发布了他们的“ meteor.sh ”和“ meteric.sh ” ,我遵循相同的路径...创建一个模拟“单一命令部署”功能的脚本......请注意,在不久的将来,所有这些东西都将成为先驱 Meteor explorer 的一部分,因为它将成长为整个 Galaxy!大多数这些问题都将成为过去。

无论如何,我很高兴看到部署的应用程序在最便宜的 VPS 中运行得有多快,延迟非常低,并且在几个不同的浏览器中几乎可以同时更新。极好的!

谢谢!!!

于 2013-07-12T17:35:55.033 回答
14

也试试Meteor Up

有了它,您可以部署到任何 Ubuntu 服务器。这在内部使用meteor build命令。并被许多人用于部署生产应用程序。

我创建 Meteor Up 是为了让开发人员在 Galaxy 出现之前部署生产质量的 Meteor 应用程序。

于 2014-11-17T01:19:42.200 回答
8

我建议使用单独的部署服务器进行风味二。关注点分离可为您的代码带来更稳定的环境,并且更易于调试。

为此,有一个出色的Meteoric bash 脚本可以帮助您部署到 Amazon 的 EC2 或您自己的服务器。

至于如何推出你自己的meteor.com,我建议你把它分解成它自己的StackOverflow问题,因为它不相关。另外,我无法回答:)

于 2013-07-12T06:27:43.743 回答
6

几天前我完成了它。我将 Meteor 应用程序部署到 DigitalOcean 上我自己的服务器上。我使用Meteor Up工具来管理服务器上的部署和 Nginx 来为应用程序提供服务。

使用起来非常简单。您应该使用以下命令安装流星:

npm install -g mup

然后创建用于部署配置的文件夹并进入创建的目录。然后运行mup init命令。它将创建两个配置文件。我们对mup.json文件感兴趣。它具有部署过程的配置。它看起来像这样:

{
  // Server authentication info
  "servers": [
    {
      "host": "hostname",
      "username": "root",
      "password": "password",
      // or pem file (ssh based authentication)
      //"pem": "~/.ssh/id_rsa",
      // Also, for non-standard ssh port use this
      //"sshOptions": { "port" : 49154 },
      // server specific environment variables
      "env": {}
    }
  ],

  // Install MongoDB on the server. Does not destroy the local MongoDB on future setups
  "setupMongo": true,

  // WARNING: Node.js is required! Only skip if you already have Node.js installed on server.
  "setupNode": true,

  // WARNING: nodeVersion defaults to 0.10.36 if omitted. Do not use v, just the version number.
  "nodeVersion": "0.10.36",

  // Install PhantomJS on the server
  "setupPhantom": true,

  // Show a progress bar during the upload of the bundle to the server.
  // Might cause an error in some rare cases if set to true, for instance in Shippable CI
  "enableUploadProgressBar": true,

  // Application name (no spaces).
  "appName": "meteor",

  // Location of app (local directory). This can reference '~' as the users home directory.
  // i.e., "app": "~/Meteor/my-app",
  // This is the same as the line below.
  "app": "/Users/arunoda/Meteor/my-app",

  // Configure environment
  // ROOT_URL must be set to https://YOURDOMAIN.com when using the spiderable package & force SSL
  // your NGINX proxy or Cloudflare. When using just Meteor on SSL without spiderable this is not necessary
  "env": {
    "PORT": 80,
    "ROOT_URL": "http://myapp.com",
    "MONGO_URL": "mongodb://arunoda:fd8dsjsfh7@hanso.mongohq.com:10023/MyApp",
    "MAIL_URL": "smtp://postmaster%40myapp.mailgun.org:adj87sjhd7s@smtp.mailgun.org:587/"
  },

  // Meteor Up checks if the app comes online just after the deployment.
  // Before mup checks that, it will wait for the number of seconds configured below.
  "deployCheckWaitTime": 15
}

填写完所有数据字段后,您可以使用 command 开始设置过程mup setup。它将设置您的服务器。

成功设置后,您可以部署您的应用程序。只需mup deploy在控制台中输入。

于 2015-09-06T17:41:53.417 回答
5

另一种选择是在您自己的服务器上开始开发。我刚刚创建了一个 Digital Ocean 盒子,然后连接了我的 Cloud9 IDE 帐户。

现在,我可以直接在云 IDE 中的机器上进行开发,而且部署很容易——只需复制文件。

我创建了一个教程,准确地展示了我的设置是如何工作的。

于 2014-10-13T14:25:49.477 回答
3

我在使用流星时遇到了很多麻烦,所以我决定编写自己的部署脚本。我还添加了如何设置 nginx 或 mongodb 的附加信息。希望能帮助到你!

查看/sh存储库中的文件夹

脚本的meteor-deploy.sh作用:

  1. 选择环境(./meteor-deploy.sh用于暂存,./meteor-deploy.sh prod用于生产)
  2. 构建和捆绑流星应用程序的生产版本
  3. 将捆绑包复制到服务器
  4. SSH 进入服务器
  5. 做一个 mongodump 来备份数据库
  6. 停止正在运行的应用程序
  7. 解包捆绑
  8. 覆盖应用程序文件
  9. 重新安装应用节点包依赖项
  10. 启动应用程序(永远使用)

测试了以下服务器配置:

  • Ubuntu 14.04.4 LTS
  • 流星——版本 1.3.2.4
  • 节点--版本 v0.10.41
  • npm --版本 3.10.3
于 2016-07-01T11:35:59.800 回答