bundle + forever部署Meteor App

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

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

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端文件中加入下列代码能够查看全部的表 查询参数:java

方便用来查询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() ‘);
}) node

相关文章
相关标签/搜索