O & M-varnish of server Cache

Source: Internet
Author: User
Tags drupal varnish
Varnish I. Introduction:

First, I want to understand several concepts,

1. varnish does not Cache HTTP output with the set-Cookie header. 2. varnish complies with the HTTP part for the cache part in the HTTP protocol. For example, control-Cache: No-store, no-cache, must-revalidate, post-check = 0, pre-check = 0. By default, varnish does not cache data. 3. In the cache section of the HTTP protocol, control-Cache takes precedence over expires. Pragma: No-cache is the product of http1.0 and can be ignored.

Varnish is a high-performance, open-source reverse proxy server and cache server. Its developer poul-Henning Kamp is one of the core developers of FreeBSD. Varnish adopts a new software architecture, which works closely with the current hardware system. Currently, varnish can run on freebsd6.0/7.0, Solaris, and Linux 2.6 kernels.

Comparison between varnish and squid
  • Varnish and squid are more likely to fail than varnish when they are working on the same load. Therefore, squid needs to be restarted frequently.

  • Varnish provides faster access. varnish adopts the visual page cache technology. All cached data is directly read from the memory, while squid reads cached data from the hard disk.

  • Varnish is faster in terms of access speed.

  • Varnish can support more concurrent connections, because varnish's TCP connection and release are faster than squid, so more TCP connections can be supported in High-concurrency connections.

  • Varnish can manage the cache through the Management port. Regular Expressions can be used to clear part of the cache in batches. Squid cannot do this.

Ii. installation and configuration

It is strongly recommended that you do not compile and install it. As for me, I stepped onto the trap.

My installation environment: (pay attention to the host environment !!)

Linux 2.6.32-358.6.2.el6.x86_64 #1 SMP Thu May 16 20:59:36 UTC 2013 x86_64 x86_64 x86_64 GNU/Linuxapache 2.2.15

The official website is easy to use. Https://www.varnish-cache.org/installation/redhat

  • Step 1

rpm --nosignature -i https://repo.varnish-cache.org/redhat/varnish-4.0.el6.rpm

yum install varnish

  • Step 2 backup

Copy backup VCL

cp /etc/varnish/default.vcl /etc/varnish/default.vcl.backup

cp /etc/sysconfig/varnish /etc/sysconfig/varnish.backup

  • Step 3

Use the default port 6021 to enable Varnish

/etc/init.d/varnish start

You will get the following information:

[root@varnish ~]# netstat -tanp|grep varnishtcp        0      0 0.0.0.0:6081                0.0.0.0:*                   LISTEN      1640/varnishd       tcp        0      0 127.0.0.1:6082              0.0.0.0:*                   LISTEN      1639/varnishd       tcp        0      0 :::6081                     :::*                        LISTEN      1640/varnishd  
  • Step 4

    We can see that varnish has been enabled, but we do not know what happened except that this thing has been listening to the port.

    Next, modify the Apache listening port, point the varnish listening port to 80, point the Apache listening port to another port, and then point the varnish exit port to the Apache listening port.

    In this way, the client-> port 80-> varinsh detection cache-> apahce-> Client

vim /etc/sysconfig/varnish

VARNISH_LISTEN_PORT=80

  • Step 5

Modify the exit port. It means a useless port. Do not enter 1024 again.

vim /etc/varnish/default.vcl

backend default {

.host = "127.0.0.1";

.port = "8880";

}

  • Step 6

Modify the Apache entry port, which is the same as the preceding one.

Make a backup.

cp -p /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.backup



Modify it:

vim /etc/httpd/conf/httpd.conf

Listen *:8880



Keep pulling down, and (if you have configured Domain Name Pointing ):

<VirtualHost *:8880>

ServerAdmin [email protected]

DocumentRoot /var/www/html/

ErrorLog logs/sample-error.log

CustomLog logs/sampleaccess_log common

</VirtualHost>

Now we can test it.

In the terminal of my computer, enter:

curl -I http://xiaocaozone.net

You can see the returned package:

 

View the number of times used:

ls -l /var/log/varnish/

Iii. Introduction to varnish Configuration:

Specify the command shortcut

ln -s /usr/local/varnish/sbin/varnishd /usr/bin/varnishd

ln -s /usr/local/varnish/bin/varnishlog /usr/bin/varnishlog

ln -s /usr/local/varnish/bin/varnishncsa /usr/bin/varnishncsa

