部署NodeJS上线步骤

  1、打开https://brew.sh/index_zh-cn

  2、brew search nginx brew install nginx

  3、brew info nginx

  4、nginx -v 查看nginx信息

  5、启动sudo brew services start nginx (默认端口8080)//太傻

  备注:如果你安装过Jenkins的话这里失效

  sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist

  systemctl start jenkins

  6、关闭sudo brew services stop nginx/nginx

  7、nginx -s reload、nginx -s stop //开启、关闭

  8、打开Nginx具体安装目录 查看配置文件 /usr/local/etc/nginx/

  9、验证配置文件 nginx -t -c 自己的配置文件地址

  10、拷贝配置文件至Node 项目目录 重新修改

  11、服务器端的nginx地址  

//给运维留的文件

http{
    upstream firsttest{
        server 192.168.1.1;  //需要反向代理的地址
        server 192.168.1.2;    //    需要反向代理的地址
    }
    server{
        listen:8080;
        localhost / {
            proxy_pass:http://firsttest;
        }
    }
}

  12、几条盖世绝学

    ps aux | grep node

    lsof -i tcp:8081

    kill -9 pid

    ssh 用户名@地址(免密登陆)

    scp course-map.json root@ip地址:/路径

    scp -r advance/ root@101.200.185.250:/opt/node-publish/www/static/

  13、npm install --production 只管上线环境

  14、pm2动态检测文件

    14-1 能够动态的监控文件的上传0秒热启动

    14-2 能够负载均衡 CPU

    14-3 内存的使用 过高了 CPU调度太频繁 重启。

    14-4 restart 个数

  

  pm2.json

//pm2

{

"name" : "api-app",

"script" : "./api.js",

"log_date_fromat":"YYYY-MM-DD HH:mm Z",

"out_file" : "log/node-app.stdout.log",

"instances" : "max",

"exec_mode" : "cluster"

}

1、pm2 log 查看错误

2、pm2 start pm2.json //启动

3、pm2 stop all //停止所有pm2

4、pm2 monit //监控

5、pm2 //线上监控地址https://app.keymetrics.io/

pm2命令地址参考 https://blog.csdn.net/chengxuyuanyonghu/article/details/74910875

nginx 做反向代理/负载均衡会出现一个坑

/usr/local/etc/nginx/ //目录地址

ngxin -s reload //出现这个错误
nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)
//解决方法:找到你的nginx.conf的文件夹目录,然后运行这个
nginx -c /usr/local/etc/nginx/nginx.conf命令,
再运行nginx -s reload,就可以了