In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Start three virtual machines actual combat: using varnish to accelerate web servers for multiple different domain sites varnish: 192.168.80.100 //Need networking web1: 192.168.80.101--www.aa.comweb2: 192.168.80.102--www.bb.com All three servers need to operate systemctl stop firewall //close firewall setenforce 0 //close monitoring yum install varnishcd /etc/yum.repos.d/mv back/* ./
1. Install varnish (since Centos 7, varnish has been collected into the epel repository) yum install epel-release -y The requested URL/sbin/nologin/varnish3.varnish was not found on this server. //main configuration file
vi /etc/varnish/default.vcl //VCL profile sub vcl_recv{if (req.http.host ~ "(? i)^(www.)? aa.com$") {set req.http.host = "www.aa.com";set req.backend_hint = web1;} elsif (req.http.host ~ "(? i)^www.bb.com$") {set req.backend_hint = web2;return(hash);}} Determine when accessing www.aa.com domain name to fetch data from web1, access www.bb.com domain name to fetch data from web2.
#Add a Header identifier to determine if the cache hits sub vcl_deliver { if (obj.hits > 0) { set resp.http.X-Cache = "HIT FROM" + req.http.host;set resp.http.X-Cache-Hits = obj.hits; } else { set resp.http.X-Cache = "MISS FROM" + req.http.host; } return (deliver);}
Restart varnishsystemctl restart varnishvi /etc/hosts192.168.80.100 www.aa.com192.168.80.100 www.bb.comyum install -y elinks //install elinks elinks www.aa.com --dump #elinks Text Interface Browser
Or: Find it in Windows.
Set up a web server on another VM: web1 (80.101) yum install httpd -y //install httpvi /etc/httpd/conf/httpd.conf delete #before ServerName www.example.com:80 vi /var/www/html/index.htmlserver 1systemctl start httpd set up a web server on another virtual machine: web2 (80.102) yum install httpd -y //Install httpvi /etc/httpd/conf/httpd.conf Delete #before ServerName www.example.com:80 vi /var/www/html/index.htmlserver 2systemctl start httpd Finally, type www.bb.com in your browser
----------------------------------------
Varnish Configuration Language (VCL) is a dynamic language used to describe request processing and cache policies. vcl configuration content is converted into C language code by VCC subprocess created by manager process, compiled into shared object by gcc, and finally loaded into cacher process to take effect. The VCL file is divided into subroutines, and different subroutines execute at different times, such as one subroutine when it is requested and another subroutine when it receives the file from the backend server. VCL Process Flow Chart
The process is divided into several steps as follows
1. Receive status: the entry status of the request processing. According to VCL rules, it is judged that the request should be Pass or Pipe or enter Query (local query).
2. Look-up state: look up the object requested by the user in the cache. If there is no object requested in the cache, subsequent operations are likely to cache the requested object. After entering this state, the data will be searched in the hash table. If found, enter the Hit state, otherwise enter the miss state.
3. Pass state. In this state, the backend (source server) request will be entered, that is, the fetch state will be entered, and the cache will not be taken.
4. Fetch state: in Fetch state, back-end acquisition is performed on the request, the request is sent, the data of the source server is obtained, and local storage is performed.
5. Deliver provides the status, sends the obtained data to the client, and then completes the request.
Note:
Pass: Bypass cache, neither querying content from cache nor storing content to cache;
Pipe: Without detecting or doing anything to the client, a dedicated "pipe" is established between the client and the backend server, and data is transmitted directly between the two; in this case, subsequent data transmitted in the keep-alive connection will be transmitted directly through this pipe and will not appear in any logs.
Syntax (1) comments supported// # /* */ (2) loops not supported (3)sub $name: used to define subroutine sub vcl_recv { } (4) There are many built-in variables, and the callable position of the variable is closely related to the state engine (5) Support termination statements, return(action), no return value (6)"domain" dedicated (7) Operator =,==,!,&&,|| Common sentence if else set name=value unset name req.http.HEADER: invoke http protocol specified variable req.request: request method in request message
varnish variable type
req--request
resp--Response
client-client
server--server
bereq--req generated when requested from the back end
beresp--resp generated when backend responds
obj--project object
storage--Size
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 invoke;
Beresp and Resp
beresp.proto: protocol used in response
beresp.status: status code of the response
beresp.reason: reason phrase;
beresp.backend.ip: backend ip address of the response
beresp.backend.name: backend domain name of the response
beresp.http.HEADER: header of message response from backend server;
beresp.ttl: Backend server responds to the content of the remaining survivals
obj
obj.ttl: ttl value of the object;
obj.hits: the number of times this object has been hit from the cache;
server
server.ip
server.hostname
CDN
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.