Build node, pm2 environment liunx

I CenterOS server system version 7.5, vm virtual out
I was given in the installation directory under / usr / local've created a node directory (command: mkdir node) years. The full path is: / usr / local / node

1. Download the installation package from the official network node, it must be keep in mind liunx-64 bits. It previously downloaded after the node-v12.13.1-linux-arm64.tar.gz installation ./node -v prompt instead of binaries
Build node, pm2 environment liunx
Build node, pm2 environment liunx

Or can be downloaded online: wget https://nodejs.org/dist/v12.13.1/node-v12.13.1-linux-x64.tar.xz

2. Extract mounting
an xz -d-Linux-Node-v12.13.1 x64.tar.xz
the tar -xvf Node-v12.13.1-Linux-x64.tar

3. Enter the node-v12.13.1-linux-x64 directory, configuration soft link configuration
LN /usr/local/node/node-v12.13.1/bin/node -s / usr / local / bin / the Node
LN -s / usr /local/node/node-v12.13.1/bin/npm / usr / local / bin / npm
if not the first, then install -s should be changed -b
LN -b / usr / local / the Node / the Node-V12. 13.1 / bin / the Node / usr / local / bin / the Node
LN -b /usr/local/node/node-v12.13.1/bin/npm / usr / local / bin / npm

 测试安装情况:
    node -v
        npm -v

配置淘宝npm镜像http://npm.taobao.org/
由于官方镜像比较慢,直接执行以下命令,将镜像地址改为淘宝的npm镜像地址
npm config set registry https://registry.npm.taobao.org

4.安装pm2:
npm i install -g pm2
ln -s /usr/local/node/node-v12.13.1/lib/node_modules/pm2/bin/pm2 /usr/local/bin/pm2 --这一步有肯能无效在安装pm2的时候默认都按照在/usr/local/bin下了,需要检查下

pm2常用命令记录

$ pm2 start app.js # 启动app.js应用程序

$ pm2 start app.js -i 4        # cluster mode 模式启动4个app.js的应用实例

4个应用程序会自动进行负载均衡

$ pm2 start app.js --name="api" # 启动应用程序并命名为 "api"

$ pm2 start app.js --watch      # 当文件变化时自动重启应用

$ pm2 start script.sh          # 启动 bash 脚本

$ pm2 list                      # 列表 PM2 启动的所有的应用程序

$ pm2 monit                    # 显示每个应用程序的CPU和内存占用情况

$ pm2 show [app-name]          # 显示应用程序的所有信息

$ pm2 logs                      # 显示所有应用程序的日志

$ pm2 logs [app-name]          # 显示指定应用程序的日志

$ pm2 flush                       # 清空所有日志文件

$ pm2 stop all                  # 停止所有的应用程序

$ pm2 stop 0                    # 停止 id为 0的指定应用程序

$ pm2 restart all              # 重启所有应用

$ pm2 reload all                # 重启 cluster mode下的所有应用

$ pm2 gracefulReload all        # Graceful reload all apps in cluster mode

$ pm2 delete all                # 关闭并删除所有应用

$ pm2 delete 0                  # 删除指定应用 id 0

$ pm2 scale api 10              # 把名字叫api的应用扩展到10个实例

$ pm2 reset [app-name]          # 重置重启数量

$ pm2 startup                  # 创建开机自启动命令

$ pm2 save                      # 保存当前应用列表

$ pm2 resurrect                # 重新加载保存的应用列表

$ pm2 update                    # Save processes, kill PM2 and restore processes

$ pm2 generate                  # Generate a sample json configuration file

pm2文档地址:http://pm2.keymetrics.io/docs/usage/quick-start/

sudo 运行 npm或node时,出现找不到命令

sudo 运行 npm或node时,出现找不到命令的情况,运行下面这些命令, 

sudo ln -s /usr/local/bin/node /usr/bin/node

sudo ln -s /usr/local/lib/node /usr/lib/node

sudo ln -s / usr / local / bin / Elevation / usr / bin / Elevation

sudo ln -s /usr/local/bin/node-waf /usr/bin/node-waf

Guess you like

Origin blog.51cto.com/14159501/2454769