如何将Meteor应用程序部署到自己的服务器?
类型1:开发和部署服务器相同;
类型2:开发服务器为一个(可能是本地主机),而部署服务器为另一个(例如位于云中的VPS);
类型3:我想制作一个类似于“meteor.com”这样的“Meteor托管”域名。这可能吗?如何实现?
更新:
我正在运行Ubuntu,并且不想将应用程序" demeteorize "。谢谢。
如何将Meteor应用程序部署到自己的服务器?
类型1:开发和部署服务器相同;
类型2:开发服务器为一个(可能是本地主机),而部署服务器为另一个(例如位于云中的VPS);
类型3:我想制作一个类似于“meteor.com”这样的“Meteor托管”域名。这可能吗?如何实现?
更新:
我正在运行Ubuntu,并且不想将应用程序" demeteorize "。谢谢。
Meteor文档目前描述:
"[...] 您需要提供Node.js 0.8和MongoDB服务器。 然后,通过调用node来指定应用程序监听的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
如果部署将在另一台服务器上进行( 2号口味 ),我们需要使用 sftp
, ftp
或任何其他文件传输方法将捆绑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”和“meteoric.sh”,我正在跟随同样的道路......创建一个脚本来模拟“单个命令部署”功能......意识到在不久的将来,所有这些东西都将成为先驱Meteor探险家的一部分,因为它将成长为整个星系!大多数这些问题都将成为过去的古董。
无论如何,我非常高兴看到部署的应用程序在最便宜的VPS上运行得有多快,延迟非常低,并且几乎可以同时在几个不同的浏览器中进行更新。太棒了!
谢谢!!!
pushd bundle/server/node_modules
应该改为 pushd bundle/programs/server/node_modules
。 - Alucardgit clone git@github.com:visionmedia/n.git && cd n && make install && n stable
。希望这能帮到你。 - Daniele Vrut也可以尝试使用 Meteor Up
这个工具可以让您部署到任何Ubuntu服务器。它在内部使用meteor build
命令,并被许多人用于部署生产应用程序。
我创建了Meteor Up,让开发人员能够部署具备生产质量的Meteor应用程序,直到Galaxy出现为止。
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
}
填写完所有数据字段后,您可以使用命令 mup setup
开始设置过程。它将设置您的服务器。
设置成功后,您可以部署您的应用程序。在控制台中输入 mup deploy
即可。
另一种选择是先在自己的服务器上进行开发。我刚刚创建了一个Digital Ocean虚拟机,然后连接了我的Cloud9 IDE账户。
现在,我可以直接在云端IDE中开发,并且部署非常容易——只需复制文件即可。
我在使用meteor up的过程中遇到了很多问题,所以我决定写自己的部署脚本。我还添加了如何设置nginx或mongodb的额外信息。希望能帮到你!
脚本meteor-deploy.sh
的功能:
./meteor-deploy.sh
表示staging,用./meteor-deploy.sh prod
表示production)已经测试过以下服务器配置: