mirror of
http://git.nowherejezfoltodf4jiyl6r56jnzintap5vyjlia7fkirfsnfizflqd.onion/nihilist/selfhosting-blogposts.git
synced 2025-05-17 04:36:58 +00:00
53 lines
1.5 KiB
Markdown
53 lines
1.5 KiB
Markdown
# Haproxy setup
|
|
|
|
This one is done from proxmox, i used a debian10+ CT template to create the machines i needed.
|
|
|
|
## **Initial setup**
|
|
|
|
To start with, get 2 identical debian hosts with nginx on them:
|
|
|
|

|
|
|
|
My 2 servers will have the ips 192.168.0.151 and 192.168.0.150 meanwhile 192.168.0.152 is going to be our haproxy server.
|
|
|
|
_First server:_
|
|
|
|
|
|
apt update -y && apt upgrade -y
|
|
apt install nginx curl -y
|
|
echo 'server number 1' > /var/www/html/index.nginx-debian.html
|
|
ip a | grep inet #IP1
|
|
|
|
|
|
|
|
 _Second server:_
|
|
|
|
|
|
apt update -y && apt upgrade -y
|
|
apt install nginx curl -y
|
|
echo 'server number 2 ' > /var/www/html/index.nginx-debian.html
|
|
ip a | grep inet #IP2
|
|
|
|
|
|
|
|

|
|
|
|
Now that we have 2 servers running http, we're going to load balance them with a third debian machine with haproxy:
|
|
|
|
|
|
apt update -y && apt upgrade -y
|
|
apt install haproxy curl -y
|
|
wget https://blog.nowhere.moe/servers/haproxy/haproxy.cfg -O /etc/haproxy/haproxy.cfg
|
|
nano /etc/haproxy/haproxy.cfg
|
|
systemctl restart haproxy
|
|
ip a | grep inet #IP3
|
|
curl 127.0.0.1
|
|
|
|
|
|
|
|
In nano, change the ips with the ips of your 2 debian servers (IP1 & IP2) and reload haproxy, then go and see if haproxy works (IP3)
|
|
|
|

|
|
|
|
You can reload haproxy's webpage multiple times, and you'll see that sometimes it is going to switch from one server to the other, therefore we successfully setup a simple load balancing with haproxy.
|
|
|