(15-deprecated) AWS(아마존 웹서비스) 홈페이지 만들기 CentOS7(Linux7) certbot-auto사용 SSL증명서 Let’s Encrypt를 스케줄러(cron)에 등록하기

웹서비스구축

sudo /usr/bin/certbot-auto renew –post-hook “sudo systemctl restart httpd”
Your system is not supported by certbot-auto anymore.
certbot-auto and its Certbot installation will no longer receive updates.
You will not receive any bug fixes including those fixing server compatibility
or security problems.
Please visit https://certbot.eff.org/ to check for other alternatives.

위의 메시지는 Certbot의 인증서 취득 방법이 변경되어 업데이트를 할 수 없다는 내용입니다. 즉, 이제는 더이상 certbot-auto를 사용하여 SSL증명서 Let’s Encrypt를 스케줄러(cron)에 등록할 수없습니다.
앞으로는 snap을 사용하여 SSL증명서 Let’s Encrypt를 스케줄러(cron)에 등록할 수 있습니다.

자세한 내용은 다음 글을 참조하십시오.
(15)AWS(아마존 웹서비스) 홈페이지 만들기 – CentOS7(Linux7) snap 사용 무료SSL증명서(Let’s Encrypt)작성 스케줄러(cron)에 등록하기

이 글은 더 이상 유효하지 않지만 참고로 남겨 놓겠습니다.


무료로 발급 되는 Let’s Encrypt증명서의 유효 기간은 3개월입니다. 유효 기간의 끝이 가까워지면 안내 메일을 받게 되지만 매번 수동으로 갱신을 하는 것은 꽤 귀찮은 작업입니다. 여기서는 Linux의 스케쥴링 자동화 명령(cron)을 이용하여 설정 기일이 되면 증명서를 자동으로 갱신하는 방법을 설명하겠습니다.

참고로 이 글은 AWS 웹 서비스 환경 작성을 위한 글 목록의 일부이지만 제공 업체(Azuru,GCP등)가 다르더라도 Linux 7 운영 체제라면 이 글의 내용을 적용할 수 있습니다.

실행 환경

CentOS Linux release 7.7.1908 (Core)
Apache 2.4.6

기존 증명서의 유효 기간 확인

다음 명령으로 증명서 기간이 얼마나 남아 있는지를 확인할 수 있습니다.

$ sudo certbot-auto certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Found the following certs:
Certificate Name: www.sample.com
Domains: www.sample.com
Expiry Date: 2020-06-22 10:31:01+00:00 (VALID: 60 days)
Certificate Path: /etc/letsencrypt/live/www.sample.com/fullchain.pem
Private Key Path: /etc/letsencrypt/live/www.sample.com/privkey.pem
Certificate Name: sample.com
Domains: sample.com www.sample.com
Expiry Date: 2020-06-22 10:28:27+00:00 (VALID: 60 days)
Certificate Path: /etc/letsencrypt/live/sample.com/fullchain.pem
Private Key Path: /etc/letsencrypt/live/sample.com/privkey.pem

자동화 등록

cron에 등록하기 전에 증명서 갱신 명령이 문제없이 동작하는지 확인합니다. renew는 증명서를 갱신하는 명령입니다. –post-hook에서 등록한 명령은 renew가 증명서 갱신에 성공했을 경우에 실행됩니다. 다만 유효기간에 근접하지 않았다면 실행을 스킵하는데, 이 때에 –post-hook에서 등록한 명령도 스킵됩니다.

$ sudo /usr/bin/certbot-auto renew --post-hook "sudo systemctl restart httpd"
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Processing /etc/letsencrypt/renewal/tech.zinnunkebi.com.conf
Cert not yet due for renewal
Processing /etc/letsencrypt/renewal/zinnunkebi.com.conf
Cert not yet due for renewal
The following certs are not due for renewal yet:
/etc/letsencrypt/live/tech.zinnunkebi.com/fullchain.pem expires on 2020-06-22 (skipped)
/etc/letsencrypt/live/zinnunkebi.com/fullchain.pem expires on 2020-06-22 (skipped)
No renewals were attempted.
No hooks were run.

/etc/crontab에 매주 화요일 오전 3시에 증명서 갱신 명령을 실행하도록 등록합니다. 등록후 내용을 반영하기위해서는 crond 서비스를 재기동합니다.

$ sudo vi /etc/crontab
#* * * * * user-name command to be executed
00 03 * * 2 root /usr/bin/certbot-auto renew --post-hook "systemctl restart httpd.service"
$
$ sudo systemctl restart crond.service
$

다음 명령으로 crond서비스가 기동 되어 있는지 확인합니다.

$ systemctl status crond.service
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-06-05 04:36:12 UTC; 31s ago
Main PID: 898 (crond)
CGroup: /system.slice/crond.service
└─898 /usr/sbin/crond -n

다음 명령으로 crond의 출력 로그를 확인 할 수 있습니다. -n5 옵션으로 후미의 5줄 출력합니다.

$ tail -n5 /var/log/cron
Jun 5 04:36:12 ip-172-31-46-141 crond[1000]: (CRON) INFO (Shutting down)
Jun 5 04:36:12 ip-172-31-46-141 crond[898]: (CRON) INFO (Syslog will be used instead of sendmail.)
Jun 5 04:36:12 ip-172-31-46-141 crond[898]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 66% if used.)
Jun 5 04:36:12 ip-172-31-46-141 crond[898]: (CRON) INFO (running with inotify support)
Jun 5 04:36:12 ip-172-31-46-141 crond[898]: (CRON) INFO (@reboot jobs will be run at computer's startup.)

증명서 갱신 확인

다음 명령으로 crond의 출력 로그에서 증명서 갱신을 했는지를 확인할 수 있습니다.

$ sudo grep certbot cron*
cron:Sep 8 03:00:01 ip-172-31-46-141 CROND[15251]: (root) CMD (/usr/bin/certbot renew --post-hook "systemctl restart httpd.service")

AWS 웹 서비스 환경 구축 전체 목록

이 글은 AWS 웹 서비스 환경 작성을 위한 전체 절차의 한 부분입니다. 전체 목록은 다음을 참조하십시오.

AWS EC2 웹 서비스(Wordpress) 구축 전체 글 목록
EC2(Elastic Compute Cloud) 웹 서비스 구축 전체 글 워드프레스 설치 , 환경 설정 전체 글
제목과 URL을 복사했습니다