Linux platform Deployment varnish high Performance cache server (1)

Source: Internet
Author: User


"The content described in this document is intended for company testing/production of common varnish environment deployments"

One: Varnish ready before deployment:

1.1 Related software and systems, Web services

System Requirements: Centos 6 (above) (64-bit)

Related middleware: varnish-4.0.2

1.2 Related system dependent package installation Check preparation

1.2.1 Check if the system comes with Nginx installed

Rpm-qa | grep varnish

If you have an installation, use the following command to uninstall the program

Yum Remove varnish-y

1.2.2 Installing the dependencies required by the Nginx compiler

Yum install Libtool ncurses-devel pcre-devel ibedit-devel pkgconfig python-docutils python-sphinx automake autoconf-y

1.2.3 Installing related Web Services

Install Apache,nginx,tomcat and so on, the web of this document is installed locally, using the Nginx Web port is: 8080

II: Varnish deployment installation

2.1 Download Varnish installation package

As shown in Varnish's official website: https://www.varnish-cache.org/releases, select the corresponding varnish version, the version of this document is varnish4.0.2

Cd/usr/local/srcwget https://repo.varnish-cache.org/source/varnish-4.0.2.tar.gz

2.2 Compiling and installing varnish

Cd/usr/local/srctar zxvf varnish-4.0.2.tar.gz./configure cppflags= "-i$path_to_libedit/include" LDFLAGS= "-L$PATH_TO _libedit/lib "--prefix=/usr/local/varnish4.0.2 make && make install

2.3 Configuring the Varnish startup script

echo "/usr/local/varnish4.0.2/sbin/varnishd-p/var/run/varnish.pid-f/usr/local/varnish4.0.2/etc/default.vcl-s Malloc,1g-t 127.0.0.1:2000-a 0.0.0.0:80 ">/usr/local/varnish4.0.2/sbin/varnishd.sh

2.4 Start the varnish as a boot service and join the system service

2.4.1 Edit/etc/init.d/varnishd

Vim/etc/init.d/varnishd

2.4.2 Add the following in/etc/init.d/varnishd

#!/bin/sh#chkconfig:345 85 15  #description:  varnish cache server# varnish#  Copyright  (C)  2001-2014 varnish cache#service= "Varnish server" daemon=/usr/local /varnish4.0.2/sbin/varnishd.shpidfile=/var/run/varnish.pidcase $1 in   ' start ')      if [ -x ${DAEMON} ]    then        $DAEMON       # Error checking here would be  good...      echo  "${service} started success ! "      else      echo  "Can ' T find file ${daemon}."       echo  "${service} not started."     fi  ;;    ' Stop ')     if [ -s ${pidfile} ]    then      if kill  ' Cat ${pidfile} '  >/dev/null 2> &1      then        echo  "${ service} shutdown success ! "         rm -f ${PIDFILE}       fi    fi  ;;    ' restart ')     $0 stop    sleep 10     $0 start  ;;   *)     echo  "Usage: $0 start|stop|restart"      ;; Esac

2.4.3 Edit/USR/LOCAL/VARNISH4.0.2/ETC/DEFAULT.VCL Add the following content

VCL 4.0;backend webserver {. host = "127.0.0.1";         . Port = "8080";      Equivalent to back-end Web server. connect_timeout = 4s;      . first_byte_timeout = 5s;  . between_bytes_timeout = 20s; }

2.4.4 Start varnishd Service

Service Varnishd Start

Three: Varnish verification test

Start the Web service

Service Nginx Start

Use the system's own command curl-i localhost as shown below:

http/1.1 200 okserver: nginx/1.8.0date: mon, 04 jan 2016 07:50:09  GMTContent-Type: text/htmlLast-Modified: Mon, 31 Aug 2015 03:55:55  gmtetag:  "55e3d04b-264" x-varnish: 112 131182age: 80via: 1.1  Varnish-v4content-length: 612connection: keep-alive 

In the red section of this article, when two sets of data appear behind x-varnish , the cache is successful, when we turn off the Web service, the data will be read from the varnish cache, as follows

Close Web Service

Service Nginx Stop

Re-curl-i localhost if the cache is hit, as follows:

http/1.1 200 okserver: nginx/1.8.0date: mon, 04 jan 2016 07:53:47  GMTContent-Type: text/htmlLast-Modified: Mon, 31 Aug 2015 03:55:55  gmtetag:  "55e3d04b-264" x-varnish: 110 131182age: 8via: 1.1  Varnish-v4content-length: 612connection: keep-alive 

When there is no hit from the cache, the following prompt appears ( no hit cache, then X-varnish followed by a single set of numbers ):

http/1.1 503 backend Fetch Faileddate:mon, Jan 07:55:59 gmtserver:varnishcontent-type:text/html; charset=utf-8retry-after:5x-varnish:98457age:0via:1.1 varnish-v4content-length:282connection:keep-alive

At this point the entire varnish deployment installation is basically OK

This article is from the "Rookie Growth" blog, please be sure to keep this source http://blief.blog.51cto.com/6170059/1731390

Linux platform Deployment varnish high Performance cache server (1)

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.