每次启动都会删除 Apache 的 PidFile 目录

Joã*_*los 12 apache-2.4 centos7

每次重新启动服务器时,都会删除目录 /run/httpd。/run 是一个 tmpfs 文件系统,因此安装在 RAM 中。

/run/httpd 仅在安装期间创建。重新启动后启动 httpd 时,不会重新创建该目录。

服务器已安装 CentOS 7 和官方存储库 Apache 包(v. 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 ..
Run Code Online (Sandbox Code Playgroud)

但是重启后:

# ls -l /run/httpd
ls: cannot access /run/httpd: No such file or directory
Run Code Online (Sandbox Code Playgroud)

以下是尝试重新启动 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.
Run Code Online (Sandbox Code Playgroud)

/var/日志/消息

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.
Run Code Online (Sandbox Code Playgroud)

/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'
Run Code Online (Sandbox Code Playgroud)

当我手动创建目录时,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
Run Code Online (Sandbox Code Playgroud)

然后重启后又没了。

关于为什么会发生这种情况的任何想法?

Joã*_*los 8

问题是,在安装 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.
Run Code Online (Sandbox Code Playgroud)

那是因为我配置了 NIS 服务器,其中有一个 NIS apache用户。因为它有一个apache用户,所以 Apache 安装不会创建apache组。但是apache组也存在于 NIS 上!好吧,NIS 把事情搞砸了。

底线是:我必须停止 ypbind,安装 Apache,然后重新启动 ypbind(或者只是在 /etc/group 中手动创建一个apache组)。