我正在将应用程序转换为以cluster_mode运行。在添加了必要的生态系统.config.js文件后,由于权限被拒绝错误,应用程序无法启动:
Error: EACCES: permission denied, open '/home/node/.pm2/logs/appplication-25.log'
[2019-08-06 09:48:55] PM2 log: App name:application id:25 disconnected
[2019-08-06 09:48:55] PM2 log: App [application] with id [25] and pid [18291], exited with code [1] via signal [SIGINT]
[2019-08-06 09:48:55] PM2 log: Starting execution sequence in -cluster mode- for app name:application id:25
[2019-08-06 09:48:55] PM2 log: App name:application id:24 online
[2019-08-06 09:48:55] PM2 log: App name:application id:25 online
/usr/lib/node_modules/pm2/lib/ProcessContainer.js:202
throw err;
^
PM2 God Daemon以root用户身份运行。超级用户还拥有$ PM2_HOME / logs目录。
$ ls -al /home/node/.pm2
total 328
drwxr-xr-x. 5 root root 199 Aug 6 09:48 .
drwxr-x---. 5 node node 66 Aug 5 15:20 ..
-rw-r--r-- 1 root root 112548 Aug 6 08:29 dump.pm2
-rw-r--r-- 1 root root 112562 Aug 2 11:43 dump.pm2.bak
drwxr-xr-x. 2 root root 32768 Aug 6 03:07 logs
-rw-r--r--. 1 root root 312 Apr 23 12:04 module_conf.json
drwxr-xr-x. 3 root root 27 Apr 23 12:04 modules
drwxr-xr-x. 2 root root 4096 Aug 6 09:48 pids
-rw-r--r--. 1 root root 51170 Aug 6 09:48 pm2.log
-rw-r--r-- 1 root root 4 Aug 5 15:19 pm2.pid
srwxrwxr-x 1 root root 0 Aug 5 15:19 pub.sock
-rw-r--r-- 1 root root 0 Aug 6 09:48 reload.lock
srwxrwxr-x 1 root root 0 Aug 5 15:19 rpc.sock
-rw-r--r--. 1 root root 13 Jul 26 2018 touch
ecosystem.config.js
module.exports = {
apps : [{
name: 'application',
script: 'index.js',
instances: 2,
exec_mode: 'cluster_mode',
}]
};
应用程序已经在fork模式下运行良好。要测试集群模式,我运行了:
pm2 delete application
pm2 start ecosystem.config.js --uid node
结果:
--- PM2 list -----------------------------------------------
┌───────────────────────────┬────┬─────────┬──────┬─────────┬─────────┬────────┬─────┬────────────┬──────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├───────────────────────────┼────┼─────────┼──────┼─────────┼─────────┼────────┼─────┼────────────┼──────┼──────────┤
│ application │ 25 │ cluster │ 0 │ errored │ 45 │ 0 │ 0% │ 0 B │ node │ disabled │
│ application │ 24 │ cluster │ 0 │ errored │ 45 │ 0 │ 0% │ 0 B │ node │ disabled │
将组写权限添加到logs目录,例如chmod 775 $PM2_HOME/logs
,允许对日志进行写访问,但是我不确定为什么。
使用Node.js v8.94和PM2 v2.10.3