<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4320291428541680545</id><updated>2012-02-16T11:47:11.465-08:00</updated><title type='text'>Being a hero</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://zorovn78.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4320291428541680545/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://zorovn78.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Roronoa Zoro</name><uri>http://www.blogger.com/profile/00621746649739064085</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4320291428541680545.post-2838397307002726799</id><published>2009-07-01T01:10:00.000-07:00</published><updated>2009-07-01T01:13:26.819-07:00</updated><title type='text'>How to configure caching-nameserver (named) in cascading mode</title><content type='html'>&lt;h3&gt;&lt;u&gt;&lt;strong&gt;Mission&lt;/strong&gt;&lt;/u&gt;&lt;/h3&gt; &lt;p&gt;To configure a caching nameserver on a local machine which will cascade to another previously configured and functional nameserver (may or may not be caching. It'll generally be your ISP nameserver or the one provided by your organization).&lt;/p&gt; &lt;h3&gt;&lt;u&gt;&lt;strong&gt;Advantage&lt;/strong&gt;&lt;/u&gt;&lt;/h3&gt; &lt;ul&gt;&lt;li&gt;Reduces the delay in domain name resolution drastically as the requests for frequently accessed websites are served from cache.&lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;&lt;u&gt;&lt;strong&gt;Working&lt;/strong&gt;&lt;/u&gt;&lt;/h3&gt; &lt;ul&gt;&lt;li&gt;&lt;em&gt;named&lt;/em&gt; gets a request for domain resolution.&lt;/li&gt;&lt;li&gt;It checks whether the request can be satisfied from cache. If the answer is in cache and not stale, the request is satisfied from cache itself saving a lot of time :)&lt;/li&gt;&lt;li&gt;If request can't be satisfied from cache, named queries the first parent. If it replies with the answer, then named will cache the response and subsequent requests for the same domain name will be satisfied from the cache.&lt;/li&gt;&lt;li&gt;In case first parent fails to reply, named will query the second parent and so on.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;(&lt;em&gt;The working is my understanding of caching-nameserver using wireshark as traffic analysis tool and caching-nameserver may not behave exactly as explained above.&lt;/em&gt;)&lt;/p&gt; &lt;h3&gt;&lt;u&gt;&lt;strong&gt;How to install&lt;/strong&gt;&lt;/u&gt;&lt;/h3&gt; &lt;p&gt;&lt;em&gt;&lt;strong&gt;named&lt;/strong&gt;&lt;/em&gt; is by default on most of the systems by the package name '&lt;em&gt;&lt;strong&gt;caching-nameserver&lt;/strong&gt;&lt;/em&gt;'. If its not present on your system, install using&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="bash geshifilter-bash" style="font-family: monospace;"&gt;&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;[&lt;/span&gt;root&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;@&lt;/span&gt;localhost ~&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;]&lt;/span&gt;&lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;# yum install caching-nameserver [ENTER]&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;h3&gt;&lt;u&gt;&lt;strong&gt;How to configure&lt;/strong&gt;&lt;/u&gt;&lt;/h3&gt; &lt;p&gt;The main configuration file for named resides in &lt;em&gt;/var/named/chroot/etc/named.caching-nameserver.conf&lt;/em&gt; which is also soft linked from &lt;em&gt;/etc/named.caching-nameserver.conf&lt;/em&gt; . named configuration file supports C/C++ style comments.&lt;/p&gt; &lt;p&gt;For a caching nameserver which will cascade to another nameserver, there is nothing much to be configured. You need to configure "&lt;em&gt;&lt;strong&gt;options&lt;/strong&gt;&lt;/em&gt;" block. Below is a configuration file for a machine with IP address 172.17.8.64 cascading to two nameserver 192.168.36.204 and 192.168.36.210. The comments inline explain what each option does.&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="cpp geshifilter-cpp" style="font-family: monospace;"&gt;options &lt;span style="color: rgb(0, 128, 0);"&gt;{&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(102, 102, 102);"&gt;// Set the port to 53 which is standard port for DNS.&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(102, 102, 102);"&gt;// Add the IP address on which named will listen separated by semi-colons.&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(102, 102, 102);"&gt;// It'll be your own IP address.&lt;/span&gt;&lt;br /&gt; listen&lt;span style="color: rgb(0, 0, 64);"&gt;-&lt;/span&gt;on port &lt;span style="color: rgb(0, 0, 221);"&gt;53&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;{&lt;/span&gt;127.0.0.1; 172.17.8.64;&lt;span style="color: rgb(0, 128, 0);"&gt;}&lt;/span&gt;;&lt;br /&gt; &lt;span style="color: rgb(102, 102, 102);"&gt;// These are default. Leave them as it is.&lt;/span&gt;&lt;br /&gt; directory   &lt;span style="color: rgb(255, 0, 0);"&gt;"/var/named"&lt;/span&gt;;&lt;br /&gt; dump&lt;span style="color: rgb(0, 0, 64);"&gt;-&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;file&lt;/span&gt;   &lt;span style="color: rgb(255, 0, 0);"&gt;"/var/named/data/cache_dump.db"&lt;/span&gt;;&lt;br /&gt; statistics&lt;span style="color: rgb(0, 0, 64);"&gt;-&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;file&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;"/var/named/data/named_stats.txt"&lt;/span&gt;;&lt;br /&gt; memstatistics&lt;span style="color: rgb(0, 0, 64);"&gt;-&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;file&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;"/var/named/data/named_mem_stats.txt"&lt;/span&gt;;&lt;br /&gt; &lt;span style="color: rgb(102, 102, 102);"&gt;// The machines which are allowed to query this nameserver.&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(102, 102, 102);"&gt;// Normally you'll allow only your machine. But you can allow other machines also.&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(102, 102, 102);"&gt;// The address should be separated by semi-colons. To allow a network 172.16.31.0/24,&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(102, 102, 102);"&gt;// the line would be&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(102, 102, 102);"&gt;// allow-query {localhost; 172.16.31.0/24; };&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(102, 102, 102);"&gt;// Don't forget the semi-colons.&lt;/span&gt;&lt;br /&gt; allow&lt;span style="color: rgb(0, 0, 64);"&gt;-&lt;/span&gt;query     &lt;span style="color: rgb(0, 128, 0);"&gt;{&lt;/span&gt; localhost; 172.17.8.64; &lt;span style="color: rgb(0, 128, 0);"&gt;}&lt;/span&gt;;&lt;br /&gt; recursion yes;&lt;br /&gt; &lt;span style="color: rgb(102, 102, 102);"&gt;// The parent nameservers. List all the nameserver which you can query.&lt;/span&gt;&lt;br /&gt; forwarders &lt;span style="color: rgb(0, 128, 0);"&gt;{&lt;/span&gt; 192.168.36.204; 192.168.36.210; &lt;span style="color: rgb(0, 128, 0);"&gt;}&lt;/span&gt;;&lt;br /&gt; forward first;&lt;br /&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;}&lt;/span&gt;;&lt;br /&gt;logging &lt;span style="color: rgb(0, 128, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;       channel default_debug &lt;span style="color: rgb(0, 128, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;               &lt;span style="color: rgb(0, 0, 255);"&gt;file&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;"data/named.run"&lt;/span&gt;;&lt;br /&gt;               severity dynamic;&lt;br /&gt;       &lt;span style="color: rgb(0, 128, 0);"&gt;}&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;}&lt;/span&gt;;&lt;br /&gt;zone &lt;span style="color: rgb(255, 0, 0);"&gt;"."&lt;/span&gt; IN &lt;span style="color: rgb(0, 128, 0);"&gt;{&lt;/span&gt;&lt;br /&gt; type hint;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;file&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;"named.ca"&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;}&lt;/span&gt;;&lt;br /&gt;include &lt;span style="color: rgb(255, 0, 0);"&gt;"/etc/named.rfc1912.zones"&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;  &lt;h3&gt;&lt;u&gt;&lt;strong&gt;Start caching-nameserver&lt;/strong&gt;&lt;/u&gt;&lt;/h3&gt; &lt;p&gt;Now start the caching-nameserver using the following command&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="bash geshifilter-bash" style="font-family: monospace;"&gt;&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;[&lt;/span&gt;root&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;@&lt;/span&gt;localhost ~&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;]&lt;/span&gt;&lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;# server named start [ENTER]&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;p class="rtecenter"&gt;&lt;strong&gt;OR&lt;/strong&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="bash geshifilter-bash" style="font-family: monospace;"&gt;&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;[&lt;/span&gt;root&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;@&lt;/span&gt;localhost ~&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;]&lt;/span&gt;&lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;# /etc/init.d/named start [ENTER]&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;p&gt;To make named start every time your reboot your machine use following command&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="bash geshifilter-bash" style="font-family: monospace;"&gt;&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;[&lt;/span&gt;root&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;@&lt;/span&gt;localhost ~&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;]&lt;/span&gt;&lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;# chkconfig named on [ENTER]&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;h3&gt;&lt;u&gt;&lt;strong&gt;Using caching-nameserver&lt;/strong&gt;&lt;/u&gt;&lt;/h3&gt; &lt;p&gt;To use your caching-nameserver, open /etc/resolv.conf file and add the following line&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="bash geshifilter-bash" style="font-family: monospace;"&gt;nameserver 127.0.0.1&lt;/pre&gt;&lt;/div&gt;  &lt;p&gt;Comment all other lines in the file, so that finally the file looks like&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="bash geshifilter-bash" style="font-family: monospace;"&gt;; generated by &lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;/&lt;/span&gt;sbin&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;/&lt;/span&gt;dhclient-script&lt;br /&gt;&lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;#search wlan.iiit.ac.in&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;#nameserver 192.168.36.204&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;#nameserver 192.168.36.210&lt;/span&gt;&lt;br /&gt;nameserver 127.0.0.1&lt;/pre&gt;&lt;/div&gt;  &lt;p&gt;Now your system will use your own nameserver (in caching mode) for resolving all domain names. To test if your nameserver use the following command&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="bash geshifilter-bash" style="font-family: monospace;"&gt;&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;[&lt;/span&gt;root&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;@&lt;/span&gt;localhost ~&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;]&lt;/span&gt;&lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;# dig fedora.co.in [ENTER]&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;p&gt;Now if you use that command for the second time, the resolution time will be around 2-3 milli seconds while first time it would be around 400-700 milli seconds.&lt;/p&gt; &lt;p&gt;&lt;u&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt; &lt;p&gt;Below is two subsequent runs of dig for fedora.co.in . Notice the Query time.&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="bash geshifilter-bash" style="font-family: monospace;"&gt;&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;[&lt;/span&gt;root&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;@&lt;/span&gt;bordeaux SPECS&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;]&lt;/span&gt;&lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;# dig fedora.co.in&lt;/span&gt;&lt;br /&gt;; &lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;&lt;&lt;&gt;&gt;&lt;/span&gt; DiG 9.4.2rc1 &lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;&lt;&lt;&gt;&gt;&lt;/span&gt; fedora.co.in&lt;br /&gt;;; global options:  printcmd&lt;br /&gt;;; Got answer:&lt;br /&gt;;; -&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;&gt;&gt;&lt;/span&gt;HEADER&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;&lt;&lt;&lt;/span&gt;- opcode: QUERY, status: NOERROR, &lt;span style="color: rgb(194, 12, 185); font-weight: bold;"&gt;id&lt;/span&gt;: &lt;span style="color: rgb(0, 0, 0);"&gt;7839&lt;/span&gt;&lt;br /&gt;;; flags: qr rd ra; QUERY: &lt;span style="color: rgb(0, 0, 0);"&gt;1&lt;/span&gt;, ANSWER: &lt;span style="color: rgb(0, 0, 0);"&gt;1&lt;/span&gt;, AUTHORITY: &lt;span style="color: rgb(0, 0, 0);"&gt;1&lt;/span&gt;, ADDITIONAL: &lt;span style="color: rgb(0, 0, 0);"&gt;1&lt;/span&gt;&lt;br /&gt;;; QUESTION SECTION:&lt;br /&gt;;fedora.co.in.                  IN      A&lt;br /&gt;;; ANSWER SECTION:&lt;br /&gt;fedora.co.in.           &lt;span style="color: rgb(0, 0, 0);"&gt;83629&lt;/span&gt;   IN      A       72.249.126.241&lt;br /&gt;;; AUTHORITY SECTION:&lt;br /&gt;fedora.co.in.           &lt;span style="color: rgb(0, 0, 0);"&gt;79709&lt;/span&gt;   IN      NS      ns.fedora.co.in.&lt;br /&gt;;; ADDITIONAL SECTION:&lt;br /&gt;ns.fedora.co.in.        &lt;span style="color: rgb(0, 0, 0);"&gt;79709&lt;/span&gt;   IN      A       72.249.126.241&lt;br /&gt;;; Query &lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;time&lt;/span&gt;: &lt;span style="color: rgb(0, 0, 0);"&gt;531&lt;/span&gt; msec&lt;br /&gt;;; SERVER: 127.0.0.1&lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;#53(127.0.0.1)&lt;/span&gt;&lt;br /&gt;;; WHEN: Wed Nov &lt;span style="color: rgb(0, 0, 0);"&gt;19&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;18&lt;/span&gt;:04:&lt;span style="color: rgb(0, 0, 0);"&gt;47&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;2008&lt;/span&gt;&lt;br /&gt;;; MSG SIZE  rcvd: &lt;span style="color: rgb(0, 0, 0);"&gt;79&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;[&lt;/span&gt;root&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;@&lt;/span&gt;bordeaux SPECS&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;]&lt;/span&gt;&lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;# dig fedora.co.in&lt;/span&gt;&lt;br /&gt;; &lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;&lt;&lt;&gt;&gt;&lt;/span&gt; DiG 9.4.2rc1 &lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;&lt;&lt;&gt;&gt;&lt;/span&gt; fedora.co.in&lt;br /&gt;;; global options:  printcmd&lt;br /&gt;;; Got answer:&lt;br /&gt;;; -&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;&gt;&gt;&lt;/span&gt;HEADER&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;&lt;&lt;&lt;/span&gt;- opcode: QUERY, status: NOERROR, &lt;span style="color: rgb(194, 12, 185); font-weight: bold;"&gt;id&lt;/span&gt;: &lt;span style="color: rgb(0, 0, 0);"&gt;64233&lt;/span&gt;&lt;br /&gt;;; flags: qr rd ra; QUERY: &lt;span style="color: rgb(0, 0, 0);"&gt;1&lt;/span&gt;, ANSWER: &lt;span style="color: rgb(0, 0, 0);"&gt;1&lt;/span&gt;, AUTHORITY: &lt;span style="color: rgb(0, 0, 0);"&gt;1&lt;/span&gt;, ADDITIONAL: &lt;span style="color: rgb(0, 0, 0);"&gt;1&lt;/span&gt;&lt;br /&gt;;; QUESTION SECTION:&lt;br /&gt;;fedora.co.in.                  IN      A&lt;br /&gt;;; ANSWER SECTION:&lt;br /&gt;fedora.co.in.           &lt;span style="color: rgb(0, 0, 0);"&gt;83625&lt;/span&gt;   IN      A       72.249.126.241&lt;br /&gt;;; AUTHORITY SECTION:&lt;br /&gt;fedora.co.in.           &lt;span style="color: rgb(0, 0, 0);"&gt;79705&lt;/span&gt;   IN      NS      ns.fedora.co.in.&lt;br /&gt;;; ADDITIONAL SECTION:&lt;br /&gt;ns.fedora.co.in.        &lt;span style="color: rgb(0, 0, 0);"&gt;79705&lt;/span&gt;   IN      A       72.249.126.241&lt;br /&gt;;; Query &lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;time&lt;/span&gt;: &lt;span style="color: rgb(0, 0, 0);"&gt;1&lt;/span&gt; msec&lt;br /&gt;;; SERVER: 127.0.0.1&lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;#53(127.0.0.1)&lt;/span&gt;&lt;br /&gt;;; WHEN: Wed Nov &lt;span style="color: rgb(0, 0, 0);"&gt;19&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;18&lt;/span&gt;:04:&lt;span style="color: rgb(0, 0, 0);"&gt;51&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;2008&lt;/span&gt;&lt;br /&gt;;; MSG SIZE  rcvd: &lt;span style="color: rgb(0, 0, 0);"&gt;79&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;[&lt;/span&gt;root&lt;span style="color: rgb(0, 0, 0); font-weight: bold;"&gt;@&lt;/span&gt;bordeaux SPECS&lt;span style="color: rgb(122, 8, 116); font-weight: bold;"&gt;]&lt;/span&gt;&lt;span style="color: rgb(102, 102, 102); font-style: italic;"&gt;#&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4320291428541680545-2838397307002726799?l=zorovn78.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zorovn78.blogspot.com/feeds/2838397307002726799/comments/default' title='Đăng Nhận xét'/><link rel='replies' type='text/html' href='http://zorovn78.blogspot.com/2009/07/how-to-configure-caching-nameserver.html#comment-form' title='0 Nhận xét'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4320291428541680545/posts/default/2838397307002726799'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4320291428541680545/posts/default/2838397307002726799'/><link rel='alternate' type='text/html' href='http://zorovn78.blogspot.com/2009/07/how-to-configure-caching-nameserver.html' title='How to configure caching-nameserver (named) in cascading mode'/><author><name>Roronoa Zoro</name><uri>http://www.blogger.com/profile/00621746649739064085</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4320291428541680545.post-6985152094847783400</id><published>2009-06-30T21:13:00.000-07:00</published><updated>2009-06-30T21:28:12.860-07:00</updated><title type='text'>How to install and configure HAProxy as an HTTP load balancer</title><content type='html'>&lt;span class="TextMedium"&gt;HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for web sites crawling under very high loads while needing persistence or Layer7 processing. Supporting tens of thousands of connections is clearly realistic with todays hardware. Its mode of operation makes its integration into existing architectures very easy and riskless, while still offering the possibility not to expose fragile web servers to the Net.&lt;br /&gt;&lt;br /&gt;This post will explain how to install HAProxy on FreeBSD and how to configure it as a simple HTTP load balancer.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;1. Getting HAproxy&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The first step is to download HAProxy. You can find the latest version at this address:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://haproxy.1wt.eu/#down" target="_blank"&gt;http://haproxy.1wt.eu/#down&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;As of writing this post, the latest version is 1.3.16, which you can find here:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.16.tar.gz" target="_blank"&gt;http://haproxy.1wt.eu/download/1.3/s...-1.3.16.tar.gz&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;2. Prepare for installation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Log on your FreeBSD machine and change to the temporary directory of your choice. You can now issue the easy following commands:&lt;br /&gt;&lt;br /&gt;&lt;div style="border: 1px inset ; margin: 5px; padding: 4px; background-color: rgb(253, 248, 235);"&gt; &lt;span style="margin: 0px; padding: 4px; overflow: auto; width: 550px;"&gt;&lt;span style="font-family:courier new;"&gt;$ wget &lt;a href="http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.16.tar.gz" target="_blank"&gt;http://haproxy.1wt.eu/download/1.3/s...-1.3.16.tar.gz&lt;/a&gt;&lt;br /&gt;$ tar xvfz haproxy-1.3.16.tar.gz&lt;br /&gt;$ cd haproxy-1.3.16&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;HAProxy is now downloaded, unpacked and ready to be compiled.&lt;br /&gt;&lt;/span&gt;&lt;span class="TextMedium"&gt;&lt;span style="font-size:130%;"&gt;3. Compile HAProxy&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you are running FreeBSD, you can simply issue the following command:&lt;br /&gt;&lt;br /&gt;&lt;div style="border: 1px inset ; margin: 5px; padding: 4px; background-color: rgb(253, 248, 235);"&gt; &lt;span style="margin: 0px; padding: 4px; overflow: auto; width: 550px;"&gt;&lt;span style="font-family:courier new;"&gt;$ make -f Makefile.bsd REGEX=pcre DEBUG= COPTS.generic="-Os -fomit-frame-pointer"&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;If you are running another version of Linux, please refer to the README file (included with HAProxy) to find the good way to compile HAProxy on your system.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;4. Install HAProxy&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Once HAProxy is compiled, you will find a light-weight, standalone  "haproxy" executable.&lt;br /&gt;&lt;br /&gt;You can copy it where you want, it's your choice! Something like this can be a good choice:&lt;br /&gt;&lt;br /&gt;&lt;div style="border: 1px inset ; margin: 5px; padding: 4px; background-color: rgb(253, 248, 235);"&gt; &lt;span style="margin: 0px; padding: 4px; overflow: auto; width: 550px;"&gt;&lt;span style="font-family:courier new;"&gt;$ cp haproxy /usr/local/sbin&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;Why? Simply because /usr/local/sbin is usually in $PATH, so haproxy will then be easy to run simply by typing "haproxy".&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;5. Configuring HAProxy&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The configuration of HAProxy, like its installation, is really easy. In fact, it can be very easy, or very complex. HAProxy is VERY flexible and it has literally thousands of parameters you can tweak. You can find the whole documentation on the HAProxy official Web site there:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://haproxy.1wt.eu/#docs" target="_blank"&gt;http://haproxy.1wt.eu/#docs&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;As of writing this post, the latest official documentation is there:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://haproxy.1wt.eu/download/1.3/doc/configuration.txt" target="_blank"&gt;http://haproxy.1wt.eu/download/1.3/d...figuration.txt&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;For this post, we'll keep it simple and configure a simple load balancer.&lt;br /&gt;&lt;br /&gt;You can put the HAProxy configuration file where you wish, and name it as you wish! This post will be using this path/filename:&lt;br /&gt;&lt;br /&gt;&lt;div style="border: 1px inset ; margin: 5px; padding: 4px; background-color: rgb(253, 248, 235);"&gt; &lt;span style="margin: 0px; padding: 4px; overflow: auto; width: 550px;"&gt;&lt;span style="font-family:courier new;"&gt;/etc/haproxy.conf&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;And here's our simple configuration file:&lt;br /&gt;&lt;br /&gt;&lt;div style="border: 1px inset ; margin: 10px; padding: 4px; background-color: rgb(253, 248, 235);"&gt;   &lt;span style="margin: 0px; padding: 4px; overflow: auto; width: 550px;"&gt;&lt;span style="font-family:courier new;"&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;global&lt;br /&gt;     &lt;/span&gt;&lt;span style="color: rgb(0, 0, 204);"&gt;maxconn 4096&lt;br /&gt;     pidfile &lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;/var/&lt;/span&gt;&lt;span style="color: rgb(0, 0, 204);"&gt;run&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;/&lt;/span&gt;&lt;span style="color: rgb(0, 0, 204);"&gt;haproxy&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(0, 0, 204);"&gt;pid&lt;br /&gt;     daemon&lt;br /&gt;&lt;br /&gt;defaults&lt;br /&gt;     mode http&lt;br /&gt;     retries 3&lt;br /&gt;     option redispatch&lt;br /&gt;     maxconn 2000&lt;br /&gt;     contimeout 5000&lt;br /&gt;     clitimeout 50000&lt;br /&gt;     srvtimeout 50000&lt;br /&gt;&lt;br /&gt;listen GALAXY aaa&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(0, 0, 204);"&gt;bbb&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(0, 0, 204);"&gt;ccc&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(0, 0, 204);"&gt;ddd&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;:&lt;/span&gt;&lt;span style="color: rgb(0, 0, 204);"&gt;80&lt;br /&gt;     mode http&lt;br /&gt;     cookie GALAXY insert&lt;br /&gt;     balance roundrobin&lt;br /&gt;     option httpclose&lt;br /&gt;     option forwardfor&lt;br /&gt;     stats enable&lt;br /&gt;     stats auth myuser&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;:&lt;/span&gt;&lt;span style="color: rgb(0, 0, 204);"&gt;mypass&lt;br /&gt;     server EARTH 192.168.0.2&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;:&lt;/span&gt;&lt;span style="color: rgb(0, 0, 204);"&gt;8080 cookie GALAXY_SERVER_01 check&lt;br /&gt;     server MOON  192.168.0.3&lt;/span&gt;&lt;span style="color: rgb(0, 102, 0);"&gt;:&lt;/span&gt;&lt;span style="color: rgb(0, 0, 204);"&gt;8080 cookie GALAXY_SERVER_02 check&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&gt; aaa.bbb.ccc.ddd should be the public IP of your server.&lt;br /&gt;&gt; 192.168.0.2 should be the LAN IP to your server 1.&lt;br /&gt;&gt; 192.168.0.3 should be the LAN IP to your server 2.&lt;br /&gt;&lt;br /&gt;Everything that is in CAPS is customizable:&lt;br /&gt;&lt;br /&gt;&lt;div style="border: 1px inset ; margin: 5px; padding: 4px; background-color: rgb(253, 248, 235);"&gt; &lt;span style="margin: 0px; padding: 4px; overflow: auto; width: 550px;"&gt;&lt;span style="font-family:courier new;"&gt;* GALAXY&lt;br /&gt;* EARTH&lt;br /&gt;* MOON&lt;br /&gt;* GALAXY_SERVER_01&lt;br /&gt;* GALAXY_SERVER_02&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;Basically, this configuration file is defining a group ("listen" block) called GALAXY, which contains 2 servers: EARTH and MOON. The "roundrobin" balance option is telling to HAProxy to alternate between the 2 servers all the time. For the other options in the global, defaults and listen blocks, they're pretty standard. If you need to tweak those or to add options to suit your needs, I'm sure HAProxy can do it! Simply refer to the whole documentation.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Cookie&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;When the user will reach the GALAXY group (using &lt;a href="http://aaa.bbb.ccc.ddd%29/" target="_blank"&gt;http://aaa.bbb.ccc.ddd)&lt;/a&gt;, the cookie GALAXY will be created and the server ID specified for "cookie" in the servers definitions will be stored in it (GALAXY_SERVER_01 or GALAXY_SERVER_02).&lt;br /&gt;&lt;br /&gt;Then, for the whole session, HAProxy will read the cookie and force the use of the server stored in it.&lt;br /&gt;&lt;br /&gt;This behavior is controlled by the "cookie GALAXY insert" line and the "cookie GALAXY_SERVER_XX" parts in the GALAXY group block. If you don't want this feature, simply remove or comment (using a "#") these parts.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Stats&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;There's a pretty complete load balancer stats page built-in HAProxy. You can reach it there:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://aaa.bbb.ccc.ddd/haproxy?stats" target="_blank"&gt;http://aaa.bbb.ccc.ddd/haproxy?stats&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;With the configuration above, the username will be "myuser" and the password "mypass". If you don't want the stats to be enabled, you can simply remove or comment these lines:&lt;br /&gt;&lt;br /&gt;&lt;div style="border: 1px inset ; margin: 5px; padding: 4px; background-color: rgb(253, 248, 235);"&gt; &lt;span style="margin: 0px; padding: 4px; overflow: auto; width: 550px;"&gt;&lt;span style="font-family:courier new;"&gt;stats enable&lt;br /&gt;stats auth myuser:mypass&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Nginx&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;In the configuration above, we used the port 8080 for the local/private Web servers. If these Web servers are running Nginx, you will need to include the following configuration in your http, server or location block (nginx.conf):&lt;br /&gt;&lt;br /&gt;&lt;div style="border: 1px inset ; margin: 5px; padding: 4px; background-color: rgb(253, 248, 235);"&gt; &lt;span style="margin: 0px; padding: 4px; overflow: auto; width: 550px;"&gt;&lt;span style="font-family:courier new;"&gt;port_in_redirect off;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;This is needed because if you try to reach this:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://aaa.bbb.ccc.ddd/test" target="_blank"&gt;http://aaa.bbb.ccc.ddd/test&lt;/a&gt; (NO ending slash)&lt;br /&gt;&lt;br /&gt;Then Nginx will try to redirect you there:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://aaa.bbb.ccc.ddd:8080/test/" target="_blank"&gt;http://aaa.bbb.ccc.ddd:8080/test/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Which will obviously not work. So if you're running Nginx and that you decided to use a port different of 80, you will need this setting.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;6. Starting HAProxy&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To start HAProxy, simply issue the following command:&lt;br /&gt;&lt;br /&gt;&lt;div style="border: 1px inset ; margin: 5px; padding: 4px; background-color: rgb(253, 248, 235);"&gt; &lt;span style="margin: 0px; padding: 4px; overflow: auto; width: 550px;"&gt;&lt;span style="font-family:courier new;"&gt;haproxy -f /etc/haproxy.conf&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;For the initial testing, you might want to disable the cookie in the configuration file and test your Web page to actually see that you're switching from a server to another.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;That's it! You've got a high-performance, high-scalability and highly-tweakable load balancer configured in a couple of minutes!&lt;br /&gt;&lt;br /&gt;Publibed by &lt;/span&gt;&lt;span&gt;Michel Nadeau, 03-26-2009 &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4320291428541680545-6985152094847783400?l=zorovn78.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zorovn78.blogspot.com/feeds/6985152094847783400/comments/default' title='Đăng Nhận xét'/><link rel='replies' type='text/html' href='http://zorovn78.blogspot.com/2009/06/how-to-install-and-configure-haproxy-as.html#comment-form' title='0 Nhận xét'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4320291428541680545/posts/default/6985152094847783400'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4320291428541680545/posts/default/6985152094847783400'/><link rel='alternate' type='text/html' href='http://zorovn78.blogspot.com/2009/06/how-to-install-and-configure-haproxy-as.html' title='How to install and configure HAProxy as an HTTP load balancer'/><author><name>Roronoa Zoro</name><uri>http://www.blogger.com/profile/00621746649739064085</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
