每次启动时,Apache的PidFile目录都会被删除。

每次服务器重新启动时,目录/run/httpd都会被删除。/run是一个tmpfs文件系统,因此在RAM中挂载。 /run/httpd只在安装过程中创建。当我在重新启动后启动httpd时,该目录不会被重新创建。 服务器已安装CentOS 7和官方仓库的Apache软件包(版本2.4.6-18)。 在安装和启动Apache之后,目录如下所示:
# ls -alR /run/httpd/
/run/httpd/:
total 8
drwx--x---.  3 root   apache  120 Sep 30 08:39 .
drwxr-xr-x. 28 root   root   1020 Sep 30 08:37 ..
-rw-r--r--.  1 root   root      8 Sep 30 08:39 authdigest_shm.2953
drwx------.  2 apache apache   40 Jul 23 10:48 htcacheclean
-rw-r--r--.  1 root   root      5 Sep 30 08:39 httpd.pid
srwx------.  1 apache root      0 Sep 30 08:39 wsgi.2953.0.1.sock

/run/httpd/htcacheclean:
total 0
drwx------. 2 apache apache  40 Jul 23 10:48 .
drwx--x---. 3 root   apache 120 Sep 30 08:39 ..
但是重新启动后:
# ls -l /run/httpd
ls: cannot access /run/httpd: No such file or directory
以下是尝试重新启动Apache时的日志记录: /var/log/httpd/error_log
[Tue Sep 30 09:30:32.310825 2014] [core:notice] [pid 3370] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[Tue Sep 30 09:30:32.312072 2014] [suexec:notice] [pid 3370] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Tue Sep 30 09:30:32.330380 2014] [auth_digest:notice] [pid 3370] AH01757: generating secret for digest authentication ...
[Tue Sep 30 09:30:32.330421 2014] [auth_digest:error] [pid 3370] (2)No such file or directory: AH01762: Failed to create shared memory segment on file /run/httpd/authdigest_shm.3370
[Tue Sep 30 09:30:32.330440 2014] [auth_digest:error] [pid 3370] (2)No such file or directory: AH01760: failed to initialize shm - all nonce-count checking, one-time nonces, and MD5-sess algorithm disabled
[Tue Sep 30 09:30:32.330445 2014] [:emerg] [pid 3370] AH00020: Configuration Failed, exiting
Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.

/var/log/message

Sep 30 08:56:09 brejetuba2 systemd: Starting The Apache HTTP Server...
Sep 30 08:56:09 brejetuba2 systemd: httpd.service: main process exited, code=exited, status=1/FAILURE
Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.
Sep 30 08:56:09 brejetuba2 systemd: Failed to start The Apache HTTP Server.
Sep 30 08:56:09 brejetuba2 systemd: Unit httpd.service entered failed state.

/var/log/audit/audit.log

Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.
type=SERVICE_START msg=audit(1412083740.602:469): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg=' comm="httpd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=failed'
当我手动创建目录时,Apache就会启动。
# mkdir /run/httpd
# systemctl restart httpd
# ls -lRa /run/httpd/
/run/httpd/:
total 8
drwxr-xr-x.  2 root   root  100 Sep 30 09:36 .
drwxr-xr-x. 28 root   root 1020 Sep 30 09:36 ..
-rw-r--r--.  1 root   root    8 Sep 30 09:36 authdigest_shm.3452
-rw-r--r--.  1 root   root    5 Sep 30 09:36 httpd.pid
srwx------.  1 apache root    0 Sep 30 09:36 wsgi.3452.0.1.sock
重启后,它又消失了。 你对这是为什么有什么想法吗?

我遇到了一个非常类似的问题,而且在这里报告的错误在2017年被修复了 https://bz.apache.org/bugzilla/show_bug.cgi?id=54622。我能够手动删除 apache 报错的 _shm.* 文件,并解决了这个问题。 - Shyam Habarakada
3个回答

问题是,在安装Apache时,组apache没有被创建。
# systemctl status systemd-tmpfiles-setup.service
systemd-tmpfiles-setup.service - Create Volatile Files and Directories
  Loaded: loaded (/usr/lib/systemd/system/systemd-tmpfiles-setup.service; static)
  Active: failed (Result: exit-code) since Tue 2014-09-30 09:40:30 EDT; 3h 24min ago
