Cloud 개발

let's encrypt 자동 갱신 설정 - 초간단 방법입니다.

긋대디 2021. 10. 5. 23:38

let's encrypt 자동 갱신 설정

인증서 자동 갱신 설정을 최대한 간단한 방법을 찾아서 정리해 봤습니다.

예전에 어려워 보여서 포기했으나 다시 정리하면서 해보니 쉽네요

 

먼저 인증서가 설치되어 있어야 합니다.

설치되지 않았다면 아래 링크 참조하여 설치

 

 

Let's Encrypt ssl 적용 - 무료 SSL 인증서 설치 (apache https 설치)

본 설치 안내는 CentOS 7 기준으로, 무료 SSL 인증서를 웹서버에 적용하는 방법을 설명합니다. let's Encrypt 인증서는 무료이나 유료인증서와 다르게 3개월 단위로 갱신하여야 합니다. 이는 자동 갱신

softone.tistory.com

 



1. 인증서 갱신 테스트

아래 명령어로 실제 갱신이 아니라 잘 갱신되는지, 명령에 오류가 나진 않는지 등을 테스트해 볼 수 있습니다.

 

# certbot renew --dry-run

[root@vm1 conf.d]# certbot renew --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/mail.korea.co.kr.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator apache, Installer apache
Starting new HTTPS connection (1): acme-staging-v02.api.letsencrypt.org
Account registered.
Simulating renewal of an existing certificate for mail.korea.co.kr
Performing the following challenges:
http-01 challenge for mail.korea.co.kr
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of apache server; fullchain is
/etc/letsencrypt/live/mail.korea.co.kr/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded:
  /etc/letsencrypt/live/mail.korea.co.kr/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

실제로 갱신하기 dry-run만 빼고 실행하시면 됩니다.
# certbot renew


2. 인증서 만료일 확인하기

Certbot으로부터 발급받은 인증서들에 대한 정보를 표시합니다.

# certbot certificates

[root@vm1 conf.d]# certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: mail.korea.co.kr
    Serial Number: 4235fe46e88c23***********b5073f53
    Key Type: RSA
    Domains: mail.korea.co.kr
    Expiry Date: 2021-11-05 07:05:03+00:00 (VALID: 88 days)
    Certificate Path: /etc/letsencrypt/live/mail.korea.co.kr/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/mail.korea.co.kr/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -




3. crontab에 자동 갱신 추가

* 현재 설정된 crontab 내용 출력

# crontab -l


* crontab 내용 입력(편집). 저장 방법은 vi와 동일. 콜론(:)입력 후 wq 입력하면 됨

# crontab -e

 

* 아래는 매일 새벽 3시에 갱신할 수 있도록 추가하고 apache 서버를 재시작하는 예

# crontab -e
0 3 * * * /usr/bin/certbot renew --renew-hook="systemctl restart httpd"

뒤에 나오는 –renew-hook은 인증서 갱신을 성공적으로 마치면 아파치를 재시작하기 위해 넣어주었습니다.