Build varnish servers with much higher performance than squid

Source: Internet
Author: User
Set up varnish servers with much higher performance than squid-Linux Enterprise applications-Linux server applications. For more information, see the following. [Author: jackbillow reprint please note the Source: http://www.discuz.net]

Arnish is a high-performance open source HTTP accelerator, and Verdens Gang, Norway's largest online newspaper, replaced the original 12 SQUIDS with three Varnish,

The performance is better 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

Type: 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 hard disk also has its own cache device, so squid

The architecture of the cache's self-processing of object replacement cannot be optimized by knowing these situations, but the operating system can be informed of these situations. Therefore, this part of work should be handled by the operating system,

This is the design architecture of Varnish cache.


1. Download the source code package for compilation and installation:

Cd/usr/local/src & wget http://nchc.dl.sourceforge.net/s... 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 specifies 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. :)

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.