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

问题描述 投票:66回答:6

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

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

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

风味3:我想制作一个“meteor hosting”域名,就像“meteor.com”一样。 可能吗? 怎么样?

更新

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

deployment hosting meteor
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


如果部署将在另一个服务器( flavor 2 )中进行,我们需要使用sftpftp或任何其他文件传输方法将bundle tar.gz文件上传到它。 一旦文件存在,我们就会遵循Meteor文档自发包含在bundle树根目录中的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 [email protected]
popd

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

# start the server
node main.js


如果部署将在同一服务器( flavor 1 )中,则bundle tar.gz文件已经存在,我们不需要重新编译本机程序包。 (只需跳过上面的相应部分。)



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

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

该应用程序已经“手动”部署,没有利用所有meteor deploy命令魔术功能......我见过人们发布了他们的“ meteor.sh ”和“ meteoric.sh ”,我遵循相同的路径......创建一个脚本来模拟“单一命令部署”功能......意识到在不久的将来所有这些东西都将成为先驱流星探险家的一部分,因为它将成长为一个完整的银河! 而且大多数这些问题将成为过去的一个古老的问题。

无论如何,我很高兴看到部署的应用程序在最便宜的VPS中运行有多快,具有令人惊讶的低延迟和几个不同浏览器中几乎即时的同步更新。 太棒了!

谢谢!!!


14
投票

尝试Meteor Up

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

我创建了Meteor Up,允许开发人员部署生产质量的Meteor应用程序,直到Galaxy到来。


8
投票

我会推荐使用单独的部署服务器的flavor 2。 关注点分离可以为您的代码提供更稳定的环境,并且更易于调试。

要做到这一点,有一个出色的Meteoric bash脚本可以帮助您部署到亚马逊的EC2或您自己的服务器。

至于如何推出自己的meteor.com,我建议你将其分解为自己的StackOverflow问题,因为它没有关系。 另外,我无法回答:)


6
投票

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

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

npm install -g mup

然后为部署配置创建文件夹并转到创建的目录。 然后运行meteor 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:[email protected]:10023/MyApp",
    "MAIL_URL": "smtp://postmaster%40myapp.mailgun.org:[email protected]: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
}

填写所有数据字段后,您可以使用命令mup setup启动设置过程。 它将设置您的服务器。

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


5
投票

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

现在,我可以在云端IDE中直接在计算机上进行开发,部署非常简单 - 只需复制文件即可。

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


2
投票

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

请参阅存储库中的/sh文件夹

脚本meteor-deploy.sh作用是什么:

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

针对以下服务器配置进行了测试:

  • Ubuntu 14.04.4 LTS
  • 流星 - 转换1.3.2.4
  • node --version v0.10.41
  • npm --version 3.10.3
© www.soinside.com 2019 - 2024. All rights reserved.