|
||||||||
|
||||||||
|
|
Công Cụ | Xếp Bài |
17-06-2014, 04:41 PM | #1 |
Guest
Trả Lời: n/a
|
Tự xây dựng hệ thống CDN với Bind, GeoIP,Nginx, Varnish (How to build your own CDN
Tự xây dựng hệ thống CDN với Bind, GeoIP,Nginx, Varnish (How to build your own CDN using BIND, GeoIP, Nginx, and Varnish) GIT – In this article, we shall outline the steps required to build a private Content Delivery or Distribution Network (CDN) using a VPS with Varnish Cache and Nginx. The goal is to build a CDN using free, readily available software but most importantly spend the least amount of funds possible. To this end, all nodes participating in this network are going to be virtual machines (Xen, Virtuozzo, OpenVZ, etc). Should you have any questions or comments on the configuration of this CDN, please post them in this forum: http://www.varnish-cache.info/ Our global CDN can not only keep the latest copy of static files closer to our global visitors but can also cache the most used pages (dynamic or not) in memory on the edge nodes! This means less trips to the geographically distant and slower Dynamic Node (see below). This is similar to what Akamai and other well known firms do, only at a fraction of the cost. However, in this article, and to keep things simple, we will only be caching static files.
Global CDN
As its name implies, Varnish Cache is a high-performance caching engine used to keep recently accessed content in memory for fastest access. Varnish is not a Web server. Hence our need to bundle it with Nginx, which is acting as a Web server at the edge nodes. We will cover Varnish in detail in our next installment. And finally the glue that holds all of these components together: BIND. BIND is the DNS software used to map Internet host names to IP addresses. We shall patch Bind to add geographical filters support. In other words, BIND will serve each client the IP of closest edge node in the CDN. For example, an vistor from Africa will receive the edge node IP of South Africa or Morocco depending on the filters. We will touch on this later.
Download BIND from ISC: http://www.bind9.net/download Download MaxMind’s C API: http://geolite.maxmind.com/download/geoip/api/c/ [root@dynamic_node /]# cd /usr/src/ [root@dynamic_node src]# wgetBind-GeoIP comes with a named.conf file with examples on how to use filtering. Setup your zone files and test them accordingly. The GeoIP patch official page has instructions and examples. Be sure to read over it should you need help: http://www.caraytech.com/geodns/. If you do not have access to nodes in the different geo locations around the world to test your BIND configuration, http://traceroute.org is a good resource to leverage. It allows one to test DNS resolution using a looking glass (ping). Here is how the filters should look inside named.conf: view “us” {Let us move on now and install Nginx and Varnish. [root@edge_node src]# wget http://nginx.org/download/nginx-0.8.45.tar.gzHere is our nginx.conf file with relevant lines only. All other configuration options are stock Nginx: http {In bold above are configuration lines that are key and define our private CDN. The upstream is essentially going to be our Dynamic Node to which we pass requests that cannot be served from cache. Also, Nginx will only be caching static files like GIF, PNG, and JS. Varnish on the other hand will be caching dynamic pages. Notice how Nginx listens on port 81. This is because Varnish will listen on port 80 and will forward requests to Nginx on port 80. More on Varnish later. Notice how we are using cdn.unixy.net as the handle for our virtual host name. It can be just about anything depending on your configuration. Once the cache builds up, you should start seeing files and directories being populated under /var/www/ as instructed above. A few seconds of browsing and the disk cache is already populating: [root@edge_node /]# ls -al /var/www/cacheNext we will proceed with installing Varnish. Varnish will act an in-memory cache. While it is not necessary, it can improve response time greatly. Nonetheless, installing Varnish does add a level of complexity to our configuration. [root@edge_node src]# wget http://downloads.sourceforge.net/pro...&ts=1279434397Be sure to follow guides online on the initial setup of Varnish. This article only covers the configuration of the CDN. There are certainly additional Varnish options that need tuning but those are most likely peculiar to your application. backend default { sub vcl_recv { sub vcl_fetch {Go ahead and startup Varnish and browse around you portal a bit to build the cache. Monitor the command varnishstat on the edge node and you will be able to see the cache hits and misses. There should be more hits as the cache builds up over time and more objects are accessed.
http://blog.unixy.net/2010/07/how-to-build-your-own-cdn-using-bind-geoip-nginx-and-varnish/ |
|
|