LoginSignup
0
0

More than 1 year has passed since last update.

【Apache2.4】再起動後に"Job for apache2.service failed because the control process exited with error code"と表示された場合の原因と対応方法

Posted at

概要

  • AWS EC2インスタンスのUbuntuでsudo systemctl restart apache2を実行したら下記のエラーメッセージが返されてしまった。
$ sudo systemctl restart apache2
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.
  • エラーは、apache2サービスの再起動に失敗したことを示しています。
  • VirtualHost設定を触っていた直後なので、そこに問題があるか...!?

環境

  • サーバー(AWS EC2インスタンス)
    • OS:Ubuntu 18.04.3 LTS
    • Web Server:Apache/2.4.29

解決手順は...エラーログを見ればすぐに分かる

  • エラーの原因を特定するため、以下を実行して、Apache2サービスのステータスを確認します。
$ systemctl status apache2.service
  • すると、以下のようなステータスが出てきます。
-- Unit apache2.service has begun starting up.
Mar 17 05:31:41 ip-111-22-33-444 apachectl[5303]: apache2: Syntax error on line 225 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/sites
Mar 17 05:31:41 ip-111-22-33-444 apachectl[5303]: Action 'start' failed.
Mar 17 05:31:41 ip-111-22-33-444 apachectl[5303]: The Apache error log may have more information.
Mar 17 05:31:41 ip-111-22-33-444 systemd[1]: apache2.service: Control process exited, code=exited status=1
Mar 17 05:31:41 ip-111-22-33-444 sudo[5293]: pam_unix(sudo:session): session closed for user root
Mar 17 05:31:41 ip-111-22-33-444 systemd[1]: apache2.service: Failed with result 'exit-code'.
Mar 17 05:31:41 ip-111-22-33-444 systemd[1]: Failed to start The Apache HTTP Server.
-- Subject: Unit apache2.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit apache2.service has failed.
--
-- The result is RESULT.
Mar 17 05:32:12 ip-111-22-33-444 sshd[5332]: error: maximum authentication attempts exceeded for root from 11.222.333.44 port 53103 ssh2 [preauth]
Mar 17 05:32:12 ip-111-22-33-444 sshd[5332]: Disconnecting authenticating user root 11.222.333.44 port 53103: Too many authentication failures [preauth]
Mar 17 05:32:28 ip-111-22-33-444 sshd[5334]: error: maximum authentication attempts exceeded for root from 11.222.333.44 port 53154 ssh2 [preauth]
Mar 17 05:32:28 ip-111-22-33-444 sshd[5334]: Disconnecting authenticating user root 11.222.333.44 port 53154: Too many authentication failures [preauth]
Mar 17 05:32:35 ip-111-22-33-444 sshd[5337]: error: maximum authentication attempts exceeded for root from 11.222.333.44 port 53223 ssh2 [preauth]
Mar 17 05:32:35 ip-111-22-33-444 sshd[5337]: Disconnecting authenticating user root 11.222.333.44 port 53223: Too many authentication failures [preauth]
Mar 17 05:32:43 ip-111-22-33-444 sshd[5341]: Invalid user louis from 177.11.233.149 port 4071
Mar 17 05:32:43 ip-111-22-33-444 sshd[5341]: Received disconnect from 177.11.233.149 port 4071:11: Bye Bye [preauth]
Mar 17 05:32:43 ip-111-22-33-444 sshd[5341]: Disconnected from invalid user louis 177.11.233.149 port 4071 [preauth]
Mar 17 05:32:48 ip-111-22-33-444 sshd[5339]: error: maximum authentication attempts exceeded for root from 11.222.333.44 port 53293 ssh2 [preauth]
Mar 17 05:32:48 ip-111-22-33-444 sshd[5339]: Disconnecting authenticating user root 11.222.333.44 port 53293: Too many authentication failures [preauth]
Mar 17 05:32:55 ip-111-22-33-444 sshd[5343]: error: maximum authentication attempts exceeded for root from 11.222.333.44 port 53350 ssh2 [preauth]
Mar 17 05:32:55 ip-111-22-33-444 sshd[5343]: Disconnecting authenticating user root 11.222.333.44 port 53350: Too many authentication failures [preauth]
Mar 17 05:33:02 ip-111-22-33-444 sshd[5347]: Connection closed by authenticating user root 11.222.333.44 port 53414 [preauth]
  • よく見るとSyntax Errorがあることがわかります。
apache2: Syntax error on line 225 of 
  • apache2.confの該当の行を見てみたら、<virtualhost>の1行がコメントアウトし忘れていた。こやつのせいで正常な再起動ができていなかったんですね。コメントアウトしたら無事に動くようになりました。
  • コマンド一つで行数まで正確に教えてくれるのはありがたいですね!

その他の解決方法や考えられる原因

  • エラーメッセージにあったように"journalctl -xe"を実行して、Apache2サービスに関連する詳細なログを取得することも可能です。
    • journalctl -xe: Linuxシステムのイベントログを表示するためのコマンド
    • 「-x」オプション: 各ログメッセージに対応するスタックトレース情報を表示
    • 「-e」オプション: システムログの最後の部分から表示を開始
  • 他にも、以下のような場合が原因として考えられるようです。
    • Apache2の構成にエラーがある場合
    • ポートがすでに使用されている場合
    • 必要なモジュールがインストールされていない場合
    • ファイルのアクセス権限に問題がある場合
    • システムがメモリ不足の場合
    • セキュリティ(ソフトウェア・ファイアウォールなど)の問題がある場合
    • Apache2のバージョンが古く最新のモジュールや機能が欠落している場合
  • Apache2を再インストールすることで問題が解決することもあるそうです。
  • 他にも、「PHP-FPM環境では、Apache設定ファイル内の「php_admin_value」という記述はエラーになります」という記事もあったので、そのような方は以下の記事を参考にすると良いかもしれません
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0