Compile and install Varnish3.03 and configure Varnish3.03 in linux

Source: Internet
Author: User

Next let's take a look at how to compile and install Varnish3.03 and configure Varnish3.03 in linux. I hope this article will help you.


This is a note on Varnish3.03 compilation and installation configuration.

Install

The Code is as follows: Copy code

Yum-y install gcc-c ++ file bison patch unzip mlocate flex wget diffutils automake autoconf kernel-devel gd cpp readline-devel openssl-devel vim-minimal nano libjpeg-devel libpng kernel-devel freetype-devel libxml2 libxml2-devel zlib-devel glibc-devel glib2 glib2-devel kernel bzip2-devel ncurses-devel curl-devel kernel e2fsprogs-devel libidn kernel-devel openldap-devel openldap-clients openldap-servers extends gettext-devel expat-devel libcap-devel libtool-ltdl-devel pam-devel pcre-devel ncurses-devel subversion bind-utils rsync libxslt groff pkgconfig

# Compile Varnish-Cache
Cd/usr/local/src
Http://repo.varnish-cache.org/source/varnish-3.0.3.tar.gz wget-c
Tar-zxf varnish-3.0.3.tar.gz
Cd varnish *
./Autogen. sh
./Configure -- prefix =/usr/local/varnish
Make
Make install

/Usr/sbin/groupadd-g 1000-o-r varnish
/Usr/sbin/useradd-M-g varnish-o-r-d/dev/zero-s/bin/false-c "Varnish-Cache Server"-u 1000 varnish
Mkdir-p {/etc/varnish,/var/log/varnish,/var/lib/varnish}
/Usr/bin/uuidgen>/etc/varnish/secret & chmod 0600/etc/varnish/secret
/Usr/bin/install-m 755./redhat/varnish. initrc/etc/rc. d/init. d/varnish
/Usr/bin/install-m 755./redhat/varnishncsa. initrc/etc/rc. d/init. d/varnishncsa
/Usr/bin/install-m 644./redhat/varnish. sysconfig/etc/sysconfig/varnish
/Usr/bin/install-m 755./redhat/varnish_reload_vcl/usr/local/varnish/bin/

Ln-s/usr/local/varnish/bin/varnish_reload_vcl/usr/bin/
Ln-s/usr/local/varnish/bin/varnishncsa/usr/bin/
Ln-s/usr/local/varnish/sbin/varnishd/usr/sbin/
Ln-s/usr/local/varnish/bin/varnishadm/usr/bin/
Ln-s/usr/local/varnish/bin/varnishstat/usr/bin/
Ln-s/usr/local/varnish/bin/varnishhist/usr/bin/
Ln-s/usr/local/varnish/bin/varnishlog/usr/bin/
Ln-s/usr/local/varnish/bin/varnishtop/usr/bin/

Chkconfig -- add varnish
Chkconfig varnish on
Chkconfig -- add varnishncsa
Chkconfig varnishncsa on

Configuration

Use the following code to replace the content in/etc/sysconfig/varnish. Replace 121.199.13.169 in the following code with the public ip address of your vps.

The Code is as follows: Copy code

 

# Configuration file for varnish
#
#/Etc/init. d/varnish expects the variable $ DAEMON_OPTS to be set from this
# Shell script fragment.
# Maximum number of open files (for ulimit-n)
NFILES = 131072 # Locked shared memory (for ulimit-l)
# Default log size is 82 MB + header
MEMLOCK = 82000 # Maximum number of threads (for ulimit-u)
NPROCS = "unlimited"

# Maximum size of corefile (for ulimit-c). Default in Fedora is 0
# DAEMON_COREFILE_LIMIT = "unlimited"

# Set this to 1 to make init script reload try to switch vcl without restart.
# To make this work, you need to set the following variables
# Explicit: VARNISH_VCL_CONF, VARNISH_ADMIN_LISTEN_ADDRESS,
# VARNISH_ADMIN_LISTEN_PORT, VARNISH_SECRET_FILE, or in short,
# Use Alternative 3, Advanced configuration, below
RELOAD_VCL = 1

# This file contains 4 alternatives, please use only one.

# Alternative 1, Minimal configuration, no VCL
#
# Listen on port 6081, administration on localhost: 6082, and forward
# Content server on localhost: 8080. Use a fixed-size cache file.
#
# DAEMON_OPTS = "-a: 6081
#-T localhost: 6082
#-B localhost: 8080
#-U varnish-g varnish
#-S file,/var/lib/varnish/varnish_storage.bin, 1G"

# Alternative 2, Configuration with VCL
#
# Listen on port 6081, administration on localhost: 6082, and forward
# One content server selected by the vcl file, based on the request. Use
# Fixed-size cache file.
#
# DAEMON_OPTS = "-a: 6081
#-T localhost: 6082
#-F/etc/varnish/default. vcl
#-U varnish-g varnish
#-S/etc/varnish/secret
#-S file,/var/lib/varnish/varnish_storage.bin, 1G"

