
Load Balancing, İsminden olduğu gibi Yük dengeleme işlemi yapmaktadır olası bir DoS/DDoS (Layer7 / HTTP) Olarak bir flood halinde veya yüksek miktarda organik ziyaretçiyi sunucuların anlık olarak taşıması için yapılan önemli bir işlemdir. Bu işlemi birden fazla sunucunun güçlerini birleştirerek tek bir sitede toplamak olarak düşünebiliriz.
Fiziki olarak gerçek anlamda verim vermektedir ancak yazılımsal olarak yapacak olursak bu işi en stabil “HAProxy” yazılımı kullanılması daha verimli olacaktır.
Kurulumu,
$ wget http://www.haproxy.org/download/2.4/src/devel/haproxy-2.4-dev7.tar.gz $ tar xvfz haproxy-2.4-dev7.tar.gz $ rm haproxy-2.4-dev7.tar.gz $ cd haproxy-2.4-dev7 $ make install $ mkdir /etc/haproxy $ cd /etc/haproxy $ nano haproxy.cfg
haproxy.cfg içerisine yapıştırın;
global daemon maxconn 20000 # count about 1 GB per 20000 connections pidfile /var/run/haproxy.pid stats socket /var/run/haproxy.stat mode 600 defaults mode http maxconn 19500 # Should be slightly smaller than global.maxconn. timeout client 60s # Client and server timeout must match the longest timeout server 60s # time we may wait for a response from the server. timeout queue 60s # Don't queue requests too long if saturated. timeout connect 4s # There's no reason to change this one. timeout http-request 5s # A complete request may never take that long. # Uncomment the following one to protect against nkiller2. But warning! # some slow clients might sometimes receive truncated data if last # segment is lost and never retransmitted : # option nolinger option http-server-close option abortonclose balance roundrobin option forwardfor # set the client's IP in X-Forwarded-For. option tcp-smart-accept option tcp-smart-connect retries 2 frontend public bind 192.168.1.1:80 bind 192.168.1.2:80 bind 192.168.1.3:80 bind 192.168.1.4:80 # table used to store behaviour of source IPs stick-table type ip size 200k expire 5m store gpc0,conn_rate(10s) # IPs that have gpc0 > 0 are blocked until the go away for at least 5 minutes acl source_is_abuser src_get_gpc0 gt 0 tcp-request connection reject if source_is_abuser # connection rate abuses get blocked acl conn_rate_abuse sc1_conn_rate gt 30 acl mark_as_abuser sc1_inc_gpc0 gt 0 tcp-request connection track-sc1 src tcp-request connection reject if conn_rate_abuse mark_as_abuser default_backend apache backend apache # set the maxconn parameter below to match Apache's MaxClients minus # one or two connections so that you can still directly connect to it. stats uri /haproxy?stats server srv 0.0.0.0:8181 maxconn 254 # Enable the stats page on a dedicated port (8811). Monitoring request errors # on the frontend will tell us how many potential attacks were blocked. listen stats # Uncomment "disabled" below to disable the stats page : # disabled bind :1881 stats uri /
Dosya, 192.168.1.1’den 192.168.1.4’e kadar kendi sunucu ip adresinizle değiştirip güncelleyiniz .Dördüncü Adım: Yapılandırma dosyasında olduğu gibi, Apache bağlantı noktanız. Srv 0.0.0.0:8181 maxconn 254. Tweak’ten WHM Ayarlarında ve Apache’nin SSL olmayan IP / portu bulun ve 8181 olarak değiştiriniz. Ardından “ctrl + x ve y” yaparak kaydedip çıkın.
Ardından kullandığınız web servisini tekrar başlatın ve son komutları girelim,
$ /etc/init.d/apache2 restart $ haproxy -f /etc/haproxy/haproxy.cfg
İstatistikleri kontrol etmek için;
http://serverip:1881
Adresine girip kontrol edebilirsiniz.
Videolu anlatım,
Güvenle Kalın.