bundle + forever部署Meteor App

Meteor是一款nodejs + MongoDB全栈式框架,活跃在国外。公司的服务器工程师给出的方案,本人加以编辑希望对Meteor感兴趣的同学有所帮助。

另外:招聘 javascript工程师,有兴趣致力于富应用开发 or NodeJs 开发的同学可以联系我哦.

bundle的作用是合并压缩Meteor Client JS文件 

对于css文件 Meteor自身已经打包合并为一个  

所以Meteor developers 不用担心打包方面的问题 处理的相当好

首先保证环境变量
在 /etc/profile.d/mrt.sh 中写入下列命令:
export PORT=80
export MONGO_URL=mongodb://yourdomain:27017/dbname
export ROOT_URL=http://yourdomain

yourdomain 一般为ip地址 ip绑定域名即可

下面以todos为例:

创建meteor todos例子:

meteor create --example todos

接下来对todos进行打包:
[root@localhost ~]# cd todos/
[root@localhost todos]# meteor bundle bundle.tgz
将bundle.tgz 复制到/目录下解压
[root@localhost /]# tar xf bundle.tgz
在/ 目录下多了个 bundle的目录
运行 node bundle/main.js

使用forever 保证服务一直运行 ,可以省去 tumx 和 screen nohup等命令 
forever start bundle/main.js
-l 选项可以指定日志输出目录
 
查看有哪些服务是通过forever运行的
forever list
info:    Forever processes running
data:        uid  command                                     script          forever pid   logfile                 uptime       
data:    [0] agGu /usr/local/node-v0.10.26-linux-x64/bin/node /bundle/main.js 27071   27604 /root/.forever/agGu.log 0:0:22:25.852
 
停止某个服务
[root@localhost /]# forever stop 0
info:    Forever stopped process:
data:        uid  command                                     script          forever pid   logfile                 uptime      
[0] agGu /usr/local/node-v0.10.26-linux-x64/bin/node /bundle/main.js 27071   27604 /root/.forever/agGu.log 0:0:23:7.356


forever命令可以把终端(server端)里面的输出信息写入到日志文件里面:

可以通过对Meteor.Collection进行扩展输出mongo操作信息

在server端文件中加入下列代码可以查看所有的表 查询参数:

方便用来查询mongo错误信息
Meteor.startup(function () {
    var wrappedFind = Meteor.Collection.prototype.find;

    console.log(‘START::::::查询方法日志信息 + new Date() ‘);
   
    Meteor.Collection.prototype.find = function () {
      console.log(this._name + '.find', JSON.stringify(arguments))
      return wrappedFind.apply(this, arguments);
    }
    console.log(‘END::::::查询方法日志信息 + new Date() ‘);
}) 

原文地址:https://www.cnblogs.com/w3cjiangtao/p/3708302.html