# Alternative 3, Advanced configuration
#
# See varnishd (1) for more information.
#
# Main configuration file. You probably want to change it :)
VARNISH_VCL_CONF =/etc/varnish/default. vcl
#
# Default address and port to bind
# Blank address means all IPv4 and IPv6 interfaces, otherwise specify
# A host name, an IPv4 dotted quad, or an IPv6 address in brackets.
VARNISH_LISTEN_ADDRESS = 121.199.13.169
VARNISH_LISTEN_PORT = 80
#
# Telnet admin interface listen address and port
VARNISH_ADMIN_LISTEN_ADDRESS = 127.0.0.1
VARNISH_ADMIN_LISTEN_PORT = 6082
#
# Shared secret file for admin interface
VARNISH_SECRET_FILE =/etc/varnish/secret
#
# The minimum number of worker threads to start
VARNISH_MIN_THREADS = 50
#
# The Maximum number of worker threads to start
VARNISH_MAX_THREADS = 1000
#
# Idle timeout for worker threads
VARNISH_THREAD_TIMEOUT = 120
#
# Cache file location
# VARNISH_STORAGE_FILE =/var/lib/varnish/varnish_storage.bin
VARNISH_STORAGE_FILE =/dev/shm/varnish_storage.bin
#
# Cache file size: in bytes, optionally using k/M/G/T suffix,
# Or in percentage of available disk space using the % suffix.
VARNISH_STORAGE_SIZE = 1G
#
# Backend storage specification
VARNISH_STORAGE = "file, $ {VARNISH_STORAGE_FILE}, $ {VARNISH_STORAGE_SIZE }"
#
# Default TTL used when the backend does not specify one
VARNISH_TTL = 120
#
# DAEMON_OPTS is used by the init script. If you add or remove options, make
# Sure you update this section, too.
DAEMON_OPTS = "-a $ {VARNISH_LISTEN_ADDRESS }:: {VARNISH_LISTEN_PORT}
-F $ {VARNISH_VCL_CONF}
-T $ {VARNISH_ADMIN_LISTEN_ADDRESS }:$ {VARNISH_ADMIN_LISTEN_PORT}
-T $ {VARNISH_TTL}
-W $ {VARNISH_MIN_THREADS}, $ {VARNISH_MAX_THREADS}, $ {VARNISH_THREAD_TIMEOUT}
-U varnish-g varnish
-S $ {VARNISH_SECRET_FILE}
-S $ {VARNISH_STORAGE }"
#

# Alternative 4, Do It Yourself. See varnishd (1) for more information.
#
# DAEMON_OPTS = ""


Use the following code to replace the content in/etc/varnish/default. vcl. If the/etc/varnish/default. vcl file does not exist, create it.

The Code is as follows: Copy code

 

# This is a basic VCL configuration file for varnish. See the vcl (7)
# Man page for details on VCL syntax and semantics.
#
# Default backend definition. Set this to point to your content
# Server.
#
Backend default {
. Host = "127.0.0.1 ";
. Port = "80 ";
} Sub vcl_recv {
Remove req. http. X-real-ip;
Set req. http. X-real-ip = client. ip;
Set req. http. X-Forwarded-For = client. ip;

If (req. http. Authorization ){
Return (pass );
}

If (req. url ~ ". (Php) $ "){
Return (pass );
}

If (req. request! = "GET "&&
Req. request! = "HEAD "&&
Req. request! = "PUT "&&
Req. request! = "POST "&&
Req. request! = "TRACE "&&
Req. request! = "OPTIONS "&&
Req. request! = "DELETE ")
{Return (pipe );}

If (req. request! = "GET" & req. request! = "HEAD "){
Return (pass );
}

If (req. request = "GET" & req. url ~ "(? I). (js | css | jpg | jpeg | png | gif | ico | rar | gz | bz2 | mp3 | swf | flv) $ "){
Unset req. http. cookie;
Return (lookup );
}
}

Sub vcl_fetch {
If (req. request = "GET" & req. url ~ "(? I). (js | css | jpg | jpeg | png | gif | ico | rar | gz | bz2 | mp3 | swf | flv) $ "){
Set beresp. ttl = 7d;
# Unset beresp. http. set-cookie;
}
Return (deliver );
}

Sub vcl_deliver {
# Set resp. http. x-hits = obj. hits;
Remove resp. http. X-Varnish;
Remove resp. http.;
Remove resp. http. Age;
Remove resp. http. X-Pingback;
Set resp. http. Server = "ZhengJie Web Server ";
Set resp. http. X-Via = "Varnish Cache Server V3.03 ";
# If (obj. hits> 0 ){
# Set resp. http. X-Cache = "Hit From CDN. IYISM. COM ";}
# Else {
# Set resp. http. X-Cache = "Miss From CDN. IYISM. COM ";}
# Set resp. http. Server = "IYISM ";
Return (deliver );
}

Finally, change all listen 80 in the nginx configuration file to listen 127.0.0.1: 80. Restart nginx after the change, and then run the following command ~

The Code is as follows: Copy code
Service varnish restart

Note: Varnish compilation and installation method is similar to icodex.org. For the configuration file, see

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.