Let’s EncryptをAmazon Linuxで使う
普通のLinuxディストリビューションであれば公式のリポジトリからLet’s Encrypt(LE)の自動化ツールである「certbot」をインストール可能ですが、Amazon Linuxは現状ではベースはRHEL6ですが独自のリポジトリ管理を行っているためLE公式サイトそのままではインストールできず少しだけ対応が必要です。
sudo yum install epel-release wget https://dl.eff.org/certbot-auto chmod a+x certbot-auto ./certbot-auto
これでインストール可能なはずですが、最後の「./certbot-auto」を実行すると、以下のエラーが発生しました。
FATAL: Amazon Linux support is very experimental at present... if you would like to work on improving it, please ensure you have backups and then run this script again with the --debug flag! Alternatively, you can install OS dependencies yourself and run this script again with --no-bootstrap.
「–no-bootstrap」オプションを付けて再実行しますが、別の問題が発生しました。
./certbot-auto --no-bootstrap Creating virtual environment... Installing Python packages... Had a problem while installing Python packages.
どうやらlibffi-develパッケージが必要なようです。「yum install libffi-devel」でインストールします。そして再実行。
./certbot-auto --no-bootstrap Creating virtual environment... Installing Python packages... Installation succeeded. Saving debug log to /var/log/letsencrypt/letsencrypt.log Certbot doesn't know how to automatically configure the web server on this system. However, it can still get a certificate for you. Please run "certbot-auto certonly" to do so. You'll need to manually configure your web server to use the resulting certificate.
今度は無事インストール出来たようです。ただし、certbotは自動でWebサーバーを構成しないよってメッセージなので、手動で設定する必要があるようです。ここは指示通りに「certonly」オプションを付けて実行します。
./certbot-auto certonly Saving debug log to /var/log/letsencrypt/letsencrypt.log How would you like to authenticate with the ACME CA? ------------------------------------------------------------------------------- 1: Place files in webroot directory (webroot) 2: Spin up a temporary webserver (standalone) ------------------------------------------------------------------------------- Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1 Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel):webmaster@arigato.es
webrootを使用した認証を行うので、「1」を入力します。初回のみメール登録を要求されるので、メールアドレスを入力します。念のためドメイン名を含むアドレスを使用していますが、その指定はどこにも無いので所有するアドレスであれば大丈夫なのかもしれません。仮登録のメールが届くので、メール内のリンクをクリックして本登録しておきます。
------------------------------------------------------------------------------- Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf. You must agree in order to register with the ACME server at https://acme-v01.api.letsencrypt.org/directory ------------------------------------------------------------------------------- (A)gree/(C)ancel: A ------------------------------------------------------------------------------- Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about EFF and our work to encrypt the web, protect its users and defend digital rights. ------------------------------------------------------------------------------- (Y)es/(N)o: Y Please enter in your domain name(s) (comma and/or space separated) (Enter 'c' to cancel):www.arigato.es <--証明書を取得したいドメインを入力します Obtaining a new certificate Performing the following challenges: http-01 challenge for www.arigato.es Select the webroot for www.arigato.es: ------------------------------------------------------------------------------- 1: Enter a new webroot ------------------------------------------------------------------------------- Press 1 [enter] to confirm the selection (press 'c' to cancel): 1 Input the webroot for www.arigato.es: (Enter 'c' to cancel):「ドキュメントルートを入力」 Waiting for verification... Cleaning up challenges Generating key (2048 bits): /etc/letsencrypt/keys/0000_key-certbot.pem Creating CSR: /etc/letsencrypt/csr/0000_csr-certbot.pem IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/www.arigato.es/fullchain.pem. Your cert will expire on 2017-07-25. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
これで無事証明書を取得できたので、あとはApacheを設定してhttpdを再起動すれば完了です。有効期間は3か月なので、有効期間まで30日を切ったら、「renew」オプションを付けて「certbot-auto」を実行すると、自動的に更新してくれるそうです。コマンドが確定したらcrontabに登録して自動化することが可能です。おそらくこんな感じかと。毎月1日の23時55分に実行します。証明書の有効期限が30日未満だったら自動的に更新されます。コマンド終了後にhttpdを再起動します。
55 23 1 * * root /etc/certbot-auto renew --post-hook "service httpd restart"
証明書と秘密鍵は、「/etc/letsencrypt/live/ドメイン名/fullchain.pem」と「/etc/letsencrypt/live/ドメイン名/privkey.pem」にシンボリックリンクが張られています。Apache2.4.8以降であれば、それぞれを「ssl.conf」の「SSLCertificateFile」ディレクティブと「SSLCertificateKeyFile」ディレクティブに指定するだけでOKです。忘れずにhttpdを再起動すれば完了です。