«

»

Kas 05

Moodle Cluster Yapısında HAproxy Load Balancer

global
maxconn 23200000
log /dev/log local0 info
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon

# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private

# See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate
ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE>
ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets
tune.ssl.default-dh-param 2048

defaults
log global
mode http
option httplog
option dontlognull
option forwardfor # istemci IP’sini nginx’e gönder yoksa, nginx’te istemci IP’si yerine HAProxy IP’si görünür.
timeout connect 10s
timeout client 100s
timeout server 100s
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
errorfile 429 /etc/haproxy/errors/429.http
default_backend MOODLE

# Frontend configuration for HTTP
# Only listens on port 80 (IPv4 and IPv6)
frontend frontend-http
bind :80 name http
#redirect scheme https code 301 if !{ ssl_fc }
#redirect scheme https if !{ ssl_fc }
# ACL for detecting Let’s Encrypt validtion requests
acl is_certbot path_beg /.well-known/acme-challenge/
acl http ssl_fc,not
http-request set-header X-Forwarded-Protocol http if http
#http-request redirect scheme https if http
use_backend backend-certbot if is_certbot

# Frontend configuration for HTTPS
# Only listens on port 443 (IPv4 and IPv6)
frontend frontend-https
bind :443 name https ssl crt /etc/haproxy/ssl/
# ACL for detecting Let’s Encrypt validtion requests
acl is_certbot path_beg /.well-known/acme-challenge/
acl https ssl_fc
http-request set-header X-Forwarded-Protocol https if https

# istek süresi limitleri
acl whitelist src 10.1.1.0/24
stick-table type ip size 100k expire 60s store http_req_rate(10s) # Son 10 saniyenin “client ve bağlantı sayısı” değerlerini key-value şeklinde tutmak için tablo oluşturuyor. Tabloda toıplam 100K tane kayıt olabilecek ve 60s esk>
http-request track-sc0 src if ! whitelist
http-request deny deny_status 429 if { sc_http_req_rate(0) gt 40 } # Belirlenen zamanda 40’ı geçerse ban’la!
# tabloyu görüntüleme komutu: echo “show table frontend-https” | socat stdio UNIX-CONNECT:/var/run/haproxy/admin.sock
use_backend backend-certbot if is_certbot

# Engellenecek varsa asagiya yaz
acl blacklist src 10.1.1.1 # blacklist boş kalmasın diye kullanılmayan bu IP’yi bırakıldı.
use_backend YASAK if blacklist

# Testler için belirli kaynak IP’den gelenleri hep aynı sunucuya yönlendir
acl tester_ipleri src 10.1.199.96 10.1.1.87
use_backend TEST if tester_ipleri

backend TEST
# standart frontend içinde testter_ipleri diye bir ACL oluşturup onu buraya yönlendiriyoruz.
redirect scheme https if !{ ssl_fc }
balance source
server TEST_MOODLE 10.1.1.111:80 check inter 1s # maxconn 1

backend YASAK
# yukarıda, frontend içinde blacklist isimli bir IP kara liste oluşturuldu. Onlar bu backend’e geliyor ve yasak.http web sayfasını görüyor. Aynı sistem, bakım yapmak için de kullanılabilir belki.
mode http
errorfile 503 /etc/haproxy/errors/yasak.http # 503 numaralı hatasını kullanarak belirttiğimiz web sayfasını varsayılan olarak gönderiyoruz buradan

# Default backend
# moodle cluster sunucuları 2 tane artırılabilir.
backend MOODLE
redirect scheme https if !{ ssl_fc }
balance source
server lms01 10.1.1.121:80 check inter 1s # maxconn 1
server lms02 10.1.1.131:80 check inter 1s
# Certbot backend
# Contains certbot stand-alone webserver
backend backend-certbot
server certbot 127.0.0.1:9123
#webten ipadresi:8443/stats ile ha statsları incelenir alttaki tanımlanan user ve pass ile giriş yapılır.
frontend stats
bind *:81
bind *:8443 ssl crt /etc/haproxy/ssl/
option http-use-htx
http-request use-service prometheus-exporter if { path /metrics }
stats enable # enable statistics reports
stats hide-version # Hide the version of HAProxy
stats refresh 10s # HAProxy refresh time
stats show-node # Shows the hostname of the node
stats auth user:pass # Enforce Basic authentication for Stats page
stats uri /stats # Statistics URL

haproxy -f /etc/haproxy/haproxy.cfg -c -V (mevcut config dosyasının valid olup olmadığını kontrol etmek için kullanıyoruz.) Buradan invalid alırsak servisi restart etmeyiniz!!!

Bir Cevap Yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

AlphaOmega Captcha Classica  –  Enter Security Code
     
 

Şu HTML etiketlerini ve özelliklerini kullanabilirsiniz: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>