11. Load Balancing

advertisement
Administrasi Server
Load Balancing
Load Balancing
• Load balancing means the ability to spread the load of
processing for an application over a number of separate
systems for an overall performance increase in processing
incoming requests.
• Simple?
• Hanya membagi tugas kah?
• Pemisahan Web Server & Database Server apakah termasuk
load balancing?
Load Balancing
• Load Balacing: Mendistribusikan Resource.
• Resource: Processor, Memory, Network, Storage
• On top of creating actions and responses, your processor also
powers your operating system
• RAM overutilization is not as big a problem as CPU
overconsumption but it can still cause significant performance
impact
• Network for monitoring bandwidth with tools bwm-ng, ping,
and traceroute
• Disk (storage) for monitoring disk usage with tools du and df
top
Prinsip Load balancing
Primary principles:
• Split applications over a number of servers, balancing the load
over a number of servers (such as separate web and database
servers).
• Add specialist components to applications in order to balance
the amount of processing needed for each application
function,
– Caching of common web site data, saving time on the collection of this
data from disk, or the creation of this data from database entries, etc.
• Create additional servers that can collectively share the load,
which can greatly increase the amount of processing power
available to complete the tasks required by a server.
Perancangan Load Balancing
Guiding Principles
• Understand your system
• Planning
• Monitoring and Testing
Topics
• Load Balancing Your Website
• Load Balancing Your Database
• Network Load Balancing
Load Balancing your Webiste
• Contoh kasus: Apache
• Apakah Apache yang terinstall sudah maksimal?
• Memaksimalkan Apache:
- Disable Modul yang tidak dibutuhkan
- Disabling DNS lookups
- Compression
Load Balancing your Website
Load Balancing your Website
• Distribute all incoming connections to your web site to a
number of different web servers by using one or more load
balancing servers.
• Reduce the overall load on the web servers, you also have
good means of failover in case one of the web servers
temporarily breaks down.
• The simplest setup requires at least two web servers and one
load-balancing server.
Load Balancing your Website
Load Balancing your Website
• Preparing the server
• Preparing the workers
• Testing the Load Balancer
Load Balancing your Website
Load Balancing your Database
• MySQL Cluster will depend on several nodes working
together.
• One or more cluster management nodes to manage,
configure, and oversee your cluster, one (though commonly
several) data nodes on which to store your data, and one or
more MySQL nodes (traditional MySQL servers) that execute
SQL queries.
Load Balancing your Database
Network Load Balancing
• Sharing the workload
• Basic Routing
• Basic network connectivity testing
Network Load Balancing
Load Balancing Scheduling
Algorithm
•
•
•
•
•
Round Robin
Least Connection
Source
URI
URL parameter
HTTP LOAD BALANCING DENGAN
HAPROXY
Topologi
Konfigurasi HAProxy (1)
• Instalasi HAProxy
− sudo apt-get install haproxy
• Enable haproxy
– Buka file /etc/default/haproxy
– Ubah bagian opsi ENABLED menjadi ENABLED=1
– Simpan perubahan
• Konfigurasi file /etc/haproxy/haproxy.cfg
– Detail file konfigurasi ada di 3 slide selanjutnya
File Konfigurasi haproxy.cfg
global
log /dev/log
log /dev/log
user haproxy
group haproxy
daemon
……
local0
local1 notice
File Konfigurasi haproxy.cfg (cont.)
…….
defaults
log
global
mode
http
option httplog
option dontlognull
contimeout 5000
clitimeout 50000
srvtimeout 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
File Konfigurasi haproxy.cfg (cont.)
…….
nama load balancer
IP/Port load balancer
listen webfarm 0.0.0.0:80
mode http
stats enable
algoritma load
stats uri /haproxy?stats
balancing
balance roundrobin
option httpclose
IP/Port webserver 1
option forwardfor
server webserver1 10.34.8.22:80 check
server webserver2 10.34.8.23:80 check
IP/Port webserver 2
Konfigurasi HAProxy (2)
• Restart service haproxy
– sudo service haproxy restart
• Catatan khusus : jika haproxy tidak dapat di-start/restart
karena error socket binding, stop service apache2
– sudo service apache2 stop
Pengujian HAProxy
• Ubah isi file /var/www/html/index.html pada webserver1
– <h1> Webserver 1</>
• Ubah isi file /var/www/html/index.html pada webserver2
– <h1> Webserver 2</>
• Lakukan akses ke alamat load balancer lewat browser
Terima Kasih
Download