2021年 Amazonlinux2 に無料のSSL証明書 Let’s Encrypt(certbot)インストール方法

投稿者:

この間、新しい案件で、いつもどおりにawsでec2のインスタンスを作ってサイトをSSL化しようといつもの手順で、certbot-auto をインストールして証明書発行しようとしたら、、、、

Skipping bootstrap because certbot-auto is deprecated on this system.
/home/app_admin/certbot/certbot-auto has insecure permissions!
To learn how to fix them, visit https://community.letsencrypt.org/t/certbot-auto-deployment-best-practices/91979/
Your system is not supported by certbot-auto anymore.
Certbot cannot be installed.
Please visit https://certbot.eff.org/ to check for other alternatives.

このシステムではcertbot-autoが非推奨 。。。。。なんですと?
はい。そうなのです。最新版の certbot は、今までの手順で git などから clone して使うことができなくなってしまったのです。。悲しい。。ついこの間手順を忘れないように記事書いたばかりなのに。。

調べてみると、 2020年12月のリリース1.10.0からDebian系で非対応になったとのこと。 ふむふむ。
で、AamazonLinuxは RedHat 系 なので、使えるはず。

certbot の公式ページで、WEBサーバとOSを選択して certbotのインストール方法を解説されているので、確認。Amazonlinuxは、選択肢にない。ただ、Amazonlinuxは RedHat 系 で、 centOSと兄弟みたいなものなので、 Apache on CentOS/RHEL 7 の場合のインストール方法に従ってインストールしてみる。

SSH into the server
SSH into the server running your HTTP website as a user with sudo privileges.

SSHで接続して、root権限になれということなので、早速接続。

Install snapd
You’ll need to install snapd and make sure you follow any instructions to enable classic snap support.
Follow these instructions on snapcraft’s site to install snapd.

snapd をインストールしてね。と。
snapdは、Linuxディストリビューションを問わず動作するソフトウェアパッケージ「Snap」形式を使うためのツールとのこと。やばい。知らなかった。
ということで、AmazonLinux2へ snapd をインストールする方法を調べてインストール。

まずは、snapdが入っているリポジトリの追加

$ cd /etc/yum.repos.d/
$ sudo wget https://people.canonical.com/~mvo/snapd/amazon-linux2/snapd-amzn2.repo

/etc/yum.conf に以下の設定を追加。[main] ディレクティブの最後に追加する。

[main]
...
# ↓こちらを追加
exclude=snapd-*.el7 snap-*.el7

ここまでの設定を行うと、慣れ親しんだ yum にて、 snapd をインストールすることが出来る

$ yum install snapd

これで、snapd のインストールが成功するはず。自分はしました。
あとは、snapd の自動起動とシンボリックリンクでコマンドを使えるようにすれば完了(snpadは)

$ systemctl enable --now snapd.socket
$ ln -s /var/lib/snapd/snap /snap

Ensure that your version of snapd is up to date
Execute the following instructions on the command line on the machine to ensure that you have the latest version of snapd.

公式に書いてあるとおりに、以下のコマンドを実行。公式では、一行で書かれているが、Amazonlinux2 でそのまま実行するとエラーになったので、それぞれ実行。

$ sudo snap install core
$ snap refresh core

Remove certbot-auto and any Certbot OS packages
If you have any Certbot packages installed using an OS package manager like apt, dnf, or yum, you should remove them before installing the Certbot snap to ensure that when you run the command certbot the snap is used rather than the installation from your OS package manager. The exact command to do this depends on your OS, but common examples are sudo apt-get remove certbot, sudo dnf remove certbot, or sudo yum remove certbot.
If you previously used Certbot through the certbot-auto script, you should also remove its installation by following the instructions here.

certbotがすでにインストールされていたら、削除しておいてね。ということなので、入っていればアンインストールしましょう。自分は今回は新しいインスタンスに入れているのでもちろん入っていない。

Install Certbot
Run this command on the command line on the machine to install Certbot.

ようやく本命の certbot のインストール。以下のコマンドでインストールしましょう。

$ snap install --classic certbot

Prepare the Certbot command
Execute the following instruction on the command line on the machine to ensure that the certbot command can be run.

snapのインストール先は、パスが通っていないので、パスを通すためにシンボリックリンクを貼りましょう。

$ ln -s /snap/bin/certbot /usr/bin/certbot

はい。これで、ようやく完了です。
後は、実際に証明書の発行を行ってみましょう!

$ certbot certonly --apache

インストールして初めて上記のコマンドを実行すると、メールアドレスの登録を求められます。SSL証明書の更新の連絡をメールで教えてくれるものになるので、ちゃんと届くメールを設定しましょう。

返信を残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です