Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaling #12

Open
shehabadel opened this issue Jun 25, 2022 · 3 comments
Open

Scaling #12

shehabadel opened this issue Jun 25, 2022 · 3 comments

Comments

@shehabadel
Copy link
Owner

  • Installed HaProxy on virtual machine
  • Create configuration dist.cfg
frontend distFE
	bind *:80
	timeout client 1000s
	mode http
	use_backend distBE

backend distBE
	mode http
	timeout server 1000s
	timeout connect 1000s
	server ws1 https://dist-ws1.herokuapp.com/
	server ws2 https://dist-ws2.herokuapp.com/

  • Run in a terminal haproxy -f dist.cfg
@shehabadel
Copy link
Owner Author

shehabadel commented Jun 25, 2022

  • Open a dns and point to the ip of the virtual machine in A record

  • Generate SSL

sudo apt install letsencrypt
sudo certbot certonly --standalone

Enter dns for example: distproxy.ddns.net

then concatenate the output certificates

sudo cat `/etc/letsencrypt/live/<name of the domain>/fullchain.pem` `/etc/letsencrypt/live/<name of the domain>/privkey.pem` | sudo tee /haproxy.pem

Now modify the dist.cfg to be like that

frontend distFE
	bind *:80
        bind *:443 ssl crt /haproxy.pem
	timeout client 1000s
	mode http
	default_backend distBE

backend distBE
	mode http
	timeout server 1000s
	timeout connect 1000s
	server ws1 https://dist-ws1.herokuapp.com
	server ws2 https://dist-ws2.herokuapp.com

@shehabadel
Copy link
Owner Author

Dead end

@shehabadel
Copy link
Owner Author

shehabadel commented Jun 26, 2022

Switched to NGINX instead of HAProxy

  1. Create a load-balancer.conf file to configure the NGINX Server

sudo nano /etc/nginx/conf.d/load-balancer.conf

  1. Write the following configuration
# Define which servers to include in the load balancing scheme. 
# It's best to use the servers' private IPs for better performance and security.
http {
   upstream ws {
	    ip_hash;
	    server dist-ws1.herokuapp.com;
	    server dist-ws2.herokuapp.com;
	}

   # This server accepts all traffic to port 80 and passes it to the upstream. 
   # Notice that the upstream name and the proxy_pass need to match.

   server {
   	listen 80;
      	server_name disthaproxy.ddns.net;

      location / {
       #Upgrading the connection in order to establish the websocket connection
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://ws;
    }
   }
   
   server {
   listen 443 ssl;
   server_name disthaproxy.ddns.net;
   ssl_certificate #/etc/letsencrypt/live/<7ot path el domain hena>/cert.pem;
   ssl_certificate_key /etc/letsencrypt/live/<7ot path el domain hena>/privkey.pem;
   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

   location / {
        #Upgrading the connection in order to establish the websocket connection
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://ws;
    }
}

}
  1. Remove the default configuration
    sudo rm /etc/nginx/sites-enabled/default

  2. Restart NGINX
    sudo systemctl restart nginx

IP hashing method instead. IP hashing uses the visitors IP address as a key to determine which host should be selected to 
service the request. This allows the visitors to be each time directed to the same server, granted that the server is available and
the visitor’s IP address hasn’t changed.

@shehabadel shehabadel changed the title Scaling - HaProxy Scaling Jun 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant