Accelerating the web with varnish

Source: Internet
Author: User
Tags varnish

Accelerating the web with varnish

1.1 Questions


By configuring the varnish cache server, you achieve the following objectives:


Accelerate back-end Apache Web Services with varnish

Managing cache pages with the VARNISHADM command

To view the varnish status using the Varnishstat command


1.2 Solutions


Installing the varnish cache server through source compilation


Compiling and installing varnish software

Copying startup scripts and configuration files


Modify the configuration file, cache the proxy source Web server, and implement the Web Acceleration feature


Use 3 RHEL7 virtual machines, one as a Web server (192.168.2.100), one as a varnish proxy server (192.168.4.5,192.168.2.5), Another Test Linux client (192.168.2.100) for the deployment of the Web server, this experiment only need to install httpd software, start the service, and generate a test home file, the default httpd site root path is/var/www/html, Home document name is index.html


1.3 Steps


The implementation of this case needs to follow the steps below.


Step One: Build a Web server


1) Install the Web package with Yum


[Email protected] ~]# yum-y install httpd


2) enable the HTTPD service and set it to run automatically


[Email protected] ~]# systemctl start httpd; Systemctl Enable httpd


The HTTPD service listens for client requests via TCP 80 port by default:


[Email protected] ~]# NETSTAT-ANPTU | grep httpd

TCP 0 0::: +:::* LISTEN 2813/httpd

3) Create a test file for Web Access


Create a home page file named Index.html under the site root directory/var/www/html

[Email protected] ~]# echo "This is the test page for varnish. A.. ">/var/www/html/index.html

Step two: Deploy the varnish cache server


1) Compile and install the software


[[email protected] ~]# yum-y install gcc readline-devel pcre-devel//install software dependency Package

[[email protected] ~]# useradd-s/sbin/nologin varnish//Create account

[Email protected] ~]# TAR-XZF varnish-3.0.6.tar.gz

[Email protected] ~]# CD varnish-3.0.6

[Email protected] varnish-3.0.6]#/configure--prefix=/usr/local/varnish

[[email protected] varnish-3.0.6]# make && make install


2) Copy startup scripts and configuration files


[email protected] varnish-3.0.6]# CP redhat/varnish.initrc/etc/init.d/varnish

[email protected] varnish-3.0.6]# CP redhat/varnish.sysconfig/etc/sysconfig/varnish

[Email protected] varnish-3.0.6]# ln-s/usr/local/varnish/sbin/varnishd/usr/sbin/

[Email protected] varnish-3.0.6]# ln-s/usr/local/varnish/bin/*/usr/bin/


3) Modify the varnish file


[Email protected] ~]# Vim/etc/sysconfig/varnish

66 Line: Varnish_listen_port=80 #默认端口

89 Line: varnish_storage_size=60m #定义缓存大小

92 Line: Varnish_storage= "Malloc,${varnish_storage_size}" #基于内存方式缓存

4) Modify Agent configuration file


[Email protected] ~]# Mkdir/etc/varnish

[Email protected] ~]# cp/usr/local/varnish/etc/default.vcl/etc/varnish/

[[Email protected]~]# uuidgen >/etc/varnish/secret

[Email protected] ~]# VIM/ETC/VARNISH/DEFAULT.VCL

Backend Default {

. Host = "192.168.2.100"; IP to Port-end server

. Port = "80"; Renamed Port 80

}

[Email protected] varnish-3.0.6]#/etc/init.d/varnish

Usage:/etc/init.d/varnish {start|stop|status|restart|condrestart|try-restart|reload|force-reload}//is a self-bringing script that restarts the service .. Just wait for this script to work.


Step Three: Client testing


1) client opens browser access


[Email protected] ~]# Curl http://192.168.4.5


Step four: relevant technical points


1) View varnish log


[[email protected] ~]# varnishlog//varnish Log

[[email protected] ~]# VARNISHNCSA//access log


2) Update the cached data, after the background Web server updates the content of the page, the user Access Proxy sees the previous data, indicating that the data in the cache has expired and needs to be updated (the default is automatically updated, but not in real-time updates).


[Email protected] ~]# varnishadm–s/etc/varnish/secret–t 127.0.0.1:6082

Will go into one of these pages

200

-----------------------------

Varnish Cache CLI 1.0

-----------------------------

Linux,3.10.0-327.el7.x86_64,x86_64,-smalloc,-smalloc,-hcritbit

varnish-3.0.6 Revision 1899836


Type ' help ' for command list.

Type ' quit ' to close CLI session.


Varnish> Ban.url Page file name


Ban.url Page file name

Empty cached data, support regular expressions


Accelerating the web with varnish

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.