惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Stack Overflow Blog
Stack Overflow Blog
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
Recent Announcements
Recent Announcements
Vercel News
Vercel News
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
U
Unit 42
F
Fortinet All Blogs
量子位
A
About on SuperTechFans
博客园 - 司徒正美
V
V2EX
GbyAI
GbyAI
S
SegmentFault 最新的问题
博客园_首页
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

mafeifan 的编程技术分享

mafengwo-mp3-downloader | mafeifan 的编程技术分享 示例页面 | mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 查看 default namespace 下的 default service account名称 mafeifan 的编程技术分享 检查日志 | mafeifan 的编程技术分享 bridge fdb show dev flannel.1 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享
mafeifan 的编程技术分享
2026-01-16 · via mafeifan 的编程技术分享

2018-04-12 更新pm2的权限问题

PM2 的功能不多做介绍了,总之使用简单,功能强大。 今天实现了本地自动部署node项目到服务器的流程。简单总结下几个注意点。 建议先看 文档

  1. 先要保证要部署的服务器上(以下简称server)能直接ssh拉仓库代码,比如 git clone git@gitee.com:finley/demo.git。不行的话配下server生成ssh-key,然后把public key存到代码仓库服务商,比如coding.net, github。
  2. 权限问题,比如服务器的登录用户是ubuntu,将来项目要部署在/home/ubuntu下面,可以执行下 sudo chown ubuntu:ubuntu /home/ubuntu/.pm2/* 不然可能会部署失败。
  3. 部署成功后会在配置的项目路径里出现以下三个目录:

current -- 当前服务运行的文件夹(是source的软链接) share -- log pid 等共享数据 source -- clone 下来的源代码

  1. 配置脚本
module.exports = {
  /**
   * Application configuration section
   * http://pm2.keymetrics.io/docs/usage/application-declaration/
   */
  apps : [
    {
      name      : 'NODE-API',
      script    : 'server.js',
      // 这里是公共变量
      env: {
          SERVER_PORT: 8081,
      },
      env_development: {
        NODE_ENV: 'development',
      },
      env_production : {
        NODE_ENV: 'production',
      }
    }
  ],

  /**
   * Deployment section
   * http://pm2.keymetrics.io/docs/usage/deployment/
   */
  deploy : {
    // 项目信息
    // 下面的配置是我用什么用户登录哪个服务器,从哪拉代码,项目存到什么位置。拉完执行的脚本是啥
    'master' : {
      user : 'ubuntu',
      // 写成数组,可以同时部署到多台服务器
      host : '119.254.xxx.xxx',
      ref  : 'origin/master',
      repo : 'ssh://git@demo.com/demo.git',
      // 项目的存放地址,会生成current, source, share目录
      path : '/home/ubuntu/node-project',
      // "ssh_options": ["StrictHostKeyChecking=no", "PasswordAuthentication=no"],
      "post-deploy" : 'npm install && pm2 startOrRestart ecosystem.config.js --env production'
    }
  }
};
  1. 执行命令, 如果是windows,在CMD中执行没用,建议在 git bash下执行。 先初始化下,这里会尝试远程登录服务器并建立项目目录,如果失败通常是ssh问题。 所以先在服务器上试试git clone能否成功,如果拉不下来,考虑服务器防火墙限制或ssh配置 pm2 deploy ecosystem.config.js master setup 这个命令只是拉仓库代码 pm2 deploy ecosystem.config.js master 这个命令会执行 配置文件的 post-deploy 部分,最终运行项目

pm2 reload 和pm2 restart 有啥区别 ​

官方说明:As opposed to restart, which kills and restarts the process, reload achieves a 0-second-downtime reload. 简单理解: restart = stop+start reload 会更优雅一些 具体用哪个要根据项目运行实际情况,有些项目需要7*24运行,不得stop,这时候用reload比较好。

权限问题 ​

使用 sudo pm2 start ecosystem.config.jspm2 start ecosystem.config.js 启动项目是有区别的,前者用户可能是root,后者是当前用户。建议不加sudo启动。我们在服务器上操作pm2 list, pm2 logs非常频繁。如果非得加sudo和密码才能成功。 可以 sudo visudo 然后追加ubuntu ALL=(ALL) NOPASSWD:ALL ubuntu 是不希望输入密码的用户名。