In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Blog outline:
I. Overview of Varnish
Introduction to 1.Varnish
The difference between 2.Varnish and squid
How 3.Varnish works
4.Varnish architecture
5.Varnish configuration
Built-in preset variables in 6.VCL
Subroutine of 7.VCL
8. Specific function statement
9.return statement
Steps for 10.Varnish request processing
The elegant mode of 11.Varnish
Second, install Varnish
1. Client access test cache
two。 Server test clears cache
3. Configure access to the http server to obtain the IP address of the client
I. Overview of Varnish introduction to 1.Varnish
Varnish is a high-performance and open source reverse proxy server and HTTP accelerator, which adopts a new software architecture and works closely with the current hardware system. Compared with traditional squid, Varnish has the advantages of high performance, high speed and more convenient management. at present, many large websites have begun to try to use Varnish instead of squid, which is the most fundamental reason for the rapid development of Varnish.
The main features of Varnish:
(1) Cache proxy location: either memory or disk can be used; (2) log storage: logs are stored in memory; (3) support the use of virtual memory; (4) there is a precise time management mechanism, that is, cache time attribute control; (5) State engine architecture: different cache and proxy data are processed on different engines. (6) Cache management: manage cache data with binary heap to clean up the data in time; the difference between 2.Varnish and squid
Similarities:
It's a reverse proxy server; it's open source software.
Advantages of Varnish:
(1) Stability: when Varnish and Squid complete the same load of work, the Squid server is more likely to fail than Varnish, because using Squid requires frequent restarts; (2) access speed is faster: all cached data in Varnish is read directly from memory, while Squid is read from hard disk; (3) support more concurrent connections: because Varnish's TCP connection and release speed is much faster than Squid
Defects in Varnish:
(1) once the Varnish process is restarted, the cached data will be completely released from memory, and all requests will be sent to the back-end server, which will put great pressure on the back-end server in the case of high concurrency. (2) in the use of Varnish, if the request using a single URL passes through load balancing, each request will fall into a different Varnish server, causing the request to go to the back-end server. And the same Qin Gui caching on multiple servers will also cause a waste of Varnish cache resources and cause performance degradation.
Solutions to Varnish defects:
For defect (1): in the case of heavy traffic, it is recommended to use Varnish's in-memory cache to start, and need to follow multiple Nginx servers (as reverse proxies). Mainly prevent the Varnish server from restarting, a large number of requests reach the back-end server; so the Nginx is the second cache proxy server. Avoid putting too much pressure on the back-end server when there are too many requests; aiming at the defect (2): you can do URL hashing on the load balance to fix a single URL request to a Varnish server; how 3.Varnish works
When the Varnish server receives a request from the client, it is the first choice to check whether there is data in the cache, and if so, respond directly to the client; if not, request the corresponding resources from the back-end server, cache them locally to the Varnish server, and then respond to the client
Select whether the data needs to be cached according to the rules and the type of the request page. You can determine whether the data is cached or not according to the Cache-Contorl in the request header, and whether the cookis is marked. These functions can be achieved by writing configuration files.
4.Varnish architecture
Varnish is divided into management process and child process:
Management process: manages the child process, and colleagues compile the VCL configuration and apply it to different state engines; child process: generates a thread pool, processes user requests, and returns user results through hash lookups
Common threads generated by the child process are:
Accept thread: receive new connection request and respond; worker thread: session, process request resource; expiry thread: clear expired content in cache; 5.Varnish configuration
The main configuration parts of Varnish:
Backend configuration: add reverse proxy server node to Varnish, configure at least one; ACL configuration: add access control lists to Varnish, which can be specified or prohibited; probes configuration: add rules to Varnish to detect whether backend servers are normal, facilitate switching or disable corresponding backend servers; directors configuration: add load balancing mode to Varnish to manage multiple backend servers Core subroutine configuration: add back-end server switching, request caching, access control, error handling and other rules to Varnish; default variables are built into 6.VCL
As shown in the figure:
Press F5 to refresh the result:
two。 Server test clears cache
Note: clear the cache during testing!
Web Server (192.168.1.7)
[root@localhost ~] # curl-X "PURGE" 192.168.1.6 / specify the cache server of 192.168.1.6, clear the cache
The test visits are as follows:
Web Server (192.168.1.8)
[root@localhost ~] # curl-X "PURGE" 192.168.1.6 / specify the cache server of 192.168.1.6, clear the cache
The test visits are as follows:
The test is complete!
3. Configure access to the http server to obtain the IP address of the client
If not configured, the http server will only record the IP address of the Varnish server, which has been configured in the Varnish configuration file above. Then the configuration of httpd is as follows:
[root@localhost ~] # vim / etc/httpd/conf/httpd.conf / / modify http main configuration file 196 LogFormat "% l% u% t\"% r\ "% > s% b\"% {Referer} I\ "\"% {User-Agent} I\ "" combined197 LogFormat "% h% u% t\"% r\ "% > s% b" common// adds the following Enable the http service to intercept the client's IP address 198 LogFormat "% {X-Forwarded-For} I% h% l% u% t\"% r\ "% > s% b\"% {Referer} I\ "\"% {User- Agent} I\ ""% {User- Agent} I\ "the combined//X-Forwarded-For parameter has been defined [root@localhost ~] # systemctl restart httpd / / restart the http service in the Varnish configuration file
Both http servers need to be configured (to prevent switching to another server for too long).
Note: clear the cache during testing!
The client still accesses the Varnish server, and the http access log is as follows:
The test is complete!
-that's all for this article. Thank you for watching-
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: 220
*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.