Versões utilizada: Debian 10 + Certbot + HAProxy
Baixe o pacote
# apt-get install certbot
Escolhi o HAProxy para armazenar e regerar os certificados devida a sua conexão com a internet.
Criando certificado
# /etc/init.d/haproxy stop
# certbot certonly --standalone --email suportetecnico@dominio.com.br -d www.dominio.com.br -d dominio.net.br
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: a <- Selecione A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing 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: n <- Se deseja receber emails selecione Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for www.dominio.com.br
http-01 challenge for dominio.net.br
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/www.dominio.com.br/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/www.dominio.com.br/privkey.pem
Your cert will expire on 2021-06-03. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"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
Execute o comando para simular a atualização
# certbot renew --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates below have not been saved.)
No renewals were attempted.
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# /etc/init.d/haproxy stop
# certbot certonly --standalone --email suportetecnico@dominio.com.br -d site1.domain.com -d site2.domain.net.br
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
You have an existing certificate that contains a portion of the domains you
requested (ref: /etc/letsencrypt/renewal/zabbix.santacasacuritiba.com.br.conf)
It contains these names: site1.domain.com
You requested these names for the new certificate:
site1.domain.com, site2.domain.net.br.
Do you want to expand and replace this existing certificate with the new
certificate?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(E)xpand/(C)ancel: E <- Precione E para expandir o certificado atual
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for site2.domain.net.br
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/site1.domain.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/site1.domain.com/privkey.pem
Your cert will expire on 2021-06-07. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"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
Criar repositório para a integração do certificado e chave
# mkdir /etc/haproxy/certs
# cat /etc/letsencrypt/live/www.dominio.com.br/fullchain.pem /etc/letsencrypt/live/www.dominio.com.br/privkey.pem > /etc/haproxy/certs/dominio.pem
Ajustar as configurações do HAProxy, edite o arquivo:
# vi /etc/haproxy/haproxy.cfg
global
...
tune.ssl.default-dh-param 4096
....
frontend HTTP
...
# Caso exista algum redirecionamento para site https
redirect scheme https if { hdr(host) -i site1.domain.com.br } !{ ssl_fc }
redirect scheme https if { hdr(host) -i site2.domain.com.br } !{ ssl_fc }
...
frontend HTTPS
bind *:443 ssl crt /etc/haproxy/certs/cert1.pem
# Mais de um certificado adicionar crt /path/to/cert2.pem
reqadd X-Forwarded-Proto:\ https
stats uri /haproxy?stats
stats hide-version
stats enable
stats refresh 30s
stats show-legends
stats show-node
stats auth admin:password
acl SITE1 hdr(host) -i site1.domain.com.br
use_backend SITE1 if SITE1
acl SITE2 hdr(host) -i site2.domain.com.br
use_backend SITE2 if SITE2
backend ZABBIX
server SRV1 <IP_SERVER>:80 check
backend GLPI
server SRV1 <IP_SERVER>:80 check
Reinicie o serviço HAProxy
# systemctl restart haproxy.service
Criar o script de criação ou adição de novos nomes
# vi /home/createcert.sh
#!/usr/bin/env bash
# STOP HAProxy
/usr/bin/systemctl stop haproxy.service
# criar o certificado
/usr/bin/certbot certonly --standalone --email suporte@domain.com.br -d site1.domain.com.br -d site2.domain.com.br
#/usr/bin/certbot certonly --standalone --email suporte@domain2.com.br -d site1.domain2.com.br -d site2.domain2.com.br
# STRAT HAProxy
/usr/bin/systemctl start haproxy.service
O certificado tem 90 dias de vida, quando completado 70 dias o sistema LetsEncrypt automaticamente encaminha email com aviso sobre a renovação. Quando completado 81 dias o sistema LetsEncrypt automaticamente encaminha email com aviso sobre a necessidade de renovação, e para realizar a renovação do certificado bastas seguir os passos abaixo.
Criar o script de renovação
# vi /home/renewletsencrypt.sh
#!/usr/bin/env bash
# STOP HAProxy
/usr/bin/systemctl stop haproxy.service
/usr/bin/certbot renew --quiet
# DOMAIN1
/bin/cat /etc/letsencrypt/live/domain1.com/fullchain.pem /etc/letsencrypt/live/domain1.com/privkey.pem > /etc/haproxy/certs/domain1.pem
# DOMAIN2
/bin/cat /etc/letsencrypt/live/domain2.com/fullchain.pem /etc/letsencrypt/live/domain2.com/privkey.pem > /etc/haproxy/certs/domain2.pem
# START HAProxy
/usr/bin/systemctl start haproxy.service
Ajuste a permissão do arquivo
# chmod 755 /home/renewletsencrypt.sh /home/createcert.sh
Agendar a renovação do certificado
# crontab -u root -e
#10 0 1 * * /home/renewletsencrypt <- Todo dia 1 de todos os meses à 00:10
01 3 * * * /home/renewletsencrypt <- Todos os dias à 03:01
<- Lembre-se de deixar a última linha em branco
Para forçar a renovação do certificado, utilize o comando abaixo:
# /usr/bin/certbot certonly --standalone --force-renew -d domain1.com -d www.domain.com
# /usr/bin/certbot certonly --standalone --force-renew -d domain2.com.br -d www.domain2.com.br
* Caso algum domínio falhe na renovação ou não é mais usado, é possivel remover este domínio para não ocorrer falha na renovação.
* Remova os arquivos que fazem referencia ao domínio que deseja remover
# /etc/letsencrypt/archive/<DOMINIO>
# /etc/letsencrypt/live/<DOMINIO>
# /etc/letsencrypt/renewal/<DOMINIO>.conf
* Execute o processo de criação novamente retirando a entrada do domínio que não será mais usado.
**** Para realizar a revogação do certificado (Em teste)
# certbot revoke -d dominio.com.br --cert-path /etc/letsencrypt/live/www.dominio.com.br/cert.pem