# 部屬筆記
## PM2常見指令
pm2 start //啟動 pm2 → ecosystem.config.js
pm2 list //查看目前有架多少站台
pm2 delete 3 //刪除id為3的站台
pm2 delete all //刪除所有站台
pm2 reload all //重新整理所有站台
pm2 save //儲存目前的pm2 站台,重開機後會還原
pm2 log //pm2出錯時擬難排除
## PM2指定打包環境 方法1
pm2 start --env prod
``` js
module.exports = {
apps: [{
name: 'jim_nuxt',
script: './node_modules/nuxt-start/bin/nuxt-start.js',
instances: 'max', // 負載平衡模式下的 cpu 數量
exec_mode: 'cluster', // cpu 負載平衡模式
max_memory_restart: '1G', // 緩存了多少記憶體重新整理
port: 3001, // 指定伺服器上的 port
env_prod: {
//此處可以覆寫
"name": 'jim_nuxt_prod',
"PORT": 3001, //指定伺服器上的 port
"NODE_ENV": "prod"
},
}]
};
```
## PM2指定打包環境 方法2
pm2 start --only jim_nuxt_prod
``` js
module.exports = {
apps: [{
name: 'jim_nuxt_prod',
script: './node_modules/nuxt-start/bin/nuxt-start.js',
instances: '1', //負載平衡模式下的 cpu 數量
exec_mode: "cluster", //cpu 負載平衡模式
max_memory_restart: '1G', //緩存了多少記憶體重新整理
port: 3001, //指定伺服器上的 port
time: true,
env: {
NODE_ENV: "prod"
}
}]
};
```
## PM2無法使用NPM指令問題(bash: npm: command not found)
打開.bashrc檔案
``` sh=
sudo nano .bashrc
```
找到
```sh
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
```
接著把這四行都註解掉
```sh
# If not running interactively, don't do anything
#case $- in
# *i*) ;;
# *) return;;
#esac
```