Blog >> Linux >> whitepapers.

certbot wildcard SSL 인증서 설치 150 150 phobe

certbot wildcard SSL 인증서 설치

여러 서브도메인을 운영 한다면 같은 인증서로 여러 도메인에 적용해야 할때가 있다.
이럴때 와일드카드 인증서를 적용해야 하는데, 이게 좀 그런게 오직 수동으로만 갱신 가능하다. 일부 제휴 된 호스팅 업체에는 자동 갱신이 가능하다는 설도 있다.
오늘 갑자기 인증서가 만료됐다. 이게 좀 그렇다 자동화가 안된다는거. 와일드카드 인증서는 다시 설치 해야 하는거랑 별반 차이가 없다. 타이핑을 잘못하는 바람에 프로세스를 CTRL+Z 강제종료. 그러니, 프로세스가 진행 중이라 하지 못하겠단다. 일단 프로세스 죽이고 로깅파일 락파일 강제 삭제 후 작업한다.

~]# ps -ef | grep certbot
~]# pkill -9 certbot
~]# find / -type f -name ".certbot.lock"
/var/lib/letsencrypt/.certbot.lock
/var/log/letsencrypt/.certbot.lock
/etc/letsencrypt/.certbot.lock
[root@server ~]# rm /var/lib/letsencrypt/.certbot.lock
rm: remove 일반 빈 파일 `/var/lib/letsencrypt/.certbot.lock'? y
[root@server ~]# rm /var/log/letsencrypt/.certbot.lock
rm: remove 일반 빈 파일 `/var/log/letsencrypt/.certbot.lock'? y
[root@server ~]# rm /etc/letsencrypt/.certbot.lock
rm: remove 일반 빈 파일 `/etc/letsencrypt/.certbot.lock'? y
[root@server ~]# find / -type f -name ".certbot.lock" -exec rm {} \;
# 스냅도 리프레시
~]# snap refresh certbot

작업 재 시작

~]# certbot certonly --manual --preferred-challenges=dns -d '*.gldigital.co.kr' -d 'gldigital.co.kr'
...중략...
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:

_acme-challenge.gldigital.co.kr.

with the following value:

8o_0-CtNNvkp8heJATpfTG3sZEgRsDo5NbWwe_ni0CY

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

이때 딱 멈추고 DNS설정에 TXT 값을 추가. 후 엔터.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:

_acme-challenge.gldigital.co.kr.

with the following value:

YfpN060E40DB5IWQdqjFscwHom7635EG17aQ8_-G66o

(This must be set up in addition to the previous challenges; do not remove,
replace, or undo the previous challenge tasks yet. Note that you might be
asked to create multiple distinct TXT records with the same name. This is
permitted by DNS standards.)

Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.gldigital.co.kr.
Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
value(s) you've just added.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

그럼 잘 읽고, 또 하나 더 DNS TXT 추가. 후 엔터.
그럼 잘 됐다고 나와요. 이러면

~]# apachectl graceful

Certbot은 아쉽게도 .conf 파일 내부에 enabled = false나 skip = true 같은 자체적인 활성화/비활성화 토글 옵션을 지원하지 않음. 아래 타이머 서비스 renewal 설정에 보면 –noninteractive 부분으로 현재 서버의 certbot-renew.service 설정을 보면 –noninteractive(비 대화형) 옵션이 강제 되어 있음.

~]# systemctl cat certbot-renew.service
# /usr/lib/systemd/system/certbot-renew.service
[Unit]
Description=This service automatically renews any certbot certificates found

[Service]
EnvironmentFile=/etc/sysconfig/certbot
Type=oneshot
ExecStart=/usr/bin/certbot renew --noninteractive --no-random-sleep-on-renew $PRE_HOOK $POST_HOOK $RENEW_HOOK $DEPLOY_HOOK $CERTBOT_ARGS

# /etc/systemd/system/certbot-renew.service.d/override.conf
[Service]
ExecStart=
ExecStart=/usr/bin/certbot renew --noninteractive --no-random-sleep-on-renew $PRE_HOOK $POST_HOOK $RENEW_HOOK $DEPLOY_HOOK $CERTBOT_ARGS

~]# cat /etc/letsencrypt/renewal/*****.co.kr.conf 
version = 4.2.0
archive_dir = /etc/letsencrypt/archive/*****.co.kr
cert = /etc/letsencrypt/live/*****.co.kr/cert.pem
privkey = /etc/letsencrypt/live/*****.co.kr/privkey.pem
chain = /etc/letsencrypt/live/*****.co.kr/chain.pem
fullchain = /etc/letsencrypt/live/*****.co.kr/fullchain.pem

# Options used in the renewal process
[renewalparams]
account = 3796e3c*****526a94695f*****
pref_challs = dns-01,
authenticator = manual
server = https://acme-v02.api.letsencrypt.org/directory
key_type = ecdsa

Certbot은 –noninteractive 상태에서 .conf 파일의 authenticator = manual 설정을 만나면 다음과 같이 동작합니다.

  1. “어? 수동으로 DNS 레코드를 구워야 하는데 사용자가 입력을 못 하는 모드네?” 하고 판단.
  2. 해당 도메인은 갱신 불가(Skiped/Failed) 처리를 하고 로그에 기록만 남김.
  3. 가장 중요한 점: 여기서 멈추지 않고 다음 차례인 다른 정상적인 가상 호스트(도메인)들의 자동 갱신을 계속 진행.

이 방법의 단점은
작동 자체는 다른 도메인에 피해를 주지 않고 넘어가므로 문제가 없지만, 일주일이나 매일 타이머가 돌 때마다 로그(또는 메일 알림 설정 시)에 해당 설정(와일드카드 도메인)의 갱신 실패라는 에러 메시지가 남게 되므로 관리자 입장에서 매번 확인해야 하는 번거로움이 생김.

이것을 위한 것으로 와일드카드 도메인의 .conf 파일만 별도 폴더(renewal-wildcard)로 격리 해야 함. 근데 이것은 또 다른 불편함을 만듦. – 와일드카드 수동 갱신 후 또 다시 해당 .conf파일이 /etc/letsencrypt/renewal/*.co.kr.conf 파일로 다시 생겨버림. 또 다른 문제는 갱신 시점을 전부 기억할 수 없다는 것에 있음.

그래서 이것을 스크립트로 만들어서 콘솔에 로그인할 때 마다 체크해 주기로 함.
1. 루트 로그인 때만 실행 – /etc/profile.d/ 디렉토리는 모든 사용자에게 적용됨.
2. 갱신 일자 체크 전 와일드카드 도메인의 /etc/letsencrypt/renewal/*.co.kr.conf 파일을 /etc/letsencrypt/renewal-wild/*.co.kr.conf 로 mv.

~]# vi /usr/local/sbin/custom-noti-cert.sh
~]# chmod 700 /usr/local/sbin/custom-noti-cert.sh

# 그리고 /etc/profile.d 디렉토리로 소프트 링크
~]# ln -s /usr/local/sbin/custom-noti-cert.sh /etc/profile.d/custom-noti-cert.sh
~]# ls -l /etc/profile.d/custom-noti-cert.sh
lrwxrwxrwx. 1 root root 35  6 18  18:53 /etc/profile.d/custom-noti-cert.sh -> /usr/local/sbin/custom-noti-cert.sh

# 링크 잘 된것 확인 후
~]# exit
로그아웃
~]$ su -
최근 로그인:   6 18 17:42:38 KST 2026 pts/0에

=======================================================
 🛡️  [시스템 안내] 수동 관리 인증서 만료 현황
=======================================================
  *****.co.kr : 82 남음 (안전)
=======================================================

~]# 
  • certbot SSL 인증서 추가 150 150 phobe certbot SSL 인증서 추가