{"id":1305,"date":"2009-10-16T10:35:38","date_gmt":"2009-10-16T15:35:38","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=1305"},"modified":"2009-10-16T10:37:33","modified_gmt":"2009-10-16T15:37:33","slug":"apache-2-load-balancing","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=1305","title":{"rendered":"Apache 2 Load Balancing"},"content":{"rendered":"<span id=\"DNS_load_sharing\"><h2>DNS load sharing<\/h2><\/span>\n<p>Pros:<br \/>\n* Protocol independent: supports web, ftp, etc.<\/p>\n<p>Cons:<br \/>\n* Session not sticky<br \/>\n* Fail over only. No load sharing<\/p>\n<span id=\"Redirected_Secondary_Name_Server\"><h3>Redirected Secondary Name Server<\/h3><\/span>\n<p>* Set primary web server as primary name server and TTL to long (e.g. 30 min) so it can be cached.<br \/>\n* Set secondary web server as secondary name server.<br \/>\n* Works only when whole machine goes down so both DNS and Web servers go down.<\/p>\n<span id=\"Load_Sharing_with_Round_Robin_DNS\"><h3>Load Sharing with Round Robin DNS<\/h3><\/span>\n<p>* Need BIND 4.9 and above.<br \/>\n* Setup round robin configuration:<\/p>\n<pre>\r\nwww.my.com.   300   IN  A       192.168.100.1\r\nwww.my.com.   300   IN  A       192.168.100.2\r\nwww.my.com.   300   IN  A       192.168.100.3\r\n<\/pre>\n<p>* Set TTL short so it won&#8217;t be cached (e.g. 5 min or 300 sec).<\/p>\n<span id=\"Software_Based_Clustering\"><h2>Software Based Clustering<\/h2><\/span>\n<span id=\"Floating_IP_Failover\"><h3>Floating IP Failover<\/h3><\/span>\n<p>* Each server has its own IP. A floating or virtual IP is assigned to primary server normally and backup web during failover.<br \/>\n* No need for DNS servers.<\/p>\n<h4>Linux Virtual Server<\/k4><\/p>\n<span id=\"Ultra_Monkey\"><h4>Ultra Monkey<\/h4><\/span>\n<p>* Servers involved must all be in the same local network with no intermediate routers involved.<\/p>\n<span id=\"Super_Sparrow\"><h4>Super Sparrow<\/h4><\/span>\n<p>* Allows distributed clustering.<\/p>\n<span id=\"Apache_Load_Balancing\"><h3>Apache Load Balancing<\/h3><\/span>\n<p>* Set up one Apache as dedicated proxy server<\/p>\n<pre>\r\n# Apache Server Configuration for Clustering Proxy\r\n#\r\n### Basic Server Setup\r\n\r\n# The proxy takes the identity of the web site...\r\nServerName               www.alpha-complex.com\r\n\r\n# Basic configuration.\r\n# Note that the DocumentRoot is a 'safe' irrelevant value as we don't serve\r\n# anything directly\r\nServerAdmin              webmaster@alpha-complex.com\r\nServerRoot               \/usr\/local\/apache\r\nDocumentRoot             \/usr\/local\/apache\/proxysite\r\nErrorLog                 \/usr\/local\/apache\/proxy_error\r\nTransferLog              \/usr\/local\/apache\/proxy_log\r\n\r\n# Choose a non-privileged user and group\r\nUser httpd\r\nGroup httpd\r\n\r\n# Dynamic servers load their modules here...\r\n# Note that if this proxy is only a proxy, we don't need most standard\r\n# modules loaded.\r\n\r\n# Don't waste time on things we don't need\r\nHostnameLookups off\r\n\r\n# This server is only for proxying so switch off everything else\r\n<Directory \/>\r\n  Options None\r\n  AllowOverride None\r\n<\/Directory>\r\n\r\n# Allow a local client to access the server status\r\n<Location \/>\r\n  order allow,deny\r\n  deny from all\r\n  allow from 127.0.0.1\r\n  SetHandler server-status\r\n<\/Location>\r\n\r\n### Part 1 - Rewrite\r\n\r\n# switch on URL rewriting\r\nRewriteEngine on\r\n\r\n# Define a log for debugging but set the log level to zero to disable it for #\r\nperformance\r\nRewriteLog logs\/proxy_rewrite\r\nRewriteLogLevel 0\r\n\r\n# define the cluster servers map\r\nRewriteMap cluster rnd:\/usr\/local\/apache\/rewritemaps\/cluster.txt\r\n\r\n# rewrite the URL if it matches the web server host\r\nRewriteRule ^http:\/\/www\\.(.*)$ http:\/\/{cluster:www}.$2 [P,L]\r\n\r\n# forbid any URL that doesn't match\r\nRewriteRule .* - [F]\r\n\r\n### Part 2 - Proxy\r\n\r\nProxyPassReverse  \/  http:\/\/wwwl.alpha-complex.com\/\r\nProxyPassReverse  \/  http:\/\/www2.alpha-complex.com\/\r\nProxyPassReverse  \/  http:\/\/www3.alpha-complex.com\/\r\nProxyPassReverse  \/  http:\/\/www4.alpha-complex.com\/\r\nProxyPassReverse  \/  http:\/\/www5.alpha-complex.com\/\r\nProxyPassReverse  \/  http:\/\/www6.alpha-complex.com\/\r\n\r\n# We don't want caching, preferring to let the back end servers take the\r\n# load, but if we did:\r\n#\r\n# Apache 2.0 only:\r\nCacheOn on\r\nCacheEnable disk \/\r\n# Apache 2.0 and 1.3:\r\n#CacheRoot \/usr\/local\/apache\/proxy\r\n#CacheSize 102400\r\n<\/pre>\n<span id=\"Hardware_Based_Load_Clustering\"><h2>Hardware Based Load Clustering<\/h2><\/span>\n<span id=\"F5_Big-IP\"><h3>F5 Big-IP<\/h3><\/span>\n<span id=\"Cisco_MNLB\"><h3>Cisco MNLB<\/h3><\/span>\n<span id=\"ServerIron\"><h3>ServerIron<\/h3><\/span>\n<span id=\"Nortel_Alteon\"><h3>Nortel Alteon<\/h3><\/span>\n<span id=\"References\"><h2>References<\/h2><\/span>\n<p>Professional Apache 2.0 by Peter Wainwright<br \/>\nThe Linux Enterprise Cluster by Karl Kopper<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DNS load sharing Pros: * Protocol independent: supports web, ftp, etc. Cons: * Session not sticky * Fail over only. No load sharing Redirected Secondary Name Server * Set primary web server as primary name server and TTL to long &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=1305\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[61],"tags":[],"class_list":["post-1305","post","type-post","status-publish","format-standard","hentry","category-linux"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-l3","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1305"}],"version-history":[{"count":2,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1305\/revisions"}],"predecessor-version":[{"id":1307,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1305\/revisions\/1307"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}