【问题标题】:Pm2 startup issue with CENTOS 8 / SELinuxCENTOS 8 / SELinux 的 Pm2 启动问题
【发布时间】:2020-06-07 03:01:28
【问题描述】:

请问,您知道如何解决此问题吗? 我到处找都没找到。

06:45 SELinux is preventing systemd from open access on the file /root/.pm2/pm2.pid. For complete SELinux messages run: sealert -l d84a5a0b-cfcf-4cb9-918a-c0952bf70600 setroubleshoot

06:45 pm2-root.service: Can't convert PID files /root/.pm2/pm2.pid O_PATH file descriptor to proper file descriptor: Permission denied systemd 2 

06:45 Failed to start PM2 process manager.

我已经执行了这个命令: sealert -l d84a5a0b-cfcf-4cb9-918a-c0952bf70600 setroubleshoot

Messages d'audit bruts 
type=AVC msg=audit(1591498085.184:7731): avc:  denied  { open } for  pid=1 comm="systemd" path="/root/.pm2/pm2.pid" dev="dm-0" ino=51695937 scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:admin_home_t:s0 tclass=file permissive=0

PM2 版本:4.4.0 节点版本:12.18.0 CentOS 版本:8

我的系统服务:

[Unit]
Description=PM2 process manager
Documentation=https://pm2.keymetrics.io/
After=network.target

[Service]
Type=forking
User=root
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Environment=PATH=/sbin:/bin:/usr/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/root/.pm2
PIDFile=/root/.pm2/pm2.pid
Restart=on-failure

ExecStart=/usr/lib/node_modules/pm2/bin/pm2 resurrect
ExecReload=/usr/lib/node_modules/pm2/bin/pm2 reload all
ExecStop=/usr/lib/node_modules/pm2/bin/pm2 kill

[Install]
WantedBy=multi-user.target

谢谢

【问题讨论】:

  • 我遇到了完全相同的问题。你解决了吗?
  • 永远使用...
  • 是的,我也考虑过...但是我还没有完成。我目前正在研究如何解除 SELinux 限制。这似乎是可能的,因为它是针对类似问题完成的:digitalocean.com/community/tutorials/…。不过,该命令有点神秘:chcon -vR system_u:object_r:httpd_sys_content_t:s0 /var/www/your_domain/
  • 我终于找到了...我在这里发布答案

标签: pm2 selinux centos8


【解决方案1】:

正如 cmets 中所说,我有 exact same issue

要解决此问题,只需在尝试启动 PM2 服务后以 root 身份运行以下命令(在您的情况下,此启动尝试将是 systemctl start pm2-root

ausearch -c 'systemd' --raw | audit2allow -M my-systemd
semodule -i my-systemd.pp

这看起来很普通,但它确实有效。这些行是 SELinux 本身提出的。为了得到它们,我必须在尝试启动服务后运行命令journalctl -xe

【讨论】:

    【解决方案2】:

    两种选择:

    1. 编辑以pm2 开头的systemd 文件并为pm2 PIDFile 指定替代位置。您必须进行两项更改,一项是告诉pm2 将 PIDFile 放在哪里,另一项是告诉systemd 在哪里查找它。用以下两行替换现有的 PIDFile 行
    Environment=PM2_PID_FILE_PATH=/run/pm2.pid
    PIDFile=/run/pm2.pid
    
    1. 创建允许此特定行为的 SELinux 规则。您可以完全按照 Backslash36 在他们的回答中建议的方式执行此操作。如果您想自己创建策略文件而不是通过audit2allow,以下应该可以工作,但您必须自己将其编译为可用的 .pp 文件。
    module pm2 1.0;
    
    require {
            type user_home_t;
            type init_t;
            class file read;
    }
    
    #============= init_t ==============
    allow init_t user_home_t:file read;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-26
      • 2018-03-04
      • 2017-08-28
      • 2015-10-20
      • 1970-01-01
      • 2018-04-26
      • 2020-02-17
      • 1970-01-01
      相关资源
      最近更新 更多