LoginSignup
1
3

More than 3 years have passed since last update.

サーバー移管に伴う、Let's Encryptにて発行したSSL証明書の使い回しをしてみた

Last updated at Posted at 2021-01-16

前提

今回サーバーA(以降、旧サーバー)からサーバーB(以降、新サーバー)へお引っ越しをする機会があり、
旧サーバーで使用していたSSL証明書を、新サーバーへ持っていきそのまま使用したかったため、以下を参考にやってみた。
以下手順であれば一瞬でもSSL化が解除されることはなくなり、安心・安全にサーバー移管可能かと思う。

https://blog.fileshelfplus.com/vps/280

環境

  • conoha VPS → conoha VPS
  • お名前.comにて発行したドメイン(そのまま・IPアドレスの紐付けだけ変更)
  • centos7 → centos7

手順

まずは旧サーバーへsshログイン
(基本的に Let's Encrypt にて発行した証明書は、/etc/letsencrypt/にある。)
letsencryptディレクトリ丸ごと圧縮する。

旧サーバー
$ zip -ry letsencrypt.zip /etc/letsencrypt
# または
$ tar zcvf letsencrypt.tar.gz /etc/letsencrypt

圧縮したファイルを新サーバーへリストア後、sshログイン。

Let’s Encrypt ユーザーガイドに従ってCertbotクライアントをインストールする。

新サーバー
$ sudo yum -y install epel-release
$ sudo yum -y install certbot
$ sudo curl https://dl.eff.org/certbot-auto -o /usr/bin/certbot-auto
$ sudo chmod 700 /usr/bin/certbot-auto

次にリストアした圧縮ファイルを解凍する。
解凍場所は/etc

新サーバー
$ zip -ry letsencrypt.zip /etc/letsencrypt
# または
$ tar zcvf letsencrypt.tar.gz /etc/letsencrypt

ドメインのIP紐付け変更

ここまで出来たらドメインの付け替えを実施。
各種サーバー会社の手順に従い、AレコードやTXTレコード、ネームサーバーの変更を行う。
今回は以下を参考にした。

https://qiita.com/sugra511/items/3b05423d4adeeec5cdd4

最後に証明書の更新を実施しwebサーバーを更新。

新サーバー
$ certbot-auto renew
$ systemctl restart httpd

※必要に応じてcronにて証明書の自動更新設定をしておく。

# 以下は、毎月1日の午前4時に自動更新をするcron
# certbot-auto で証明書を更新し、apacheを再起動
# [webroot]の設定を忘れないこと

$ crontab -e
00 04 01 * * certbot-auto renew --force-renew --webroot-path /var/www/html/[webroot] --post-hook "systemctl reload httpd"
1
3
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
1
3