Apache手動インストールしたらcertbot更新が大変だった話

掲載日

はじめに

セキュリティ対策を行った記事でApacheの再インストールを行いました。

年末も近いのでついでに証明書のメンテナンスでもしとくかと思い、certbot renew --dry-runコマンドを実行したところ何やらエラーが出てしまったので対応したログです。

パスが通ってない

まずはエラー内容が以下の通り。

[XXX@XXX ~]#  certbot renew --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/awatana.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Failed to renew certificate awatana.com with error: The apache plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError('Cannot find Apache executable httpd')

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
All simulated renewals failed. The following certificates could not be renewed:
  /etc/letsencrypt/live/awatana.com/fullchain.pem (failure)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1 renew failure(s), 0 parse failure(s)

結論

以下の通りシンボリックリンクを張ります。

yum installするとsbin配下に実行スクリプトを勝手に入れてくれますが、手動では当然そうはならないので実行できるようにします。

ln -s /usr/local/apache2/bin/httpd /sbin/httpd
 ln -s /usr/local/apache2/bin/apachectl /sbin/apachectl

/usr/local/apache2/bin/~~~は任意のパスに変更してください。

原因

Cannot find Apache executable httpd

とあるので、実行できるhttpdがないよということだと思われます。

certbotは実行指示にapachectlコマンドとhttpdコマンドを実行しているようで、パスが通ってないと当然コマンドが実行できなくてエラーになります。
よって、パスを通してあげればOKです。(.bashrcにはパスを追加していたのですが、これってインタラクティブモード(対話形式)で起動した時にしか読み込まないんですね。知らなかった…。)

設定ファイルの場所が不明

上記を修正したので、もう一度実行すると今度は別のエラーが。

[XXX@XXX ~]# certbot renew --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/awatana.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Failed to renew certificate awatana.com with error: The apache plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError('Could not find configuration root')

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
All simulated renewals failed. The following certificates could not be renewed:
  /etc/letsencrypt/live/awatana.com/fullchain.pem (failure)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1 renew failure(s), 0 parse failure(s)
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

結論

対応1. オプションを指定

実行時に以下のオプションを追加して実行します。(新ディレクトリ位置を明示する)

  • --apache-server-root 任意のパス
    設定ファイルとか入ってるルートパス(デフォルト/etc/httpd
  • --apache-challenge-location 任意のパス
    チャレンジ設定のパス(デフォルト/etc/httpd/conf.d)
certbot renew --apache-server-root /usr/local/apache2/ --apache-challenge-location /usr/local/apache2/conf.d --dry-run

対応2. シンボリックリンク

毎回上記オプション指定するのは絶対忘れるので、シンボリックリンクを追加します。

 ln -s /usr/local/apache2/ /etc/httpd

原因

問題の箇所は以下。

The apache plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError('Could not find configuration root')

Could not find configuration rootということで、configファイルが入ってるディレクトリのルートが見つからないよ的な話と思われます。
確かに手動インストールにあたって、/etc/httpd配下から移動したのでそれが原因でした。
以下のコマンドを実行してヘルプを見ると、それらしきオプションが見つかります。

[XXX@XXX ~]# certbot -h all
  (省略)
apache:
  Apache Web Server plugin

  (省略)
  --apache-server-root APACHE_SERVER_ROOT
                        Apache server root directory (default: /etc/httpd)
  (省略)
  --apache-challenge-location APACHE_CHALLENGE_LOCATION
                        Directory path for challenge configuration (default: /etc/httpd/conf.d)
  (省略)

よって、--apache-server-rootオプションと--apache-challenge-locationオプションで新しいルートを明示すれば実行が出来るようになるということでした。

おわりに

最後まで修正ができたら、念のためcertbot renew --dry-runをもう一度やって問題なければOKです。
更なるエラーが出たらもうひと踏ん張りです。

 

手動再インストールはこういうのが起きるので怖いですが、マニュアルを見てコマンドの勉強をする機会にもなります。
どこにどういう設定ファイルがあるのかとか、このコマンドはそういうファイルを勝手に見てくれてるんだとかも分かるので、趣味サイトの構築サーバーで遭遇する分には楽しいですね。
(実機だったら、こうなる前に仮想マシンで試して手動インストール自体やらないと思いますが、万が一こうなったら血の気が引きそう。)

記事の作成者のA.W.のアイコン

この記事を書いた人

A.W.
茨城県在住Webエンジニアです。 PHPなどを業務で使用しています。 趣味ではGoやNuxt、Flutterをやってます。

Comment