将 Meteor 应用程序从 OS X 部署到 Linux 会导致 bcrypt 问题

2024-04-17

我刚刚部署了我的第一个生产 Meteor 应用程序,但遇到了一个非常严重的问题。当我尝试运行我的应用程序时,出现以下错误:

/home/hiapp/bundle/programs/server/node_modules/fibers/future.js:173
                        throw(ex);
                              ^
Error: /home/hiapp/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/build/Release/bcrypt_lib.node: invalid ELF header
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at bindings (/home/hiapp/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/node_modules/bindings/bindings.js:74:15)
    at Object.<anonymous> (/home/hiapp/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/bcrypt.js:1:97)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

通过一些研究,问题似乎在于 bcrypt 是特定于平台的,并且因为我的开发是在 OS X 10.10 上,但我的生产服务器是在 Ubuntu 14.04 上,所以问题就在这里。我的解决方法是运行npm install bcrypt从programs/server文件夹中,然后从programs/server/node_modules/bcrypt to programs/server/npm。这似乎有很多手动步骤。

我正要重新部署我的应用程序并进行一些修复,我担心我将不得不再次执行相同的步骤。有没有更好的方法来部署 Meteor 应用程序而不会遇到此问题?目前我的程序是:

  1. Run meteor build
  2. scp 将生成的 tarball 发送到我的服务器(Digital Ocean)
  3. 在我的应用程序用户主目录中分解 tarball
  4. 添加的步骤:重新编译 bcrypt 并复制目录,如上所述

我猜测自动刷新将会被破坏,因为服务器第一次尝试加载新库时,它会在火热的荣耀中爆炸。是否最好简单地克隆服务器上的 GIT 存储库并直接从那里进行构建,或者我可以使用mup或任何其他工具可以帮助简化部署过程?


有两种方法可以解决这个耗时的问题,这完全取决于您的部署方式。

手动部署

If you are manually deploying your app then make sure that you are using node v0.10.361 and only that. Meteor does not work well with node v0.12.x. More specifically, the fibers module causes a lot of problems, it chokes on various errors2.

The following is the procedure that fixed it for me3, 4:

  1. 从中删除 bcrypt 模块npm目录:

    $ cd path_to_your_app/bundle/programs/server
    $ rm -rf npm/npm-bcrypt/node_modules/bcrypt/
    
  2. 将 bcrypt 模块安装到node_modules首先目录。这将针对服务器的操作系统构建 bcrypt:

    $ npm install bcrypt
    
  3. 将新创建的 bcrypt 模块移入npm目录:

    $ cp -r node_modules/bcrypt npm/npm-bcrypt/node_modules/bcrypt
    
  4. Finally, restart the app, mogodb and any web server processes such as nginx6, through upstart if you have it configured. Under the heading sanity steps below you can perform if the steps outlined above have not fixed it for you.

使用 Meteor Up (mup)

如果您使用 mup 那么这个过程会容易得多,正如该线程上的其他答案所指出的那样。然而,在某些情况下仍然会出现错误,包括invalid ELF header错误。确保您拥有最新版本的 mupnpm update mup -g.

  1. 第一步是删除任何预先存在的应用程序和 Nodejs 包。 Mup 将应用程序安装到/opt/在那里你可以找到your_app and nodejs。删除它们。

  2. Verify that you have the correct node version, 0.10.36 only1 and the following settings, in the mup.json file:

    {
    
     ...
    
      "setupMongo": true,
      "setupNode": true,
      "nodeVersion" : "0.10.36",
      "setupPhantom": true,
      "enableUploadProgressBar": true,
    
      // Application name (No spaces)
      "appName": "your_app",
    
      // Location of app (local directory)
      "app": ".",
    
     ...
    
    }
    
  3. Run:

    $ mup setup
    $ mup deploy
    
  4. 导航至server服务器上的文件夹并重建模块:

    $ cd /opt/your_app/app/programs/server
    $ npm rebuild
    $ npm install
    

    选修的:$ sudo npm update node-gyp -g

  5. Finally, restart the app, mogodb and any web server processes such as nginx6. After the above steps, you may want to look at sanity steps below for more debugging options.


理智步骤

您还可以执行其他一些步骤:

  • 请注意,apache 也可能将自己绑定到 nginx 运行的同一端口。查看应用程序的错误日志和网络服务器的错误日志,看看是否存在任何问题。通过停止阿帕奇sudo service apache2 stop or 暴力关闭 https://stackoverflow.com/a/9346231/3526705(不推荐)端口 80 上任何正在运行的进程。

    • 然后删除或移动 apache2 conf 文件以防止其再次启动。所有conf文件位于/etc/init or /etc/init.d.
  • Use $ mup logs -f查看 mup 日志。要查看应用程序中的错误,请查看文件末尾,/var/log/upstart/your_app.log很有用(假设您已经配置了 upstart)。

  • 如果使用 nginx,请确保您的目录已符号链接。

    $ ln -s /etc/nginx/sites-available/your_server_config /etc/nginx/sites-enabled/your_server_config
    

    Moreover, make sure that you have specified a default_server5 in your_server_config.

  • 检查 mongodb 是否可以运行。


参考

  1. Meteor 版本 1.0.4.1(于 2015 年 3 月底发布)要求安装节点版本 0.10.36。我建议使用节点版本管理器,n https://github.com/tj/n,随时控制服务器上运行的节点版本。Link https://github.com/arunoda/meteor-up/issues/349.

  2. 可怕的[XXX.XX.XXX.XX] Error: '/opt/your_app/programs/server/node_modules/fibers/bin/linux-x64-v8-3.28/fibers.node' is missing. Try reinstalling 'node-fibers'? error. Link https://github.com/arunoda/meteor-up/issues/332.

  3. 该过程从此处修改:Link https://stackoverflow.com/a/26173194/3526705.

  4. 为了供您参考,我使用了 DigitalOcean 关于将 Meteor 应用程序部署到服务器的非常有用的指南。Link https://www.digitalocean.com/community/tutorials/how-to-deploy-a-meteor-js-application-on-ubuntu-14-04-with-nginx.

  5. 指定一个default_server. Link http://blog.gahooa.com/2013/08/21/nginx-how-to-specify-a-default-server/.

  6. 常见的重启进程有:sudo service mongod/nginx/yourapp restart.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 Meteor 应用程序从 OS X 部署到 Linux 会导致 bcrypt 问题 的相关文章

随机推荐