Cara Setup Load Balancer Dengan HAProxy Di Linux Ubuntu/Debian/Centos/Redhat

Haproxy bukan sekedar load balancer biasa lho guys, berikut fiturnya diambil dari sumber wikipedia:

Oke BW, Mau setup loadbalancer dengan haproxy? Cekidot!

Install haproxy:

Ubuntu/Debian

sudo apt-get -y install haproxy

Centos/Redhat

sudo yum install haproxy Katakanlah kita memiliki skema sebagai berikut:

Cara Setup Load Balancer Dengan HAProxy Di Linux Ubuntu/Debian/Centos/Redhat

Maka pastikan server yang akan kita set sebagai backend
(Khusus Centos/Redhat)

#firewall-cmd --permanent --zone=public --add-service=http

#firewall-cmd --permanent --zone=public --add-service=https
#firewall-cmd --permanent --zone=public --add-port=8181/tcp

#firewall-cmd --permanent --zone=public --add-port=8080/tcp

#firewall-cmd --permanent --zone=public --add-port=80/tcp

#firewall-cmd --permanent --zone=public --add-port=22/tcp

#firewall-cmd --permanent --zone=public --add-port=443/tcp

#firewall-cmd --reload

Buka file /etc/haproxy/haproxy.cfg dan edit menjadi:

global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http

frontend Ayies-LB-devops
bind *:80
reqadd X-Forwarded-Proto:\ http
default_backend devopsapi
stats enable
stats uri /ayies-lb?stats
stats realm Strictly\ Private
stats auth admin:ayiespassword
#settingan let's encrypt untuk SSL
#bind *:443 ssl crt /etc/ssl/certs/devopsapi.ayies.com.pem
bind *:443 ssl crt /etc/ssl/certs/ayies.com.pem
reqadd X-Forwarded-Proto:\ https
acl devopsapi hdr(host) -i devopsapi.ayies.com

use_backend devopsapi if devopsapi

# Redirect if HTTPS is *not* used
redirect scheme https code 301 if !{ ssl_fc }

acl letsencrypt-acl path_beg /.well-known/acme-challenge/
use_backend letsencrypt-backend if letsencrypt-acl

#ini backend let's encrypt
backend letsencrypt-backend
server letsencrypt 127.0.0.1:8888

backend devopsapi
balance roundrobin
#option forwardfor
#option httpchk
option http-keep-alive
option forwardfor
cookie SRVNAME insert
redirect scheme https if !{ ssl_fc }
server Devopsapi-Ayies1 192.168.5.68:80 cookie SA check verify none
server Devopsapi-Ayies2 192.168.5.62:80 cookie SB check verify none

Acess the Haproxy control panel with this url: http://IPADDRESS/ayies-lb?stats

Untuk detail project haproxy klik link ini: haproxy


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *