當你開始接觸 clustering 時就會發覺, 原來沒學 clustering 根本等於沒有學 Unix / Linux.
我們一般情況用到的 SERVER / Client 只是皮毛. Clustering 一個字, 內裹包含了多種技術,
HPC – High performance computing
Server Load balancing 負載平衡
DNS round robin
LVS – ipvsadm
HA – High availability
DRBD - http://www.drbd.org/
今天所談的是入門級的 clustering, LVS
LVS – Linux virtual server主要是用作負載平衡 與 HA,
What is the Linux Virtual Server?
The Linux Virtual Server is a highly scalable and highly available server built on a cluster of real servers, with the load balancer running on the Linux operating system. The architecture of the server cluster is fully transparent to end users, and the users interact as if it were a single high-performance virtual server.
負載平衡的意思是把一部服務器的工作分到多部服務器之上. 由一個服務器為主人 ( Master ), 其他為幫手 ( node ). 如下圖
- rr – Robin Robin: distributes jobs equally amongst the available real servers.
- wrr – Weighted Round Robin: assigns jobs to real servers proportionally to there real servers’ weight. Servers with higher weights receive new jobs first and get more jobs than servers with lower weights. Servers with equal weights get an equal distribution of new jobs.
- lc – Least-Connection: assigns more jobs to real servers with fewer active jobs.
- wlc – Weighted Least-Connection: assigns more jobs to servers with fewer jobs and relative to the real servers’ weight (Ci/Wi). This is the default.
- lblc – Locality-Based Least-Connection: assigns jobs destined for the same IP address to the same server if the server is not overloaded and available; otherwise assign jobs to servers with fewer jobs, and keep it for future assignment.
- lblcr – Locality-Based Least-Connection with Replication: assigns jobs destined for the same IP address to the least-connection node in the server set for the IP address. If all the node in the server set are over loaded, it picks up a node with fewer jobs in the cluster and adds it in the sever set for the target. If the server set has not been modified for the specified time, the most loaded node is removed from the server set, in order to avoid high degree of replication.
- dh – Destination Hashing: assigns jobs to servers through looking up a statically assigned hash table by their destination IP addresses.
- sh – Source Hashing: assigns jobs to servers through looking up a statically assigned hash table by their source IP addresses.
- sed – Shortest Expected Delay: assigns an incoming job to the server with the shortest expected delay. The expected delay that the job will experience is (Ci + 1) / Ui if sent to the ith server, in which Ci is the number of jobs on the the ith server and Ui is the fixed service rate (weight) of the ith server.
- nq – Never Queue: assigns an incoming job to an idle server if there is, instead of waiting for a fast one; if all the servers are busy, it adopts the Shortest Expected Delay policy to assign the job.
source: Man page of ipvsadm
- NAT (Network address translation)
- DR – direct routing
以下是 LVS – NAT LOAD BALANCING 的參考
VS via NAT, source: http://www.linuxvirtualserver.org/VS-NAT.html
在 Master (NAT)
echo 1 > /proc/sys/net/ipv4/ip_forward
ipvsadm -A -t 192.168.7.200:80 -s rr
ipvsadm -a -t 192.168.7.200:80 -r 192.168.7.201:80 -m
ipvsadm -a -t 192.168.7.200:80 -r 192.168.7.202:80 -m
ipvsadm -a -t 192.168.7.200:80 -r 192.168.7.203:80 -m
ipvsadm -L –stats (現時的連接情況)
Set default route to 192.168.7.200
route add default gw 192.168.7.000
||Www – web 服務器的 port number
||Round robin 策略
Thanks, 有興趣多討論請跟我連絡 email@example.com !!