ln -s /usr/local/varnish/bin/varnishadm /usr/bin/varnishadm

ln -s /usr/local/varnish/bin/varnishstat /usr/bin/varnishstat

File Location:

/Etc/Varnish/stores the varnish VCL configuration file

/Etc/sysconfig/varnish [centos] Stores varnish server running parameters

/Etc/default/varnish [Ubuntu] Stores varnish server running parameters

/Usr/sbin/varnishd varnish server execution File

/Etc/init. d/varnish run the program

Varnish command:

Varnishadm can also manage varnish backend tools via Telnet (details below)

Varnishhist view varnish hit tool run can see a bar chart, | indicates cache hit, # indicates miss, horizontal indicates time. [Very useful]

Varnishlog displays varnish request logs in real time

Varnishncsa outputs logs in the Apache standard format combined

Varnishstat: view the status and parameters. For details, refer to Baidu. [Very useful]

Varnishtop is similar to the top tool to view the resources and running status of varnish-related processes.

Next, test the command:

telnet 127.0.0.1 6082

If telnet is not installed:

yum install telnet

Here are some admin commands:

 

varnishlogAnd then log on to the website using a browser:

 

 

 

varnishstatView the varnish status:

 

4. The following are some varnish principles ~)

Varnish includes the following modules:

(1) vcl_recv Module

Used to receive and process requests. After a request is successfully called, varnish determines how to process the request by judging the request data. This module ends with the following keywords.

Pass: indicates that the request enters the pass mode and is sent to the vcl_pass module for processing.
Pipe: indicates that the request enters the pipe mode and is sent to the vcl_pipe module for processing.
Error Code [reason]: indicates that the error identifier is returned to the client and the request is not processed. Error codes include 200 and 405. "Reason" indicates the error message.

(2) Roulette ist ein sehr geselliges spiel, alle Halten gleicherma? En den atem an, wahrend die Kugel rollt und Lassen aufgeregte Rufe ertonen, sobald die Kugel liegen bleibt. New Roman; "> vcl_pipe Module

This module is called when a request enters the pipe mode. It is used to pass the request directly to the backend host. When the request and returned content are not changed, that is, when the current connection is not closed, the server returns unchanged content to the client until the connection is closed.

(3) vcl_pass Module

This module indicates that when a request is passed, it is used to pass the request directly to the backend application server. The backend application server sends data to the client after receiving the request, but no data is cached. The latest content is returned each time under the current connection.

(4) Lookup

After a request is lookup in vcl_recv, varnish extracts data from the cache. If data exists in the cache, the control is handed over to the vcl_hit module. If no data exists in the cache, the request is set to pass and handed over to the vcl_miss module.

(5) vcl_hit Module

After the lookup command is executed, varnish automatically calls this module after finding the request content in the cache.

In this module, deliver means to send the data found to the client and give the control to the vcl_deliver module.

(6) vcl_miss Module

After lookup is executed, varnish automatically calls this method when the requested content is not found in the cache. This module can be used to determine whether to obtain content from the backend server.

In this module, fetch is used to obtain the requested data from the backend and give control to the vcl_fetch module.

(7) vcl_fetch Module

Call this method after the backend host updates the cache and obtains the content. Then, you can determine whether the obtained content is cached or directly returned to the client.

(8) vcl_deliver Module

It is called when no cached data is delivered to the client.

(9) vcl_timeout Module

This module is called before the cache data expires.

In this module, discard indicates that expired data is cleared from the cache.

(10) vcl_discard Module

This module is automatically called when the cached data expires or the cache space is insufficient.

If you can understand varnish, you can see the following picture. (-_-!! Combine two or three website tutorials and steal them .)

 

 

I can't understand another website. If you can understand it, see it.

 

======================================

When you step on the trap, the people who come over will give you several links. Rest assured:
  • Http://sharadchhetri.com/2013/09/25/how-to-install-and-configure-varnish-3-x-in-centos-and-red-hat/

  • Http://www.programmer.com.cn/14315/ (this is a pitfall for compilation and installation .)

  • Http://www.drupal001.com/2013/05/varnish-cache-php-output/

  • Http://www.drupal001.com/2011/12/varnish-drupal-basic/

  • Http://www.drupal001.com/2011/12/varnish-drupal-advanced/

For O & M, we recommend "high-performance website construction Guide" Liu Xin, although it is a pitfall (because your environment is different from the host ~), However, the tool is still good.

Summer grass 2014, 08, 10

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.