certbot SSL 인증서 발급 https://foxydog.tistory.com/63 > 잡다한 IT

본문 바로가기

잡다한 IT

잡다한 IT HOME



certbot SSL 인증서 발급 https://foxydog.tistory.com/63

페이지 정보

작성자 낙엽타는향기 댓글 0건 조회 3,093회 작성일 22-06-17 11:58

본문

https://foxydog.tistory.com/63

 

STEP01 →EPEL 저장소 추가(또는 업데이트)

[root@localhost ~]# dnf install epel-release

Upgraded: epel-release-8-9.el8.noarch


 


STEP02→필요한 패키지 설치

※ 저는 아파치를 이용하므로 아래와 같이 진행 [nginx를 이용한다면 python3-certbot-(nginx) 부분만 변경]


[root@localhost ~]# dnf install certbot python3-certbot-apache mod_ssl



 


STEP03 →인증서 받기 [수동 진행]

※ 만약 본인이 서버 관리자라면 자동은 되도록 피하는 것이 좋습니다. 자동으로 설정을 변경하기 때문에 예외 변수가 발생할 수 있습니다. 그러므로 인증서 파일만 발급받는 수동 옵션인 [certonly] 이용하는 게 좋습니다.


※ 제가 사용하는 메일서버 도메인[mail.foxydog.co.kr]을 예시로 발급받아보겠습니다.


순서대로 진행


[root@mail ~]# certbot certonly -d mail.foxydog.co.kr

Saving debug log to /var/log/letsencrypt/letsencrypt.log

Error while running apachectl configtest.


AH00526: Syntax error on line 85 of /etc/httpd/conf.d/ssl.conf: (에러 무시)

SSLCertificateFile: file '/etc/pki/tls/certs/localhost.crt' does not exist or is empty



How would you like to authenticate with the ACME CA?

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

1: Apache Web Server plugin (apache) [Misconfigured]

2: Spin up a temporary webserver (standalone)

3: Place files in webroot directory (webroot)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Select the appropriate number [1-3] then [enter] (press 'c' to cancel): 2

Plugins selected: Authenticator standalone, Installer None

Enter email address (used for urgent renewal and security notices)

▷ 긴급 갱신 및 보안 공지에 사용되므로 수신받을 수 있는 이메일 주소를 입력

 (Enter 'c' to cancel): foxydog@foxydog.co.kr


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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. Do you agree?

▷ 서비스 약관 읽고 ACME 서버에 등록하기 위한 절차

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

(Y)es/(N)o: Y (동의)


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Would you be willing, once your first certificate is successfully issued, 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: Y (동의)


Account registered.

Requesting a certificate for mail.foxydog.co.kr

Performing the following challenges:

http-01 challenge for mail.foxydog.co.kr

Waiting for verification...

Cleaning up challenges

Subscribe to the EFF mailing list (email: foxydog@foxydog.co.kr).


IMPORTANT NOTES:

 - Congratulations! Your certificate and chain have been saved at:

▷ 축하합니다! 인증서와 체인이 다음 위치에 저장되었습니다. (메시지가 나와야 정상 생성)

   /etc/letsencrypt/live/mail.foxydog.co.kr/fullchain.pem

   Your key file has been saved at:

   /etc/letsencrypt/live/mail.foxydog.co.kr/privkey.pem

   Your certificate will expire on 2021-08-12. To obtain a new or

▷ 인증서 만료일은 [2021-08-12] (무료 인증서이기 때문에 3개월 기준으로 새로 발급받아야 한다.)

   tweaked version of this certificate in the future, simply run

   certbot again. To non-interactively renew *all* of your certificates, run "certbot renew"

▷ 인증서가 만료되면 "certbot renew" 통해 갱신이 가능합니다.

 - 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



[참고] ※ 에러 발생 시

① 방화벽에 의한 실패 [국가]


에러 메시지 : An unexpected error occurred:


ValueError: Requesting acme-v02.api.letsencrypt.org/directory: Network is unreachable


해결방안 : acme-v02.api.letsencrypt.org 사이트 IP가 해외이므로 요청을 처리하기 위해서는 앞단 방화벽이 있을 시 국가일 경우는 미국(US)을 허용할 것



 


② 80 포트 사용으로 인한 실패


에러 메시지 : Problem binding to port 80: Could not bind to IPv4 or IPv6.


해결방안 : 사이트 요청 처리하기 위해서는 80 포트를 사용, 다만 중복이 불가하므로 이미 사용 중인 해당 포트 아파치(Apache), Nginx 프로세스가 실행되고 있다면 중지 후 진행



 


