certbot SSL 인증서 추가
먼저 인증서를 설치 할 도메인이 IP에 정확히 연결이 되어 있는지 확인한다.
– ping 커맨더 혹은 브라우저 접속으로 확인
– Apache 에 mod_ssl, mod_rewrite 모듈 확인
– 방화벽 서비스 열림 확인 80(http), 443(https), 일반적으로 zone 옵션 생략
~]# ping example.com
~]# httpd -M | grep ssl
ssl_module (shared)
~]# httpd -M | grep rewrite
rewrite_module (shared)
~]# firewall-cmd --zone=public --list-all
services: cockpit dhcpv6-client http httpsexample.com, www.example.com 두 도메인을 example.com 파일명으로 인증서 설치.
설정 파일의 수정 없이 인증서만 발급 받아 설치 후 수동으로 서비스 파일 수정할 계획.
– 먼저 로그 기록 하겠다. 이메일 등록할래? 묻고
– ACME server 에 등록해야 한다. 뭐 이렇게 뜨고 동의하면 설치를 진행 한다.
– 잘 설치 되었고, 갱신은 백그라운드에 등록해서 자동 갱신한다. 뭐 이러네요.
– 백그라운드 등록 확인, 크론 혹은 타이머 둘 중 하나에 등록 예상. 리눅스가 최신이니 타이머 아닐까?
– 타이머 맞고, 대략 하루 두번 0시 12시 하는데, 실행 시점은 랜덤 지연 포함해서 분산 되도록 했네요.
~]# certbot certonly --webroot -w /host/example.com/public_html -d example.com -d www.example.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address or hit Enter to skip.
(Enter 'c' to cancel):.....
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at:
https://letsencrypt.org/documents/LE-SA-v1.5-February-24-2025.pdf
You must agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Account registered.
.....중략......
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
~]# systemctl cat certbot-renew.timer
# /usr/lib/systemd/system/certbot-renew.timer
[Unit]
Description=This is the timer to set the schedule for automated renewals
[Timer]
OnCalendar=*-*-* 00/12:00:00 # 매일 00:00과 12:00에 실행 시도
RandomizedDelaySec=12hours # 00시~12시 사이, 또는 12시~24시 사이에 무작위 실행
Persistent=true # 시스템이 꺼져 있다가 켜져도 누락된 실행을 보완해서 실행
[Install]
WantedBy=timers.target타이머로 갱신 시 자동으로 Apache 를 자동으로 리로드 해야겠죠.
기존 certbot-renew.timer가 systemd로 등록되어 있으니,
기존 certbot-renew.timer가 systemd로 등록되어 있으므로,/usr/lib/systemd/system/certbot-renew.service를 수정하거나 override 설정을 추가.
certbot 에 --deploy-hook추가
certbot renew --deploy-hook "apachectl graceful"
# --deploy-hook: 인증서가 실제로 갱신된 경우에만 실행됨
# --deploy-hook은 --renew-hook보다 최신 방식이며, Certbot 0.22 이후 권장
# --renew-hook은 모든 renew 시도마다 실행되지만, --deploy-hook은 실제 갱신이 있을 때만 실행
# apachectl graceful: 무중단으로 Apache 설정 reload
~]# ll /etc/systemd/system/timers.target.wants/
합계 0
lrwxrwxrwx. 1 root root 43 10월 20일 18:48 certbot-renew.timer -> /usr/lib/systemd/system/certbot-renew.timer
....중략.... # 심볼릭링크 되어 있음. 서비스파일도 이 위치.
~]# vi /usr/lib/systemd/system/certbot-renew.service
[Service]
ExecStart=/usr/bin/certbot renew --deploy-hook "apachectl graceful"
....중략....
# 오버라이드 형식으로 작업
~]# systemctl edit certbot-renew.service
# 오버라이드 내용
[Service]
ExecStart=
ExecStart=/usr/bin/certbot renew --deploy-hook "/usr/sbin/apachectl graceful" >> /var/log/letsencrypt/renew.log 2>&1
# ExecStart=: 기존 설정 초기화
# >> /var/log/letsencrypt/renew.log: 로그를 지정 경로에 저장
# 2>&1: 표준 오류도 함께 기록


