ApacheはローカルネットワークのCentOSでは起動しません。

ApacheはローカルネットワークのCentOSでは起動しません。

CentOS 7サーバーにhttpdをインストールしましたsystemctl start httpd.serviceが失敗しました。

httpdCentOS 7で正しく起動するには、どの特定のコマンドシーケンスを入力する必要がありますか?


エラーメッセージ

下部の結果全体から抽出された正確なエラーメッセージは次のとおりです。

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain.   
Set the 'ServerName' directive globally to suppress this message  

また、@DopeGhotiが提案したように、ログの内容は次のとおりです。

[root@localhost ~]# vi /var/log/httpd/error_log
(13)Permission denied: AH00091: httpd: could not open error log file /var/www/mytestdeployment/error.log.
AH00015: Unable to open logs
(13)Permission denied: AH00091: httpd: could not open error log file /var/www/mytestdeployment/error.log.
AH00015: Unable to open logs
(13)Permission denied: AH00091: httpd: could not open error log file /var/www/mytestdeployment/error.log.


インストール方法httpd

1.) Apacheをインストールします:

sudo yum -y install httpd

2.)再起動時に自動的に再起動するようにApacheをCentOSサービスとして有効にします。

sudo systemctl enable httpd.service

3.) ファイアウォールの構成

sudo firewall-cmd --zone=public --add-service=http
sudo firewall-cmd --list-all
sudo firewall-cmd --zone=public --permanent --add-service=http  

4.) サーバ名を指定します。

vi /etc/httpd/conf/httpd.conf
//Uncomment the ServerName line and give it the IP of the machine:  
ServerName 192.168.1.5:80


エラーメッセージ:

httpd上記のコマンドを使用してインストールした後、httpd次のように起動できません。

[root@localhost ~]# systemctl start httpd.service
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.


[root@localhost ~]# systemctl status httpd.service -l
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2017-06-06 11:31:32 PDT; 15min ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 32268 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
  Process: 32267 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 32267 (code=exited, status=1/FAILURE)

Jun 06 11:31:32 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Jun 06 11:31:32 localhost.localdomain httpd[32267]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
Jun 06 11:31:32 localhost.localdomain systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Jun 06 11:31:32 localhost.localdomain kill[32268]: kill: cannot find process ""
Jun 06 11:31:32 localhost.localdomain systemd[1]: httpd.service: control process exited, code=exited status=1
Jun 06 11:31:32 localhost.localdomain systemd[1]: Failed to start The Apache HTTP Server.
Jun 06 11:31:32 localhost.localdomain systemd[1]: Unit httpd.service entered failed state.
Jun 06 11:31:32 localhost.localdomain systemd[1]: httpd.service failed.
[root@localhost ~]# systemctl status httpd.service -l

[root@localhost ~]# vi /var/log/httpd/error_log
(13)Permission denied: AH00091: httpd: could not open error log file /var/www/mytestdeployment/error.log.
AH00015: Unable to open logs
(13)Permission denied: AH00091: httpd: could not open error log file /var/www/mytestdeployment/error.log.
AH00015: Unable to open logs
(13)Permission denied: AH00091: httpd: could not open error log file /var/www/mytestdeployment/error.log.
AH00015: Unable to open logs
(13)Permission denied: AH00091: httpd: could not open error log file /var/www/mytestdeployment/error.log.
AH00015: Unable to open logs
(13)Permission denied: AH00091: httpd: could not open error log file /var/www/mytestdeployment/error.log.
AH00015: Unable to open logs
~
"/var/log/httpd/error_log" 10L, 675C


@JeffSchallerの提案

setenforce 0@JeffSchallerがSELinuxを検討することを提案した後、rootとして入力すると、次のような結果が発生することがわかりました。

[root@localhost ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28

[root@localhost ~]# setenforce 0

[root@localhost ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28

[root@localhost ~]# systemctl start httpd.service -l
[root@localhost ~]# systemctl status httpd.service -l
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2017-06-06 12:28:38 PDT; 22s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 32577 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
 Main PID: 32690 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─32690 /usr/sbin/httpd -DFOREGROUND
           ├─32691 /usr/sbin/httpd -DFOREGROUND
           ├─32692 /usr/sbin/httpd -DFOREGROUND
           ├─32693 /usr/sbin/httpd -DFOREGROUND
           ├─32694 /usr/sbin/httpd -DFOREGROUND
           └─32695 /usr/sbin/httpd -DFOREGROUND

Jun 06 12:28:38 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Jun 06 12:28:38 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
[root@localhost ~]#

ベストアンサー1

Apacheを起動できません。エラーメッセージ

(13)権限が拒否されました:AH00091:httpd:エラーログファイル/var/www/mytestdeployment/error.logを開くことができません。

AH00015: ログをオープンできません。

SELinux は強制モードになっているため、Apache が標準以外のログディレクトリに書き込むのを防ぎます。維持するためにダンウォルシュが泣くそして医療コード効果的にこのディレクトリにhttpd_log_tポリシーを適用できます。

semanage fcontext -a -t httpd_log_t "/var/www/mytestdeployment(/.*)?"
restorecon -Rv /var/www/mytestdeployment

そして確認してください:

ls -lZ /var/www/mytestdeployment

semanage ユーティリティがない場合は、次のコマンドを使用してインストールできます。

yum install policycoreutils-python

おすすめ記事