Linux compiler installation Varnish3.03 and configuration

Source: Internet
Author: User
Tags bind bz2 curl gettext openssl rar openldap varnish


This is a note about Varnish3.03 compiling the installation configuration

Installation

The code is as follows Copy Code

Yum-y Install gcc gcc-c++ file Bison patch Unzip Mlocate flex wget diffutils automake autoconf GD cpp Rea Dline-devel OpenSSL openssl-devel vim-minimal nano libjpeg libjpeg      -devel libpng Libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2 -devel ncurses Ncurses-devel Curl curl-devel        e2fsprogs Libidn libidn-devel openldap openldap-devel openldap-clients openldap-servers nss_ldap gettext gettext-devel Expat-devel libcap libcap-devel libtool libtool-     ltdl-devel pam-devel pcre-devel ncurses-devel Subversion bind-utils rsync libxslt Groff pkgconfig

    # Compile Varnish-cache
    cd/usr/local/src
    wget-c http://repo.varnish-cache.org/source/varnish-3.0.3.tar.gz
    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

Replace the contents of the/etc/sysconfig/varnish with the following code, and be careful to replace the 121.199.13.169 in the following code with the public IP of your VPS

The code is as follows Copy Code

# Configuration file for varnish
#
#/etc/init.d/varnish expects the variable $DAEMON _opts to is 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 82MB + header
memlock=82000# Maximum Number of threads (for ulimit-u)
nprocs= "Unlimited"

# Maximum size of Corefile (for ulimit-c). Default in Fedora 0
# daemon_corefile_limit= "Unlimited"

# Set this to ' make init script reload try to switch VCL without restart.
# to make this work, your 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.

# # alternative 1, minimal configuration, no VCL
#
# Listen on Port 6081, administration in localhost:6082, and forward to
# 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 in localhost:6082, and forward to
# One content server selected by the VCL file and based on the request. Use a
# 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
#
# varnishd (1) for the more information.
#
# Main configuration file. Probably want to change it:)
Varnish_vcl_conf=/etc/varnish/default.vcl
#
# # Default address and port to bind to
# Blank address means all IPv4 and IPV6 interfaces, otherwise specify
# A host name, an IPV4 dotted quad, or of 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 spaces 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 is not specify one
varnish_ttl=120
#
# # daemon_opts is used by the Init script. If you add or remove the options, make
# # Sure 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. VARNISHD (1) for the more information.
#
# daemon_opts= ""


Use the following code to replace the contents of the/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 the file for varnish. The VCL (7)
# Mans 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.Via;
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 the Listen 80 in the Nginx configuration file into listen 127.0.0.1:80, restart Nginx after the change, and then execute the following command on the OK ~

The code is as follows Copy Code
Service Varnish Restart

Description: Varnish compiler installation Method imitation self-treacherous (icodex.org), configuration file Reference

Related Article

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.