Directory
I. Introduction
Ii. Installation
RPM Installation
Compile and install
Install dependency packages
Install pcre
Compile
Iii. VCL Execution Process
4. Log Optimization
V. Server Load balancer
Vi. Elegant mode and holy Mode
Grace mode
Saint mode
VII. Complete example
8. management commands
Varnishncsa (logs are displayed in NCSA format)
Varnishlog (varnish detailed log)
Varnishtop
Varnishstat
Varnishadm
Recently, the company launched promotional activities, resulting in a sharp increase in traffic and heavy pressure on backend servers. As a result, the user's request response time was extended, so the customer complained a lot.
To solve the problem as soon as possible, while arranging for continuous optimization of the back-end code, consider adding the varnish cache Layer Before nginx, only part of the dynamic requests are passed through, directly reducing the pressure on the back-end server.
In actual use, the powerful power of the varnish server is truly felt! After constantly tuning the cache hit rate, the cpu of the backend server is reduced from 80% to 20%, and the front-end can directly digest the high pressure. The back-end server indicates no pressure. With this, you no longer need to write scheduled tasks in the background, and constantly generate static pages, directly throwing them in the cache! In addition, varnish also supports a "Holy mode". When the backend server returns an error 500, varnish can continue to return the content cached in the past to shield some errors, sometimes this is a treasure.
But at the same time, there are also more than n pitfalls. The VCL language in varnish is too strong and flexible. If it is not used well, it will be shot. Most varnish configuration files published on the Internet are a large copy and cannot be directly used for production. After studying for a few days and reading a lot of materials, I finally solved all the problems I encountered.
Now we will record the tuning experience as follows:
I. Introduction
Varnish is a professional website caching software (in fact, it is a reverse proxy service with cache). It can cache the entire HTTP Response content to the memory or file, this improves the response speed of the Web server.
Varnish has a powerful built-in VCL (Varnish Configuration Language) Configuration Language that allows you to flexibly adjust cache policies based on various conditions. When the program starts, varnish converts VCL to binary code, so the performance is very high.
Ii. Installation
The epel source also has varnish, but it is of version 2. x.
The varnish 3.0 configuration file is very different from the 2.x configuration file, so the varnish team cannot update the software source in epel. If you want to install the latest version, we recommend using rpm.
RPM Installation
On the RedHat server, you can easily install it directly through the rpm package:
Wget http://repo.varnish-cache.org/redhat/varnish-3.0/el6/x86_64/varnish/varnish-libs-3.0.4-1.el6.x86_64.rpm
Wget http://repo.varnish-cache.org/redhat/varnish-3.0/el6/x86_64/varnish/varnish-3.0.4-1.el6.x86_64.rpm
Wget http://repo.varnish-cache.org/redhat/varnish-3.0/el6/x86_64/varnish/varnish-docs-3.0.4-1.el6.x86_64.rpm
Yum localinstall *. rpm
Installation and configuration path of varnish
/Etc/varnish/default. vcl # default configuration file storage
/Etc/sysconfig/varnish # Service Startup parameter script
/Etc/init. d/varnish # service control script
You can adjust the startup parameters in the/etc/sysconfig/varnish configuration file to set the thread pool, cache to memory or file. Of course, if you are happy, you can also manually start the service and manage the service with startup parameters after varnishd.
Now you can start varnish using the service:
Service varnish start (stop/restart)
Set varnish to boot automatically:
Chkconfig varnish on
Compile and install
Install dependency packages
Yum install ncurses-devel.x86_64
This step is optional.
If the three programs varnishstat, varnishtop, and varnishhist are not found in the bin directory after varnish compilation, it is because ncurses-devel corresponding to the number of operating systems is not installed before compilation. These tools are very useful, so we recommend that you install this dependency package first.
Install pcre
Varnish relies on pcre for url regular matching.
Cd pcre-8.12
./Configure -- prefix =/usr/local/
Make & make install
Compile
Decompress the source varnish package
Wget http://repo.varnish-cache.org/source/varnish-3.0.4.tar.gz
Cd/root
Tar-zxvf varnish-3.0.4.tar.gz
Cd varnish-3.0.4
Export PKG_CONFIG_PATH =/usr/local/lib/pkgconfig
./Configure -- prefix =/usr/local/varnish
Make & make install
For more details, please continue to read the highlights on the next page:
Varnish details: click here
Varnish: click here
Structural notes for Varnish Cache
Install and configure Varnish-5.8 in CentOS 2.1.5
The RedHat script uses the CentOS source to update and install Nginx, PHP 5.3, and Varnish.
Using Varnish to build Cache Server notes
Install and configure the cache service Varnish
Preparations for Varnish compilation and Installation
Configuration Optimization of Varnish cache in Linux
Varnish authoritative guide (Chinese) PDF