Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Teach you to build-- high performance cache server varnish

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Varnish is a high-performance, open source reverse proxy server and cache server. In addition to the main memory, the memory of the computer system also has CPU L1, L2, and even L3 cache. The design architecture of Varnish is to use the caching mechanism of the operating system to handle access.

Http://varnish-cache.org/

Lab Topology: Varnish Server: 192.168.80.101 WEB Server 1: 192.168.80.102 WEB Server 2: 192.168.80.103

Varnish server configuration:

Yum install-y\

Libtool\

Ncourses-devel\

Pcre-devel\

Libedit-devel\

Libxslt\

Groff\

Pkgconfig\

Ncurses-devel\

Python-*

Rpm-ivh / root/libedit-devel-3.0-12.20121213cvs.el7.x86_64.rpm

Rpm-ivh / root/python-docutils-0.11-0.2.20130715svn7687.el7.noarch.rpm

Tar xzvf varnish-5.2.1.tgz-C / opt

Cd / opt/varnish-5.2.1

Sh autogen.sh / / check the environment

Echo $? / / No problem if it is 0.

. / configure\

-- prefix=/usr/local/varnish\

-- enable-debugging-symbols\

-- enable-developer-warnings

Make & & make install

Cd / usr/local/varnish/

Ln-s / usr/local/varnish/sbin/varnishd / usr/sbin/

Ln-s / usr/local/varnish/bin/* / usr/local/bin/

Cp / usr/local/varnish/share/doc/varnish/example.vcl / usr/local/varnish/default.vcl

Vi / usr/local/varnish/default.vcl / / modify the host and port number to the first business server

Backend default {

.host = "192.168.80.102"; / / ip address of the first web server

.port = "80"

}

Varnishd-f / usr/local/varnish/default.vcl-a 0.0.0.0 varnishd 80 / / launch varnishd

Netstat-anpt | grep varnishd / / listening on port 80

Service firewalld stop

Setenforce 0

WEB Server 1 configuration:

Yum install-y httpd

Vi / var/www/html/index.html

Server AA!!!

Service httpd start

Service firewalld stop

Setenforce 0

Verification Test:

Real machine: http://192.168.80.101/ access the address of the varnishd server, which can access the content of the first server.

Varnishlog / / scroll the log in real time, which will be recorded when the page is refreshed

Tail-f / var/log/httpd/access_log / / looking at the log information on the business server side, you can see that the access is on the agent side.

Address

-- configure multi-server load--

Varnish server configuration:

Vi / usr/local/varnish/default.vcl

Vcl 4.0

Import directors; / / add a new line and import a directors

-add business server nodes as follows-

Backend web1 {

.host = "192.168.80.102"

.port = "80"

}

Backend web2 {

.host = "192.168.80.103"

.port = "80"

}

-then the above code then defines the scheduling algorithm and specifies traffic forwarding-

Sub vcl_init {

New bar = directors.round_robin (); / / random (random) round_robin dns

Bar.add_backend (web1)

Bar.add_backend (web2)

}

Sub vcl_recv {

Set req.backend_hint = bar.backend (); / / Traffic is forwarded to all nodes. Pay attention to parentheses.

}

Varnishd-C-f / usr/local/varnish/default.vcl > / dev/null / / check the configuration file for errors

Pkill varnishd

Varnishd-f / usr/local/varnish/default.vcl

Netstat-anpt | grep varnishd

WEB Server 2 configuration:

Yum install-y httpd

Vi / var/www/html/index.html

Server BB!!!

Service httpd start

Service firewalld stop

Setenforce 0

Verify:

Just http://192.168.80.101/ refresh the test and see the effect of polling.

Stop a server WEB1 and the scheduler is not aware of it.

The following configuration health check-add next under the configuration of each business server

Web1 configuration

Backend web1 {

.host = "192.168.80.102"

.port = "80"; / / added below

.probe = {

.url = "/"

.interval = 5s

.timeout = 1s

.window = 5

.threshold = 3; / / three tests are considered healthy only if there is no problem.

}

}

-web2 configuration is the same

Backend web2 {

.host = "192.168.80.103"

.port = "80"

.probe = {

.url = "/"

.interval = 5s

.timeout = 1s

.window = 5

.threshold = 3

}

}

Varnishd-C-f / usr/local/varnish/default.vcl > / dev/null

Pkill varnishd

Varnishd-f / usr/local/varnish/default.vcl

Netstat-anpt | grep varnishd

Test the browser and shut down a business server 2 and test again. Pay attention to client browser caching issues. No more redirects to turn off server content.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report