Varnish is mainly used for caching servers, and some other software can also implement caching functions, such as memcached but it mainly caches the value data, suitable for caching MySQL data, and Nginx also has the cache function, also can provide cache for back-end host at the time of the reverse generation. But Nginx is often used for anti-generation server, and does not recommend a host to carry out multi-tasking work, which will reduce the performance of the agent, and varnish is often used as the HTTP protocol anti-generation work.
Modern Internet services, in order to provide users with a good experience, access to the Web site to open the speed of the page is very fast, so each site basically put resources as far as possible on the client's closest access node, that is often said to push resources to the user's doorstep. Implementations are commonly used in two ways: one is to use a CDN, the other is to point the user requests to a portal, at the entrance of the customer request to deploy the cache server, the hotspot resources are placed on the user's nearest cache server. Varnish work in the second way, as a cache server to provide users with a good experience of access.
The same function also has a software squid, and varnish relationship, equivalent to the relationship between httpd and Nginx, Squid appeared earlier, but faced with a large load of work is very stable, and rich in functionality, while supporting the forward, reverse proxy; varnish is relatively light weight, Mainly used for the realization of the reverse generation, but more than the load can be very unstable;
Install varnish:
]# Yum Install varnish
Installing the varnish Documentation package
]# yum-y Install Varnish-docs
Varnish Host: 172.18.11.111
Back-end Web host:
rs1:172.18.11.11
rs2:172.18.11.12
Varnish Host:
]# VIM/ETC/VARNISH/DEFAULT.VCL
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/82/11/wKiom1dJt9ah8ONbAAB6u8Tq3vI776.png "title=" 1.png " alt= "Wkiom1djt9ah8onbaab6u8tq3vi776.png"/>
]# Vim/etc/varnish/varnish.params
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/82/0F/wKioL1dJuUTQQ6hHAACgRIlcJjI092.png "title=" 2.png " Width= "height=" border= "0" hspace= "0" vspace= "0" style= "width:700px;height:500px;" alt= " Wkiol1djuutqq6hhaacgrilcjji092.png "/>
To start the varnish dedicated command line:
]# varnishadm-s/etc/varnish/secret-t 127.0.0.1:6082
Vcl.load test1 DEFAULT.VCL
Show:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/82/0F/wKioL1dJulHCIk9nAAAIpP5CDsU360.png "title=" 3.png " alt= "Wkiol1djulhcik9naaaipp5cdsu360.png"/>
No problem, then enter:
Vcl.use test1
Show:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/82/10/wKioL1dJuoSC2c8wAAAIbLV0KKQ594.png "title=" 4.png " alt= "Wkiol1djuosc2c8waaaiblv0kkq594.png"/>
No problem after the browser can test.
Provide test pages on the backend two Web servers, respectively:
]# vim/var/www/html/index.html
]# vim/var/www/html/index.html
Browser input: http://172.18.11.111/
Alternate display after refresh:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/82/10/wKioL1dJu27QEblmAAA3b3YgxvY744.png "style=" float: none; "title=" 5.png "alt=" Wkiol1dju27qeblmaaa3b3ygxvy744.png "/>
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/82/11/wKiom1dJunXyj9GyAAA0K-Vkyjs668.png "style=" float: none; "title=" 6.png "alt=" Wkiom1djunxyj9gyaaa0k-vkyjs668.png "/>
Stop a back-end Web server and continue to access the Web services that are still available.
Varnish basic applications