启动

时间:2017-09-02 02:46:34

标签: linux apache server centos

我在CentOS 7中安装了httpd 2.4.27。我将httpd.service配置为systemd服务。但每次我在启动后 PID文件/usr/local/apache2/logs/httpd.pid都不可读(但是?)。当我启动或重启httpd.service时。

这是我对httpd.service的配置:

[root@localhost ~]# cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=forking
ExecStart=/usr/local/apache2/bin/apachectl -k start
ExecReload=/usr/local/apache2/bin/apachectl -k graceful
ExecStop=/usr/local/apache2/bin/apachectl -k graceful-stop
PIDFile=/usr/local/apache2/logs/httpd.pid
PrivateTmp=true

[Install]
WantedBy=multi-user.target
[root@localhost ~]# 

以下是错误信息:

[root@localhost ~]# systemctl start httpd.service
[root@localhost ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2017-09-01 22:30:48 EDT; 1s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 2173 ExecStart=/usr/local/apache2/bin/apachectl -k start (code=exited, status=0/SUCCESS)
 Main PID: 2176 (httpd)
   CGroup: /system.slice/httpd.service
           ├─2176 /usr/local/apache2/bin/httpd -k start
           ├─2177 /usr/local/apache2/bin/httpd -k start
           ├─2178 /usr/local/apache2/bin/httpd -k start
           └─2179 /usr/local/apache2/bin/httpd -k start

Sep 01 22:30:47 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Sep 01 22:30:48 localhost.localdomain systemd[1]: PID file /usr/local/apache2/logs/httpd.pid not readable (yet?) after start.
Sep 01 22:30:48 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
[root@localhost ~]# 

以下是httpd.pid文件的权限:

[root@localhost ~]# ll /usr/local/apache2/logs/
total 8
-rw-r--r--. 1 root root    0 Sep  1 20:46 access_log
-rw-r--r--. 1 root root 3270 Sep  1 22:30 error_log
-rw-r--r--  1 root root    5 Sep  1 22:30 httpd.pid
[root@localhost ~]# 

我发现没有必要手动更改httpd.pid文件的权限,因为当服务停止时,该文件将被自动删除。一旦打开服务,就会生成新的httpd.pid文件。

注意:我看到一些帖子说更新/usr/lib/tmpfiles.d/httpd.conf会起作用。但是因为我从源代码安装了apache,所以我没有这个文件。我认为只有&yum安装httpd'有这个。

任何人都可以提供帮助?我只想要一个干净的服务开始,没有错误或警告。感谢。

1 个答案:

答案 0 :(得分:0)

您可以设置/lib/tmpfiles.d/httpd.conf跟随:

d /usr/local/apache2/logs/httpd.pid 700 apache apache