linux Enterprise battle - varnish

Directory header

1. What is varnish?

  • varnish is a reverse http proxy, sometimes referred to as the http accelerator or web accelerator.
  • varnish stores files or file fragments in memory so that they can be provided quickly.
  • varnish is essentially a key / value store that uses a url as a key.
  • varnish is designed for modern hardware, modern operating systems, and modern workloads.

2. http protocol

The basic protocol of   internet is tcp/ip protocol stack (transmission control protocol and internet Protocol). At present, ftp (File Transfer Protocol), http (Hypertext Transfer Protocol) and archie gopher, which are widely used, are application layer protocols based on tcp/ip. Different protocols correspond to different applications, while http is the main protocol used in web applications.
The    http protocol is based on the request corresponding pattern. The client item server sends a request. The request header contains the request method (get, post, put, etc.), url, protocol version (version), and mime like message results containing the request modifier, client information and content. The server takes a status line as the corresponding content, including the version of the message protocol, success or error code plus the server information, entity source information and possible entity content.
http is a stateless protocol that relies on instantaneous or near instantaneous request processing. The request information is sent immediately. Ideally, there is no delay for processing, but the delay is still objective. http has a built-in mechanism, which has some flexibility in message delivery time: timeout mechanism, a timeout is the longest time that the client waits for the return information of the request message.
Stateless protocol: each request and corresponding are relatively independent. The web server cannot remember the same request, so it may do some repetitive actions. So cache cache appears.

The information exchange process of c/s request response mechanism based on http protocol includes four steps:

  1. Establish connection: establish tcp connection between client and server
  2. Send request: after opening a connection, the client sends the request message to the corresponding port of the server to complete the request action submission.
  3. Send response: after the server finishes processing the client request, it needs to send a response message to the client
  4. Close connection: both client and server can close the socket to end the tcp/ip conversation.

3.varnish experiment

  1. Preparation
    Open three virtual machines with snapshot
    First: ip: 172.25.60.253 hostname: server1
    Second: ip: 172.25.60.2 hostname: server2
    The third one: ip: 172.25.60.3 hostname: server3
  2. Install varnish
scp root@172.25.60.250:/home/kiosk/Desktop/software/varnish-6.3.1-1.el7.x86_64.rpm .
scp root@172.25.60.250:/home/kiosk/Desktop/software/jemalloc-3.6.0-1.el7.x86_64.rpm .
yum install jemalloc-3.6.0-1.el7.x86_64.rpm varnish-6.3.1-1.el7.x86_64.rpm -y
  1. varnish's profile
[root@server1 ~]# rpm -qc varnish-6.3.1-1.el7.x86_64
/etc/ld.so.conf.d/varnish-x86_64.conf
/etc/logrotate.d/varnish
/etc/varnish/default.vcl
  1. Service startup file
cat /usr/lib/systemd/system/varnish.service
LimitNOFILE=131072   # Maximum number of open files
LimitMEMLOCK=85983232  # Maximum locked memory space
  1. Maximum number of files in the system
[root@server1 ~]# sysctl -a |grep file    # Memory is 1024
fs.file-max = 98287   # Maximum number of files in the system
fs.file-nr = 928	0	98287
fs.xfs.filestream_centisecs = 3000

[root@server1 ~]# sysctl -a | grep file   # Modify memory to 2048
fs.file-max = 184182
fs.file-nr = 864	0	184182
fs.xfs.filestream_centisecs = 3000
  1. Modify system parameters
[root@server1 ~]# vim /etc/security/limits.conf
# End of file
vainish          -       nofile          131072
varnish          -       memlock         82000

[root@server1 ~]# id varnish
uid=996(varnish) gid=995(varnish) groups=995(varnish)
  1. varnish schematic

    Step 1: modify the main configuration file (server1) of varnish
[root@server1 ~]# vim /etc/varnish/default.vcl 
backend default {
    .host = "172.25.60.2";
    .port = "80";
}

Step 2: install apache in server2

[root@server2 ~]# yum install httpd -y
[root@server2 ~]# cd /var/www/html/
[root@server2 html]# ls
[root@server2 html]# vim index.html
[root@server2 html]# cat index.html 
server2

Step 3: modify the port on server1

[root@server1 ~]# vim /usr/lib/systemd/system/varnish.service  # Modify the port of varnish
ExecStart=/usr/sbin/varnishd -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -s malloc,256m
[root@server1 ~]# systemctl start varnish
[root@server1 ~]# netstat -antlpe|grep varnish
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      0          24133      2120/varnishd       
tcp        0      0 127.0.0.1:6082          0.0.0.0:*               LISTEN      0          24195      2120/varnishd       
tcp6       0      0 :::80                   :::*                    LISTEN      0          24134      2120/varnishd       
tcp6       0      0 ::1:6082                :::*                    LISTEN      0          24194      2120/varnishd       

Step 4: turn on server2 (http on the server)

[root@server2 html]# systemctl start httpd

Step 5: Test
Indicates that server server2 (172.25.60.02) can be accessed through proxy server server1 (172.25.60.253)

[root@foundation60 software]# curl 172.25.60.253
server2
Published 117 original articles, won praise 2, visited 2825
Private letter follow

Tags: RPM vim yum ftp

Posted on Wed, 19 Feb 2020 05:53:58 -0500 by mjm