昔、CentOS 6の環境でLet’s Encryptを使おうとしたら割とハマってしまったんですが、今だと大分楽になっているようなので再チャレンジ。
格安のSSL証明書サービスもありますが、無料でスタートできるLet’s Encryptは便利に使えますね。
Let’s Encrypt – Free SSL/TLS Certificates
次回の契約更新の際にさくらのVPSのプランを更新して新しいバージョンのVPSを借りることにしたので、まずはミニマムな512MBプランで環境構築してみました。
Certbot のインストール
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | [root@os3-392-29368 yuuichi] # yum install certbot python-certbot-apache 読み込んだプラグイン:fastestmirror, langpacks Loading mirror speeds from cached hostfile epel /x86_64/metalink | 9.9 kB 00:00 * base: mirrors. cat .net * epel: www. ftp . ne .jp * extras: mirrors. cat .net * remi-safe: ftp .riken.jp * updates: mirrors. cat .net base | 3.6 kB 00:00 extras | 3.4 kB 00:00 mariadb-main | 2.9 kB 00:00 mariadb-maxscale | 2.4 kB 00:00 mariadb-tools | 2.9 kB 00:00 remi-safe | 3.0 kB 00:00 updates | 3.4 kB 00:00 remi-safe /primary_db | 1.4 MB 00:00 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> パッケージ certbot.noarch 0:0.29.1-1.el7 を インストール --> 依存性の処理をしています: python2-certbot = 0.29.1-1.el7 のパッケージ: certbot-0.29.1-1.el7.noarch --> 依存性の処理をしています: /usr/sbin/semanage のパッケージ: certbot-0.29.1-1.el7.noarch ---> パッケージ python2-certbot-apache.noarch 0:0.29.1-1.el7 を インストール --> 依存性の処理をしています: python2-acme >= 0.25.0 のパッケージ: python2-certbot-apache-0.29.1-1.el7.noarch --> 依存性の処理をしています: mod_ssl のパッケージ: python2-certbot-apache-0.29.1-1.el7.noarch --> トランザクションの確認を実行しています。 ---> パッケージ mod_ssl.x86_64 1:2.4.6-88.el7.centos を インストール ---> パッケージ policycoreutils-python.x86_64 0:2.5-29.el7 を インストール --> 依存性の処理をしています: setools-libs >= 3.3.8-4 のパッケージ: policycoreutils-python-2.5-29.el7.x86_64 --> 依存性の処理をしています: libsemanage-python >= 2.5-14 のパッケージ: policycoreutils-python-2.5-29.el7.x86_64 --> 依存性の処理をしています: audit-libs-python >= 2.1.3-4 のパッケージ: policycoreutils-python-2.5-29.el7.x86_64 --> 依存性の処理をしています: python-IPy のパッケージ: policycoreutils-python-2.5-29.el7.x86_64 --> 依存性の処理をしています: libqpol.so.1(VERS_1.4)(64bit) のパッケージ: policycoreutils-python-2.5-29.el7.x86_64 --> 依存性の処理をしています: libqpol.so.1(VERS_1.2)(64bit) のパッケージ: policycoreutils-python-2.5-29.el7.x86_64 --> 依存性の処理をしています: libcgroup のパッケージ: policycoreutils-python-2.5-29.el7.x86_64 --> 依存性の処理をしています: libapol.so.4(VERS_4.0)(64bit) のパッケージ: policycoreutils-python-2.5-29.el7.x86_64 --> 依存性の処理をしています: checkpolicy のパッケージ: policycoreutils-python-2.5-29.el7.x86_64 --> 依存性の処理をしています: libqpol.so.1()(64bit) のパッケージ: policycoreutils-python-2.5-29.el7.x86_64 --> 依存性の処理をしています: libapol.so.4()(64bit) のパッケージ: policycoreutils-python-2.5-29.el7.x86_64 ---> パッケージ python2-acme.noarch 0:0.29.1-1.el7 を インストール --> 依存性の処理をしています: pyOpenSSL >= 0.13 のパッケージ: python2-acme-0.29.1-1.el7.noarch --> 依存性の処理をしています: pytz のパッケージ: python2-acme-0.29.1-1.el7.noarch --> 依存性の処理をしています: python2-six のパッケージ: python2-acme-0.29.1-1.el7.noarch --> 依存性の処理をしています: python2-requests のパッケージ: python2-acme-0.29.1-1.el7.noarch --> 依存性の処理をしています: python2-pyrfc3339 のパッケージ: python2-acme-0.29.1-1.el7.noarch --> 依存性の処理をしています: python2-pyasn1 のパッケージ: python2-acme-0.29.1-1.el7.noarch --> 依存性の処理をしています: python2-josepy のパッケージ: python2-acme-0.29.1-1.el7.noarch --> 依存性の処理をしています: python2-cryptography のパッケージ: python2-acme-0.29.1-1.el7.noarch --> 依存性の処理をしています: python-requests-toolbelt のパッケージ: python2-acme-0.29.1-1.el7.noarch --> 依存性の処理をしています: python-ndg_httpsclient のパッケージ: python2-acme-0.29.1-1.el7.noarch ---> パッケージ python2-certbot.noarch 0:0.29.1-1.el7 を インストール --> 依存性の処理をしています: python2-mock のパッケージ: python2-certbot-0.29.1-1.el7.noarch --> 依存性の処理をしています: python2-future のパッケージ: python2-certbot-0.29.1-1.el7.noarch --> 依存性の処理をしています: python2-configargparse のパッケージ: python2-certbot-0.29.1-1.el7.noarch --> 依存性の処理をしています: python-zope-interface のパッケージ: python2-certbot-0.29.1-1.el7.noarch --> 依存性の処理をしています: python-zope-component のパッケージ: python2-certbot-0.29.1-1.el7.noarch --> 依存性の処理をしています: python-setuptools のパッケージ: python2-certbot-0.29.1-1.el7.noarch --> 依存性の処理をしています: python-parsedatetime のパッケージ: python2-certbot-0.29.1-1.el7.noarch --> トランザクションの確認を実行しています。 ---> パッケージ audit-libs-python.x86_64 0:2.8.4-4.el7 を インストール ---> パッケージ checkpolicy.x86_64 0:2.5-8.el7 を インストール ---> パッケージ libcgroup.x86_64 0:0.41-20.el7 を インストール ---> パッケージ libsemanage-python.x86_64 0:2.5-14.el7 を インストール ---> パッケージ pyOpenSSL.x86_64 0:0.13.1-4.el7 を インストール ---> パッケージ python-IPy.noarch 0:0.75-6.el7 を インストール ---> パッケージ python-ndg_httpsclient.noarch 0:0.3.2-1.el7 を インストール ---> パッケージ python-requests-toolbelt.noarch 0:0.8.0-1.el7 を インストール --> 依存性の処理をしています: python-requests のパッケージ: python-requests-toolbelt-0.8.0-1.el7.noarch ---> パッケージ python-setuptools.noarch 0:0.9.8-7.el7 を インストール --> 依存性の処理をしています: python-backports-ssl_match_hostname のパッケージ: python-setuptools-0.9.8-7.el7.noarch ---> パッケージ python-zope-component.noarch 1:4.1.0-3.el7 を インストール --> 依存性の処理をしています: python-zope-event のパッケージ: 1:python-zope-component-4.1.0-3.el7.noarch ---> パッケージ python-zope-interface.x86_64 0:4.0.5-4.el7 を インストール ---> パッケージ python2-configargparse.noarch 0:0.11.0-1.el7 を インストール ---> パッケージ python2-cryptography.x86_64 0:1.7.2-2.el7 を インストール --> 依存性の処理をしています: python-idna >= 2.0 のパッケージ: python2-cryptography-1.7.2-2.el7.x86_64 --> 依存性の処理をしています: python-cffi >= 1.4.1 のパッケージ: python2-cryptography-1.7.2-2.el7.x86_64 --> 依存性の処理をしています: python-ipaddress のパッケージ: python2-cryptography-1.7.2-2.el7.x86_64 --> 依存性の処理をしています: python-enum34 のパッケージ: python2-cryptography-1.7.2-2.el7.x86_64 ---> パッケージ python2-future.noarch 0:0.16.0-6.el7 を インストール ---> パッケージ python2-josepy.noarch 0:1.1.0-1.el7 を インストール ---> パッケージ python2-mock.noarch 0:1.0.1-9.el7 を インストール ---> パッケージ python2-parsedatetime.noarch 0:2.4-5.el7 を インストール ---> パッケージ python2-pyasn1.noarch 0:0.1.9-7.el7 を インストール ---> パッケージ python2-pyrfc3339.noarch 0:1.0-2.el7 を インストール ---> パッケージ python2-requests.noarch 0:2.6.0-0.el7 を インストール ---> パッケージ python2-six.noarch 0:1.9.0-0.el7 を インストール ---> パッケージ pytz.noarch 0:2016.10-2.el7 を インストール ---> パッケージ setools-libs.x86_64 0:3.3.8-4.el7 を インストール --> トランザクションの確認を実行しています。 ---> パッケージ python-backports-ssl_match_hostname.noarch 0:3.5.0.1-1.el7 を インストール --> 依存性の処理をしています: python-backports のパッケージ: python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch ---> パッケージ python-cffi.x86_64 0:1.6.0-5.el7 を インストール --> 依存性の処理をしています: python-pycparser のパッケージ: python-cffi-1.6.0-5.el7.x86_64 ---> パッケージ python-enum34.noarch 0:1.0.4-1.el7 を インストール ---> パッケージ python-idna.noarch 0:2.4-1.el7 を インストール ---> パッケージ python-ipaddress.noarch 0:1.0.16-2.el7 を インストール ---> パッケージ python-requests.noarch 0:2.6.0-1.el7_1 を インストール --> 依存性の処理をしています: python-urllib3 >= 1.10.2-1 のパッケージ: python-requests-2.6.0-1.el7_1.noarch ---> パッケージ python-zope-event.noarch 0:4.0.3-2.el7 を インストール --> トランザクションの確認を実行しています。 ---> パッケージ python-backports.x86_64 0:1.0-8.el7 を インストール ---> パッケージ python-pycparser.noarch 0:2.14-1.el7 を インストール --> 依存性の処理をしています: python-ply のパッケージ: python-pycparser-2.14-1.el7.noarch ---> パッケージ python-urllib3.noarch 0:1.10.2-5.el7 を インストール --> トランザクションの確認を実行しています。 ---> パッケージ python-ply.noarch 0:3.4-11.el7 を インストール --> 依存性解決を終了しました。 依存性を解決しました ================================================================================ Package アーキテクチャー バージョン リポジトリー 容量 ================================================================================ インストール中: certbot noarch 0.29.1-1.el7 epel 36 k python2-certbot-apache noarch 0.29.1-1.el7 epel 227 k 依存性関連でのインストールをします: audit-libs-python x86_64 2.8.4-4.el7 base 76 k checkpolicy x86_64 2.5-8.el7 base 295 k libcgroup x86_64 0.41-20.el7 base 66 k libsemanage-python x86_64 2.5-14.el7 base 113 k mod_ssl x86_64 1:2.4.6-88.el7.centos base 112 k policycoreutils-python x86_64 2.5-29.el7 base 456 k pyOpenSSL x86_64 0.13.1-4.el7 base 135 k python-IPy noarch 0.75-6.el7 base 32 k python-backports x86_64 1.0-8.el7 base 5.8 k python-backports-ssl_match_hostname noarch 3.5.0.1-1.el7 base 13 k python-cffi x86_64 1.6.0-5.el7 base 218 k python-enum34 noarch 1.0.4-1.el7 base 52 k python-idna noarch 2.4-1.el7 base 94 k python-ipaddress noarch 1.0.16-2.el7 base 34 k python-ndg_httpsclient noarch 0.3.2-1.el7 epel 43 k python-ply noarch 3.4-11.el7 base 123 k python-pycparser noarch 2.14-1.el7 base 104 k python-requests noarch 2.6.0-1.el7_1 base 94 k python-requests-toolbelt noarch 0.8.0-1.el7 epel 77 k python-setuptools noarch 0.9.8-7.el7 base 397 k python-urllib3 noarch 1.10.2-5.el7 base 102 k python-zope-component noarch 1:4.1.0-3.el7 epel 227 k python-zope-event noarch 4.0.3-2.el7 epel 79 k python-zope-interface x86_64 4.0.5-4.el7 base 138 k python2-acme noarch 0.29.1-1.el7 epel 146 k python2-certbot noarch 0.29.1-1.el7 epel 545 k python2-configargparse noarch 0.11.0-1.el7 epel 30 k python2-cryptography x86_64 1.7.2-2.el7 base 502 k python2-future noarch 0.16.0-6.el7 epel 799 k python2-josepy noarch 1.1.0-1.el7 epel 87 k python2-mock noarch 1.0.1-9.el7 epel 92 k python2-parsedatetime noarch 2.4-5.el7 epel 78 k python2-pyasn1 noarch 0.1.9-7.el7 base 100 k python2-pyrfc3339 noarch 1.0-2.el7 epel 13 k python2-requests noarch 2.6.0-0.el7 epel 2.9 k python2-six noarch 1.9.0-0.el7 epel 2.9 k pytz noarch 2016.10-2.el7 base 46 k setools-libs x86_64 3.3.8-4.el7 base 620 k トランザクションの要約 ================================================================================ インストール 2 パッケージ (+38 個の依存関係のパッケージ) 総ダウンロード容量: 6.3 M インストール容量: 27 M |
証明書の作成
インストールしたcertbotコマンドを実行して、使用するドメイン用の証明書を作成します。
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | [root@os3-392-29368 html] # certbot certonly --webroot -w /var/www/html/ -d [サーバのドメイン] Saving debug log to /var/log/letsencrypt/letsencrypt .log Plugins selected: Authenticator webroot, Installer None Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): [メールアドレス] Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https: //letsencrypt .org /documents/LE-SA-v1 .2-November-15-2017.pdf. You must agree in order to register with the ACME server at https: //acme-v02 .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 our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: N Obtaining a new certificate Performing the following challenges: http-01 challenge for www2.u-1.net Using the webroot path /var/www/html for all unmatched domains. Waiting for verification... Cleaning up challenges Resetting dropped connection: acme-v02.api.letsencrypt.org IMPORTANT NOTES: Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/www2 .u-1.net /fullchain .pem Your key file has been saved at: /etc/letsencrypt/live/www2 .u-1.net /privkey .pem Your cert will expire on 2019-04-02. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt . You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - 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で証明書を使用する設定
証明書各種はデフォルトの設定だと、/etc/letsencrypt/live/[サーバのドメイン]/ 以下に作成されました。
/etc/httpd/conf.d/ssl.conf に証明書のパスを記述してやります。
SSLCertificateFile /etc/letsencrypt/live/[サーバのドメイン]/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/[サーバのドメイン]/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/[サーバのドメイン]/chain.pem
その後、Apacheを再起動してやるとHTTPSでアクセスできました。
証明書更新の手順
証明書は有効期限が90日と短めなので定期的に更新が必要です。
更新自体はシンプルで、
1 | [root@os3-392-29368 yuuichi] # certbot renew |
で完了します。導入したての今の時点では実施しても更新はされなかったので、–dry-run オプションを付けてシミュレーションを行ってみます。
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | [root@os3-392-29368 yuuichi] # certbot renew --dry-run Saving debug log to /var/log/letsencrypt/letsencrypt .log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Processing /etc/letsencrypt/renewal/www2 .u-1.net.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Cert not due for renewal, but simulating renewal for dry run Plugins selected: Authenticator webroot, Installer None Starting new HTTPS connection (1): acme-staging-v02.api.letsencrypt.org Renewing an existing certificate Performing the following challenges: http-01 challenge for www2.u-1.net Waiting for verification... Cleaning up challenges Resetting dropped connection: acme-staging-v02.api.letsencrypt.org - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - new certificate deployed without reload, fullchain is /etc/letsencrypt/live/www2 .u-1.net /fullchain .pem - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ** DRY RUN: simulating 'certbot renew' close to cert expiry ** (The test certificates below have not been saved.) Congratulations, all renewals succeeded. The following certs have been renewed: /etc/letsencrypt/live/www2 .u-1.net /fullchain .pem (success) ** DRY RUN: simulating 'certbot renew' close to cert expiry ** (The test certificates above have not been saved.) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt . You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. |
大丈夫そう。
あとは、常用するならcronなどに組み込んで定期的に更新させてやれば良さそうですね。
参考
以上、下記サイトを参考にして実施しました。
CentOS 7 + Apache 2.4 に Let’s Encrypt の証明書を導入する手順 | WEB ARCH LABO
コメント