Docs: man:tmpfiles.d(5)
      man:systemd-tmpfiles(8)
  Process: 724 ExecStart=/usr/bin/systemd-tmpfiles --create --remove --boot --exclude-prefix=/dev (code=exited, status=1/FAILURE)
Main PID: 724 (code=exited, status=1/FAILURE)

Sep 30 09:40:30 servername systemd-tmpfiles[724]: [/usr/lib/tmpfiles.d/httpd.conf:1] Unknown group 'apache'.
Sep 30 09:40:30 servername systemd-tmpfiles[724]: [/usr/lib/tmpfiles.d/httpd.conf:2] Unknown user 'apache'.
Sep 30 09:40:30 servername systemd[1]: systemd-tmpfiles-setup.service: main process exited, code=exited, status=1/FAILURE
Sep 30 09:40:30 servername systemd[1]: Failed to start Create Volatile Files and Directories.
Sep 30 09:40:30 servername systemd[1]: Unit systemd-tmpfiles-setup.service entered failed state.
这是因为我配置了一个NIS服务器,其中有一个NIS apache用户。由于它有一个apache用户,Apache安装不会创建apache组。但是apache组也存在于NIS中!嗯,NIS搞砸了事情。 底线是:我必须停止ypbind,安装Apache然后重新启动ypbind(或者在/etc/group中手动创建一个apache组)。

我遇到了同样的问题,但解决方法稍有不同。

使用@joaoolavo的解决方案,我尝试了systemctl status systemd-tmpfiles-setup.service

[root@server ~]# systemctl status systemd-tmpfiles-setup.service
● systemd-tmpfiles-setup.service - Create Volatile Files and Directories
   Loaded: loaded (/usr/lib/systemd/system/systemd-tmpfiles-setup.service; static; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:tmpfiles.d(5)
           man:systemd-tmpfiles(8)
请注意:Active: inactive(已停止)。 重新启动systemd-tmpfiles-setup会在/run/目录下创建我所需的文件,并且状态变为Active: active(已退出),尽管显然httpd(以及在我的情况下,postgresql)并未加载:
[root@server ~]# systemctl start systemd-tmpfiles-setup.service
[root@server ~]# systemctl status systemd-tmpfiles-setup.service
● systemd-tmpfiles-setup.service - Create Volatile Files and Directories
   Loaded: loaded (/usr/lib/systemd/system/systemd-tmpfiles-setup.service; static; vendor preset: disabled)
   Active: active (exited) since Fri 2016-03-18 13:35:36 AEDT; 8s ago
     Docs: man:tmpfiles.d(5)
           man:systemd-tmpfiles(8)
  Process: 2551 ExecStart=/usr/bin/systemd-tmpfiles --create --remove --boot --exclude-prefix=/dev (code=exited, status=0/SUCCESS)
 Main PID: 2551 (code=exited, status=0/SUCCESS)

Mar 18 13:35:36 server.org systemd[1]: Starting Create Volatile Files and Directories...
Mar 18 13:35:36 server.org systemd[1]: Started Create Volatile Files and Directories.
能在重启后继续运行吗? 是的,它可以。事实上,现在重新启动后会按照我们的预期进行 - 所有临时文件都被创建,httpd和postgresql也会启动。 看起来,systemd-tmpfiles-setup.service需要处于活动状态active (exited),而不是inactive (dead),以便在启动后正常工作。

我对我的问题有与@datakid相同的解决方案,不同之处在于重新启动后systemd-tmpfiles-setup.service又挂了。

对于我的解决方案,你首先需要知道我将/var目录挂载到了另一块磁盘上。问题就出在这里。 我的/etc/fstab文件中关于/var的条目如下:

/dev/xvdb1 /var ext4 defaults,noatime,_netdev,nofail 0 2
所以问题是_netdev。因为这对于需要网络但不适用于我的情况下的NFS可能很有用,/var目录。 以下是_netdev的解释: 文件系统驻留在需要网络访问的设备上(用于防止系统在启用系统上的网络之前尝试挂载这些文件系统)。 我移除了_netdev后,一切都恢复正常,即使重新启动也是如此。

在RHEL系统上运行时,应该使用tmpfs,因此涉及到/var的“修复”是一个误导。 - DaveG