Skip to content

Instantly share code, notes, and snippets.

@kamuridesu
Created July 5, 2023 20:56
Show Gist options
  • Select an option

  • Save kamuridesu/3c904cd069e862d52d82ba8a252321a9 to your computer and use it in GitHub Desktop.

Select an option

Save kamuridesu/3c904cd069e862d52d82ba8a252321a9 to your computer and use it in GitHub Desktop.
HAProxy Load Balancer Config
# /usr/bin/bash
sudo apt update && sudo apt update -y && sudo apt install haproxy curl certbot vim net-tools git -y
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 81 -j ACCEPT
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 80 -j ACCEPT
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 443 -j ACCEPT
sudo netfilter-persistent save
sudo certbot certonly --standalone -d kamuridesu.com -d count.kamuridesu.com -d waifuis.kamuridesu.com -d inv.kamuridesu.com -d rabbit.kamuridesu.com -d www.kamuridesu.com -d notes.kamuridesu.com --non-interactive --agree-tos --email myk.gata14@gmail.com
sudo mkdir -p /etc/ssl/com.kamuridesu/
sudo cat /etc/letsencrypt/live/kamuridesu.com/fullchain.pem /etc/letsencrypt/live/kamuridesu.com/privkey.pem | sudo tee /etc/ssl/com.kamuridesu/com.kamuridesu.pem
sudo bash -c 'cat << EOF > /opt/update-certs.sh
#!/bin/bash
# Renew the certificate
certbot renew --force-renewal --pre-hook "service haproxy stop" --post-hook "service haproxy start"
# Concatenate new cert files, with less output (avoiding the use tee and its output to stdout)
bash -c "cat /etc/letsencrypt/live/kamuridesu.com/fullchain.pem /etc/letsencrypt/live/kamuridesu.com/privkey.pem > /etc/ssl/com.kamuridesu/com.kamuridesu.pem"
EOF'
cat /opt/update-certs.sh
vim /etc/cron.d/certbot
sudo vim /etc/cron.d/certbot
sudo systemctl enable haproxy
sudo systemctl start haproxy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment