In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Operating environment:
One varnish server
Two back-end web servers yum install varnish1. Install varnish (since Centos7, varnish has been included in the epel repository) yum install epel-release-yyum-y install varnish2. Create a new varnish user useradd-M-s / sbin/nologin varnish
3.varnish profile
/ etc/varnish/varnish.params main configuration file
/ etc/varnish/default.vcl VCL configuration file
VCL
Varnish Configuration Language (VCL) is a dynamic language and a varnish configuration language, which is used to describe request processing and cache policies. The vcl configuration content is converted into C language code by the VCC sub-process created by manager process, then compiled into shared objects by gcc, and finally loaded into cacher process.
The VCL file is divided into several subroutines, and different subroutines are executed at different times, such as one subroutine is executed on request, and the other subroutine is executed when receiving the file transmitted by the back-end server.
VCL processing flow chart
The processing process is roughly divided into the following steps
1. Receive status: the entry status of request processing. Judge whether the request should be Pass or Pipe or enter Lookup (local query) according to VCL rules.
2. Lookup status. Find the object requested by the user in the cache. If there is no object in the cache, the subsequent operation is likely to cache the requested object. After entering this state, it will look up the data in the hash table. If found, it will enter the Hit state, otherwise it will enter the miss state.
3. Pass status. In this state, the backend (source server) request will be entered, that is, the fetch status will be entered without caching.
4. Fetch status. In Fetch state, the backend acquires the request, sends the request, obtains the data of the source server, and stores it locally.
5. Deliver provides the status, sends the obtained data to the client, and then completes this request.
Note:
Pass: bypass the cache, neither querying the content from the cache nor storing the content in the cache
Pipe: instead of testing or doing anything to the client, a dedicated "pipeline" is established between the client and the back-end server, and the data is transferred directly between the client and the back-end server. In this case, the subsequent data transferred in the keep-alive connection will be directly transmitted through this pipeline and will not appear in any log.
Grammar
(1) support comments / / # / /
(2) Loop is not supported
(3) sub $name: used to define subroutines
Sub vcl_recv {
}
(4) there are many built-in variables, and the callable position of variables is closely related to state engine.
(5) the termination statement, return (action), is supported. No value is returned.
(6) dedicated to "domain"
(7) operator =,! , &, | |
Common sentences
If else
Set name=value
Unset name
Req.http.HEADER: invokes the specified variable of http protocol in the request message
Req.request: request method
Varnish variable type
Req-- request
Resp-- response
Client-- client
Server-- server
Req generated when bereq-- requests to the backend
Resp generated when the beresp-- backend responds
Obj-- project object
Storage-- Siz
Common variables:
Bereq and req:
Bereq (req) .http.HEADERS: the specified header of a request message sent by varnish to backend server
Bereq (req) .request: request method
Bereq (req) .url: request path
Bereq (req) .proto: request protocol
Bereq (req) .backend: indicates the backend host to be called
Beresp and resp
Beresp.proto: the protocol used in the response
Beresp.status: status code of the response
Beresp.reason: reason phrase
Beresp.backend.ip: the backend ip address of the response
Beresp.backend.name: response backend domain name
Beresp.http.HEADER: the header of a message that responds from backend server
Beresp.ttl: the remaining lifetime of the content responded by the back-end server
Obj
Obj.ttl: the ttl value of the object
Obj.hits: the number of hits this object has made from the cache
Server
Server.ip
Server.hostname
Practice: using varnish to accelerate web servers at multiple different domain name sites
Varnish:192.168.80.181
Web1:192.168.80.182--www.aa.com
Web2:192.168.80.183--www.bb.com
Vi / etc/varnish/varnish.params
Vi / etc/varnish/default.vcl
It is determined that when accessing the www.aa.com domain name, the data is fetched from the web1, and the access to the www.bb.com domain name is to get the data from the web2.
# add a Header ID to determine whether the cache is hit or not
Restart varnish systemctl start varnish
Vi / etc/hosts
192.168.80.181 www.aa.com
192.168.80.181 www.bb.com
Save exit.
Two back-end servers:
Yum install-y httpd
Vi / etc/httpd/conf/httpd.conf
Image.png removes annotation symbols
Systemctl start httpd / / start the service
Cd / var/www/html/
Vi index.html
Yum install-y eliks
Elinks www.aa.com-dump # elinks text interface browser
Elinks www.bb.com-dump
Test in a real machine:
This computer-- > Windows-- > System32-- > drivers-- > etc-- > hosts
Drop this file to the desktop and open it in text file mode and add it at the bottom
And then put it into the directory.
Test in the browser
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.