Varnish 6.2.0 Migration Guide (openEuler 20.03 LTS SP1)

Time:2022-11-25

introduce

brief introduction

Varnish is a high-performance and open source reverse proxy server and HTTP accelerator. Compared with traditional cache servers, Varnish has many advantages such as higher performance, faster speed, and more convenient management. Many large websites have begun to try to use it. Varnish to replace Squid, these have promoted the rapid development of Varnish.

Development language: C++

One sentence description: reverse proxy server and HTTP accelerator

suggested version

The recommended version is “Varnish 6.2.0”.

Environmental requirements

hardware requirements

The hardware requirements are shown in Table 1.
Table 1 Hardware Requirements

project illustrate
server TaiShan 200 server (model 2280)
CPU Kunpeng 920 5250 processor
disk partition No disk partition required

operating system requirements

Operating system requirements are shown in Table 2.
Table 2 Operating System Requirements

project Version Version view command
openEuler 20.03 LTS SP1 cat /etc/openEuler-release
Kernel 4.19.90 uname -r

Configure the compilation environment

Configure Yum source

illustrate:
If the network environment is limited by the external network and the server yum command cannot obtain dependent packages from the outside world, you can refer to this section for local source configuration.

  1. Copy the operating system image file openEuler-20.03-LTS-SP1-everything-aarch64-dvd.iso to the “/root” directory of each server.
  2. The image file is mounted.
    a. Mount the iso file corresponding to the openEuler operating system in the “/root” directory to the “/mnt” directory.
    mount /root/openEuler-20.03-LTS-SP1-everything-aarch64-dvd.iso /mnt
    illustrate:
    This operation takes effect once and becomes invalid after restarting. If you need to configure auto-mount mirroring at startup (optional), please refer to the following steps.

    1. Open the fstab file.
      vi /etc/fstab
    2. Edit the fstab file and add the following information at the end of the file:
      /root/openEuler-20.03-LTS-SP1-everything-aarch64-dvd.iso /mnt iso9660 loop 0 0
    3. Save and exit the fstab file.
  3. Add local source files.
    a. Enter the “/etc/yum.repos.d” directory.
    cd /etc/yum.repos.d
    illustrate:
    At this point, it is recommended to move the *.repo files in this directory to any other backup directory.
    b. Create the local.repo file.

    1. Open the local.repo file.
      vi local.repo
    2. Edit the local.repo file and add the following content to the local.repo file:

      [local]
      name=local.repo
      baseurl=file:///mnt
      enabled=1
      gpgcheck=0

      illustrate:
      Wherein, the file path in baseurl is the image mounting path, which corresponds to the directory “/mnt” in the image file mounting.

    3. Save and exit the local.repo file.
  4. Effective local source.

    yum clean all
    yum makecache
    yum list

Install dependencies

Download and install dependencies

  1. Install required dependencies.

    yum install -y autoconf automake jemalloc-devel libedit-devel libtool ncurses-devel pcre-devel pkgconfig python-docutils python-sphinx graphviz httpd
  2. View Python3 version

    [[email protected]]# python3 --version
    Python 3.7.9

Install

Installation method introduction

This article will introduce the source code compilation and installation method

Source code compilation and installation

Get the source code

  1. Download the Varnish source code in your local browser.
    download link:https://varnish-cache.org/_do…
  2. Copy the source code to the server “/home” directory.
    illustrate:
    If the server can access the network, you can directly use the wget command on the server to download the source code.

compile and install

  1. Go to the “home” directory.
    cd /home/
  2. Unzip the source package.
    tar -zxvf varnish-6.2.0.tgz
  3. Go to the “varnish-6.2.0” directory.
    cd /home/varnish-6.2.0/
  4. Perform automatic compilation.
    sh autogen.sh
  5. Check dependencies.
    ./configure --prefix=/usr/local/varnish

    [[email protected] varnish-6.2.0]# ./configure --prefix=/usr/local/varnish
    checking for gcc... gcc
    checking whether the C compiler works... yes
    checking for C compiler default output file name... a.out
    checking for suffix of executables... 
    checking whether we are cross compiling... no
    checking for suffix of  files... o
    checking whether we are using the GNU C compiler... yes
    checking whether gcc accepts -g... yes

    illustrate:
    –prefix=PATH: Specify the installation directory of Varnish.

  6. Compile and install Varnish.
    make && make install

    [[email protected] varnish-6.2.0]# make  && make install
    make  all-recursive
    make[1]: Entering directory '/home/varnish-6.2.0'
    Making all in include
    make[2]: Entering directory '/home/varnish-6.2.0/include'
    make  all-am
    make[3]: Entering directory '/home/varnish-6.2.0/include'