③ 잘못된 도메인 주소 또는 A(AAAA) 레코드 응답 실패


에러 메시지 : Challenge failed for domain mail.foxydog.com, Some challenges have failed.


해결방안 : 인증을 받기 위해서는 실제 존재하는 도메인으로 연결이 되어야 합니다. 본인이 사용하는 도메인을 잘못 적었거나 혹은 레코드 연결이 A(AAAA) IP 연결이 제대로 되어 있지 않아 홈페이지 연결이 되지 않으면 해당 에러 메시지가 발생할 수 있습니다.



 


STEP04 →인증서 파일 생성 확인

[root@mail ~]# ls -al /etc/letsencrypt/live/mail.foxydog.co.kr/ | grep pem

lrwxrwxrwx 1 root root  42 May 14 14:08 cert.pem -> ../../archive/mail.foxydog.co.kr/cert1.pem

lrwxrwxrwx 1 root root  43 May 14 14:08 chain.pem -> ../../archive/mail.foxydog.co.kr/chain1.pem

lrwxrwxrwx 1 root root  47 May 14 14:08 fullchain.pem -> ../../archive/mail.foxydog.co.kr/fullchain1.pem

lrwxrwxrwx 1 root root  45 May 14 14:08 privkey.pem -> ../../archive/mail.foxydog.co.kr/privkey1.pem


※ 소프트 링크로 걸려있으며 실제 파일 경로는 아래와 같습니다. Certbot을 이용하여 자동으로 연장 설정하기 위해서 다음과 같은 방식을 사용하는 것 같습니다. 만약 다른 서버에 인증서를 설치해야 할 경우는 아래 파일을 복사하여 사용하시면 됩니다.


[root@mail ~]# ls -al /etc/letsencrypt/archive/mail.foxydog.co.kr/ | grep pem

-rw-r--r-- 1 root root 1850 May 14 14:08 cert1.pem

-rw-r--r-- 1 root root 3749 May 14 14:08 chain1.pem

-rw-r--r-- 1 root root 5599 May 14 14:08 fullchain1.pem

-rw------- 1 root root 1704 May 14 14:08 privkey1.pem


 


STEP05 →인증서 적용

※ 인증서가 문제없는지 개인적인 테스트 화면입니다.


 


① Apache ssl.conf 인증서 설정하기


[root@mail ~]# vim /etc/httpd/conf.d/ssl.conf


 


  5 Listen 443 https  [수정 X]


 40 <VirtualHost _default_:443>  [▷ 시작 지점]


 43 DocumentRoot "/home/roundcube"  [홈페이지 경로 변경]

 44 ServerName mail.foxydog.co.kr  [도메인 네임 이름 변경]


 54 SSLEngine on

 85 SSLCertificateFile /etc/letsencrypt/live/mail.foxydog.co.kr/cert.pem  [인증서(CRT) 경로 변경]

 93 SSLCertificateKeyFile /etc/letsencrypt/live/mail.foxydog.co.kr/privkey.pem  [인증서(KEY) 경로 변경]


102 SSLCertificateChainFile /etc/letsencrypt/live/mail.foxydog.co.kr/chain.pem  [체인 인증서(CA) 경로 변경]


202 </VirtualHost>  [◀끝 지점(이 범위 안에 각 옵션 포함 적용)]


 


② Apache 재시작


[root@mail ~]# systemctl restart httpd


 


③ 웹 HTTPS://도메인주소 접속 확인, 브라우저는 에지(Edge)에서 접속



 


STEP06 →인증서 만료 시 갱신 및 (Crontab) 자동 갱신 등록 (정상 확인)

 


① 인증서 만료 시 갱신 (renew 명령어 이용)


[root@mail ~]# certbot renew


Saving debug log to /var/log/letsencrypt/letsencrypt.log


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Processing /etc/letsencrypt/renewal/mail.foxydog.co.kr.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Cert not yet due for renewal


▷ 인증서 갱신 기간이 아닙니다.



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

The following certificates are not due for renewal yet:

  /etc/letsencrypt/live/mail.foxydog.co.kr/fullchain.pem expires on 2021-08-12 (skipped)

No renewals were attempted.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



※ 명령어는 제대로 실행되었지만 발급받은 지 얼마 되지 않았기 때문에 "인증서 갱신 기간이 아닙니다."라는 메시지가 호출이 되네요. 인증서를 처음 발급받았을 때 자동으로 등록되는 환경설정(파라미터) 값을 확인해봅니다.


[root@mail ~]# vi /etc/letsencrypt/renewal/mail.foxydog.co.kr.conf


