从源代码编译Varnish

如果您的系统没有可用的二进制程序包,或者您出于其他原因想要从源代码编译Varnish,请执行以下步骤:

掌握消息来源

下载相应的发行版tarball,您可以在https://varnish-cache.org/releases/上找到。

或者,如果您想黑进Varnish,您应该通过执行以下操作来克隆我们的git存储库。

git clone https://github.com/varnishcache/varnish-cache

在FreeBSD上构建依赖项

要获得从源代码生成Varnish所需的依赖项,您可以执行以下操作:

pkg install automake pkgconf py36-sphinx py36-docutils pcre2 libtool

还可以选择运行所有测试用例::

pkg install haproxy nghttp2 vttest

或者,如果您想要从源代码构建:

cd /usr/ports/www/varnish6
make depends clean

然后继续 Compiling Varnish

在Debian/Ubuntu上构建依赖项

为了从源代码构建Varnish,您需要安装许多包。在Debian或Ubuntu系统上,使用以下命令安装它们(替换 sudo apt-get install 如有需要):

sudo apt-get install \
    make \
    automake \
    autotools-dev \
    libedit-dev \
    libjemalloc-dev \
    libncurses-dev \
    libpcre2-dev \
    libtool \
    pkg-config \
    python3-docutils \
    python3-sphinx \
    cpio

要重建SVG文件,请执行以下操作:

sudo apt-get install graphviz

建议,特别是如果您计划构建自定义vmod::

sudo apt-get install autoconf-archive

(可选)要从存储库中提取:

sudo apt-get install git

然后继续 Compiling Varnish

在Red Hat/CentOS上构建依赖项

在以下Shell命令中,替换 sudo yum install 如果需要的话。

安装狮身人面像

  • 在Red Hat/CentOS 8上,默认存储库中不包括Shinx,因此执行以下步骤以从PowerTools存储库中将其包括在内:

    sudo dnf install -y 'dnf-command(config-manager)'
    sudo yum config-manager --set-enabled powertools
    sudo yum install -y diffutils python3-sphinx
    
  • 在Red Hat/CentOS<=7上,安装Shinx::

    sudo yum install -y python-sphinx
    

以下步骤应完成所需程序包的安装:

yum install -y \
      make \
      autoconf \
      automake \
      jemalloc-devel \
      libedit-devel \
      libtool \
      libunwind-devel \
      ncurses-devel \
      pcre2-devel \
      pkgconfig \
      python3-docutils \
      cpio

要重建SVG文件,请执行以下操作:

yum install graphviz

(可选)要从存储库中提取:

yum install git

然后继续 Compiling Varnish

在MacOS上构建依赖项

要在MacOS上编译Varnish,这些步骤应该安装所需的依赖项:

  • 安装 xcode 通过App Store

  • 通过以下方式安装依赖项 brew **

    brew install \
        autoconf \
        automake \
        pkg-config \
        libtool \
        docutils \
        sphinx-doc
    
  • 按照安装程序的建议将狮身人面像添加到PATH::

    PATH="/usr/local/opt/sphinx-doc/bin:$PATH"
    

然后继续 Compiling Varnish

在阿尔卑斯Linux上构建依赖项

从ALPINE 3开始,这些步骤应安装所需的依赖项:

  • 添加 Alpine Community Repository

  • 安装依赖项::

    apk add -q \
        autoconf \
        automake \
        build-base \
        ca-certificates \
        cpio \
        gzip \
        libedit-dev \
        libtool \
        libunwind-dev \
        linux-headers \
        pcre2-dev \
        py-docutils \
        py3-sphinx \
        tar \
        sudo
    

要重建SVG文件,请执行以下操作:

apk add -q graphviz

(可选)要从存储库中提取:

apk add -q git

然后继续 Compiling Varnish ,使用 --with-unwind configure 选择。

在SmartOS区域上构建依赖项

从SmartOS pkgsrc 2019Q4开始,安装以下程序包:

pkgin in autoconf automake editline libtool ncurses \
         pcre2 python37 py37-sphinx py37-docutils gmake gcc8 pkg-config

Note: 您可能需要添加 /opt/local/gcc8/binPATH 为了拥有 gcc 可用。

要重建SVG文件,请执行以下操作:

pkgin in graphviz

(可选)要从存储库中提取:

pkgin in git

在Solaris和其他Solaris操作系统上构建

与GCC一起建设应该是直截了当的,只要安装了上述要求。

按照惯例,可以考虑将Varnish安装在 /opt/local 使用::

./configure \
        --prefix=/opt/local \
        --mandir=/opt/local/man

或者,使用Solaris Studio 12.4构建时应考虑以下建议:

  • 拥有GNU nm 在……里面 $PATH 在Solaris之前 nm

  • 为以下项提供编译器标志 configure 以包括安装依赖项的路径。示例 /opt/local **

    ./configure \
            --prefix=/opt/local \
            --mandir=/opt/local/man \
            CPPFLAGS="-I/opt/local/include" \
            CFLAGS="-m64" \
            LDFLAGS="-L/opt/local/lib -R/opt/local/lib"
    

编译Varnish

配置将需要满足上述依赖项。一旦该问题得到解决::

cd varnish-cache
sh autogen.sh
sh configure
make

这个 configure 脚本需要一些参数,但现在您很可能会忘记这一点,Varnish中的几乎所有内容都可以通过运行时参数进行调整。

在安装之前,您可能想要运行测试套件,在运行时泡一杯茶,这通常需要几分钟:

make check

如果一两次测试失败,也不用担心。有些测试对时间有点太敏感(请告诉我们哪种测试,这样我们就可以解决它们)。然而,如果它们中的许多都失败了,特别是如果 b00000.vtc 测试失败,有些地方出了严重的问题。如果不解决这个问题,你将一事无成。

正在安装

最后,对一颗勇敢的心的真正考验: sudo make install

Varnish现在将安装在 /usr/local 。这个 varnishd 二进制是流行的 /usr/local/sbin/varnishd 。要确保找到最新共享库的必要链接和缓存,请运行 sudo ldconfig