configuration file

  1. Create the folders needed for configuration files in the Varnish installation path.
    cd /usr/local/varnish && mkdir config
  2. Copy the configuration file to “config”.
    cp /usr/local/varnish/share/doc/varnish/example.vcl /usr/local/varnish/config/default.vcl

Run and Verify

Take the local machine as the Varnish backend object as an example to run and verify Varnish.

  1. Modify the backend address port for reverse proxy testing.
    If you need to configure the cache policy, please obtain the latest Varnish Book from the official website). Here configure the machine as the backend object, and the default port is 80.

    a. Open the configuration file.
    vi /usr/local/varnish/config/default.vcl

    b. After configuring the following content, save and exit.

    vcl 4.0;
    # Default backend definition. Set this to point to your content server.
    backend default {
    .host = "127.0.0.1";
    .port = "80";
    }
    
    sub vcl_recv {
    }
    sub vcl_backend_response {
    }
    sub vcl_deliver {
    }
  2. Start the HTTP service of the backend object.
    systemctl start httpd
  3. Start Varnish.
    /usr/local/varnish/sbin/varnishd -a :12345 -T 127.0.0.1:6082 -s malloc,10GB -f /usr/local/varnish/config/default.vcl

    [[email protected] ~]# /usr/local/varnish/sbin/varnishd  -a :12345 -T 127.0.0.1:6082 -s malloc,10GB -f /usr/local/varnish/config/default.vcl
    Debug: Version: varnish-6.2.0 revision b14a3d38dbe918ad50d3838b11aa596f42179b54
    Debug: Platform: Linux,4.19.90-2012.4.0.0053.oe1.aarch64,aarch64,-jnone,-smalloc,-sdefault,-hcritbit
    Debug: Child (30634) Started

    For the description of Varnish startup parameters, see Table Varnish startup parameter description.
    Parameter Description

    -a address:port : Indicates Varnish’s HTTP monitoring address and port, where the IP defaults to this machine.

    -T address:port : Set Varnish’s Telnet management address and port.

    -s : Specifies the storage method of Varnish cache, here in the form of malloc, a total of 10GB of memory space is allocated.

    -f : Specify Varnish configuration file location.

  4. Visit this machine to see the test page of the backend service.
    curl http://localhost:80

    ...
       <div class="content-middle">
        This page is used to test the proper operation of the Apache HTTP server after it has been installed. If you can read this page, it means that the Apache HTTP server installed at this site is working properly.
       </div>
       <hr>
    
       <div class="content-columns">
        <div class="content-column-left">
         <h2>If you are a member of the general public:</h2>
    
         The fact that you are seeing this page indicates that the website you just visited is either experiencing problems, or is undergoing routine maintenance.
    
         If you would like to let the administrators of this website know that you've seen this page instead of the page you expected, you should send them e-mail. In general, mail sent to the name "webmaster" and directed to the website's domain should reach the appropriate person.
    
         For example, if you experienced problems while visiting www.example.com, you should send e-mail to "[email protected]".
    
         For information on openEuler Linux, please visit the <a href="#" class="white">openEuler, Inc. website</a>. The ation for openEuler Linux is <a href="#" class="white">available on the openEuler, Inc. website</a>.
     
    ...

    illustrate:

    • If you need to stop Varnish, use the following command, which does not need to be executed during business operation.

    pkill varnish

    • Uninstall Varnish, and check.

    Uninstall Varnish installed from source.
    rm -rf /usr/local/varnish/

Related Links:

  1. openEuler official website: www.openeuler.org/
  2. OS Migration Zone:https://www.openeuler.org/zh/…
  3. openEuler compatibility list:https://www.openeuler.org/zh/…
  4. openEuler migration guide:https://www.openeuler.org/zh/…