Build varnish servers with much higher performance than squid
Source: Internet
Author: User
The varnish server, which has a much higher performance than squid, is a high-performance open-source HTTP accelerator. verdens gang, Norway's largest online newspaper (
Http://www.vg.no3 varnish replace the original 12 squids for better performance than before.
Varnish's author, Poul-Henning Kamp, is one of FreeBSD's kernel developers. He believes that today's computers are much more complicated than in 1975. In 1975, there were only two storage media types: memory and hard disk. However, in addition to primary memory, the memory of the computer system also includes L1, L2 in the CPU, and even L3 cache.
The Squid cache has its own caching device on the hard disk, so it is impossible for the architecture of Squid cache to handle the replacement of objects on its own to know these conditions, but the operating system can know these situations, therefore, this part of work should be handed over to the operating system, which is the varnish cache design architecture.
1. Download the source code package for compilation and installation: CD/usr/local/src & wget
Http://nchc.dl.sourceforge.net... Arnish-1.1.1.tar.gz
Tar zxvf/usr/local/src/varnish-1.1.1.tar.gz
CD/usr/local/src/Varnish-1.1.1
./Autogen. Sh
./Configure -- enable-debugging-symbols -- enable-developer-warnings -- enable-dependency-tracking
NOTE: If your GCC version is 4.2.0 or later, you can add the -- enable-extra-warnings compilation parameter to get an additional warning when an error occurs.
I am using the source code package. If you are using RedHat or centos, you can use the RPM package for installation (RPM download location: http: // sourceforge.net/project/showfiles.php?
Group_id = 155816 & package_id = 173643 & release_id = 533569 ).
2. Create a cache directory: Mkdir-P/Cache/Varnish/V & chown-r nobody: Nobody/Cache
3. Compile the Startup file: CD/usr/local/Varnish/sbin
VI start. Sh
The content is as follows:
#! /Bin/sh
# File: Go. Sh
Date-u
/Usr/local/Varnish/sbin/varnishd/
-A 10.0.0.129: 80/
-S file,/Cache/Varnish/V, 1024 M/
-F/usr/local/Varnish/sbin/VG. VCL. Default/
-P thread_pool_max = 1500/
-P thread_pools = 5/
-P listen_depth = 512/
-P client_http11 = on/
Note :-A is the IP address or hostname of the backend server, just like the originserver of squid when performing revese proxy.
But this can also be written in VCL.
-F indicates the VCL file used.
-S specifies the storage type, file location, and size of the cache directory.
-P is some startup parameters for varnish startup. You can optimize varnish performance based on your machine configuration.
You can use varnishd -- help to view the specific meanings of other parameters.
4. Compile VCL: My VCL is as follows:
Backend default {
Set backend. Host = "127.0.0.1 ";
Set backend. Port = "HTTP ";
}
# I use a machine for testing and the backend is 127.0.0.1: 80. If the varnish machine is separated from the background machine.
Write the IP address or hostname of the corresponding machine.
Sub vcl_recv {
If (req. Request! = "Get" & Req. Request! = "Head "){
Pipe;
}
If (req. http. Exact CT ){
Pipe;
}
If (req. http. Authenticate | Req. http. Cookie ){
Pass;
}
If (req. Request = "get" & Req. url ~ "/. (GIF | JPG | SWF | CSS | JS) $ "){
Lookup;
}
Lookup;
}
Sub vcl_pipe {
Pipe;
}
Sub vcl_pass {
Pass;
}
Sub vcl_hash {
Hash;
}
Sub vcl_hit {
If (! OBJ. cacheable ){
Pass;
}
Deliver;
}
Sub vcl_timeout {
Discard;
}
Sub vcl_discard {
Discard;
}
If multiple sites are on different originserver, you can use the following Configuration: Backend WWW {
Set backend. Host ="
Www.jackbillow.com";
Set backend. Port = "80 ";
}
Backend images {
Set backend. Host = "images.jackbillow.com ";
Set backend. Port = "80 ";
}
Sub vcl_recv {
If (req. http. Host ~ "^ (
Www .)? Jackbillow.com $"){
Set Req. http. Host ="
Www.jackbillow.com";
Set Req. backend = WWW;
} Elsif (req. http. Host ~ "^ Images.jackbillow.com $ "){
Set Req. backend = images;
} Else {
Error 404 "Unknown Virtual Host ";
}
5. Start varnish: /Usr/local/Varnish/sbin/start. Sh
Mon Sep 3 03:13:19 UTC 2007
File/Cache/Varnish/V/varnish. tekxxx (unlinked) size 1073741824 bytes (262144 FS-blocks, 262144 pages)
Using old shmfile
PS waux | grep varnish
Root 16254 0.0 0.0 11200 708? SS/usr/local/Varnish/sbin/varnishd-A 10.0.0.129: 80-S/Varnish/V, 1024 m
-F/usr/local/Varnish/sbin/VG. VCL. Default-P thread_pool_max 1500-P thread_pools 5-P listen_depth 512-P client_http11 on
Nobody 16255 0.0 0.1 1152552? SL/usr/local/Varnish/sbin/varnishd-A 10.0.0.129: 80-S
File,/Cache/Varnish/V, 1024 M-F/usr/local/Varnish/sbin/VG. VCL. Default-P thread_pool_max 1500-P thread_pools 5-P
Listen_depth 512-P client_http11 on
The above information indicates that varnish is started correctly. Congratulations, you have configured it successfully.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service