# renew_before_expiry = 30 days (만료 전 갱신일이 30일로 되어 있음)

version = 1.14.0

archive_dir = /etc/letsencrypt/archive/mail.foxydog.co.kr

cert = /etc/letsencrypt/live/mail.foxydog.co.kr/cert.pem

privkey = /etc/letsencrypt/live/mail.foxydog.co.kr/privkey.pem

chain = /etc/letsencrypt/live/mail.foxydog.co.kr/chain.pem

fullchain = /etc/letsencrypt/live/mail.foxydog.co.kr/fullchain.pem


# Options used in the renewal process

[renewalparams]

account = 개인 값

authenticator = standalone

server = https://acme-v02.api.letsencrypt.org/directory



즉, 발급받은 날 3개월 기준으로 최소 60일이 경과되어야 재발급을 받을 수 있다는 뜻이 됩니다. 물론 강제로 재발급받는 명령어가 있지만 신용도에는 좋지 않으므로 권고하지 않습니다.


 


② (Crontab) 자동 갱신 등록


먼저 자동 실행 스크립트 파일을 하나 만듭니다. 저는 별도의 경로를 만들어서 저장하겠습니다.


[root@mail ~]# mkdir /root/script


[root@mail ~]# vi /root/script/letsencrypt.sh


!/bin/sh

systemctl stop httpd

sleep 10

certbot renew

sleep 10

systemctl start httpd


:wq (값 입력 후 저장)


※ 혹시나 중간에 행 걸리는 것을 막기 위해 약간의 텀을 주었으며, 아파치를 재시작하는 이유는 앞서 말씀드렸듯이 발급 또는 갱신 시 80 포트를 중복으로 사용하지 못하므로 아파치 중지-인증서 갱신-아파치 시작 순으로 작성합니다. 다른 웹서비스일 경우도 동일합니다. 또한 리눅스 방화벽에 80 포트를 오픈 해야 합니다.


 


Crontab 이 실행할 수 있도록 권한을 부여합니다.


[root@mail ~]# chmod +x /root/script/letsencrypt.sh


[root@mail ~]# ls -al /root/script/ | grep letsencrypt.sh

-rwxr-xr-x  1 root root  84 May 20 14:33 letsencrypt.sh


Crontab 편집 모드 에서 만들었던 스크립트를 등록 합니다.


[root@mail ~]# crontab -e


01 00 */80 * * /root/script/letsencrypt.sh


:wq (값 입력 후 저장)


[root@mail ~]# crontab -l

01 00 */80 * * /root/script/letsencrypt.sh


※ 제대로 등록 되었는지 확인을 하시고, 저의 경우는 80일마다 오전 00시 01분에 실행되도록 등록, 안전하게 [70 초과~90 미만] 일 사이의 숫자로 사용자에 맞게 등록하시면 될 것 같습니다.


 


③ Crontab 정상 실행 확인 (80일 경과 후 확인 예정)


[root@mail ~]# cat /var/log/cron-(로테이션) | grep letsencrypt.sh


cron-20210801:Aug  1 00:01:02 mail CROND[33847]: (root) CMD (/root/script/letsencrypt.sh)


정상 실행



 


STEP07 →인증서 갱신 모의 테스트

renew 갱신이 제대로 작동이 되지는 테스트할 수 있는 --dry-run 기능 옵션이 있습니다.


[root@mail log]# certbot renew --dry-run

Saving debug log to /var/log/letsencrypt/letsencrypt.log


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Processing /etc/letsencrypt/renewal/mail.foxydog.co.kr.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Cert not due for renewal, but simulating renewal for dry run

Plugins selected: Authenticator standalone, Installer None

Simulating renewal of an existing certificate for mail.foxydog.co.kr

Performing the following challenges:

http-01 challenge for mail.foxydog.co.kr

Waiting for verification...

Cleaning up challenges


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

new certificate deployed without reload, fullchain is

/etc/letsencrypt/live/mail.foxydog.co.kr/fullchain.pem

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Congratulations, all simulated renewals succeeded:


▷ 축하합니다. 모든 시뮬레이션된 갱신이 성공했습니다. (메시지가 나와야 정상)

  /etc/letsencrypt/live/mail.foxydog.co.kr/fullchain.pem (success)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


[이 게시물은 낙엽타는향기님에 의해 2022-08-17 11:07:35 자유게시판에서 이동 됨]

댓글목록



등록된 댓글이 없습니다.

댓글쓰기

내용
자동등록방지 숫자를 순서대로 입력하세요.
Total 73 / 1 page
검색 열기 닫기
게시물 검색

잡다한 IT 목록