varnish安装

系统centos7

ip 192.168.40.131

禁止透明大页
echo never > /sys/kernel/mm/transparent_hugepage/enabled 

减少最大堆栈大小
ulimit -s 256


安装nginx
yum list | grep ^nginx && yum -y install nginx*

mkdir /usr/share/nginx/html/hello
echo “hello world” > /usr/share/nginx/hello/index.html
systemctl start nginx

http://192.168.40.131/hello/


源码编译
wget https://varnish-cache.org/downloads/varnish-7.5.0.tgz
https://varnish-cache.org/docs/7.5/installation/install_source.html

tar -zxvf varnish-7.5.0.tgz

[root@racknerd-5cad50 ~]# cd varnish-7.5.0
[root@racknerd-5cad50 varnish-7.5.0]# ls
aclocal.m4  config.h.in   etc      m4                README.rst                    varnish.m4
autogen.sh  configure     include  Makefile.am       tools                         vmod
bin         configure.ac  INSTALL  Makefile.in       varnishapi.pc.in              vsc.am
build-aux   contrib       lib      man               varnishapi-uninstalled.pc.in  vtc.am
ChangeLog   doc           LICENSE  README.Packaging  varnish-legacy.m4             wflags.py

在 Red Hat / CentOS 8 上,sphinx 不包含在默认存储库中,因此请执行以下步骤以将其从 powertools 存储库中包含:
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 -y
从存储库中提取
yum install git -y


cd varnish-cache
sh autogen.sh
libtoolize: `build-aux/ltmain.sh' is newer: use `--force' to overwrite
libtoolize: `m4/libtool.m4' is newer: use `--force' to overwrite
libtoolize: `m4/ltoptions.m4' is newer: use `--force' to overwrite
libtoolize: `m4/ltversion.m4' is newer: use `--force' to overwrite

[root@host2 varnish-7.5.0]# autoreconf -fi
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `build-aux'.
libtoolize: copying file `build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'


[root@host2 varnish-7.5.0]# sh autogen.sh 
[root@host2 varnish-7.5.0]# sh configure



make      check
Testsuite summary for Varnish 7.5.0
============================================================================
# TOTAL: 1
# PASS:  0
# SKIP:  1
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
==========================================


sudo make install

/bin/sh /root/varnish-7.5.0/build-aux/install-sh -d -m 0755 /usr/local/var/varnish
/usr/bin/mkdir -p '/usr/local/share/aclocal'
/usr/bin/install -c -m 644 varnish.m4 varnish-legacy.m4 '/usr/local/share/aclocal'
/usr/bin/mkdir -p '/usr/local/lib/pkgconfig'
/usr/bin/install -c -m 644 varnishapi.pc '/usr/local/lib/pkgconfig'


[root@host2 bin]# which varnishd
/usr/local/sbin/varnishd

配置文件
cp -r ./share/doc/varnish/example.vcl  /etc/varnish/default.vcl

mkdir /etc/varnish
uuidgen > /etc/varnish/secret

cat /etc/varnish/default.vcl
# Default backend definition. Set this to point to your content server.
backend default {
    .host = "192.168.40.131";
    .port = "80";
}
启动
varnishd -f /etc/varnish/default.vcl -s malloc,1G -T 127.0.0.1:20000 -a 0.0.0.0:8080 -p thread_pool_min=50 -p thread_pool_max=1000 -P  /var/log/varnish.pid

启动2
varnishd -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,1G -T 127.0.0.1:20000 -a 0.0.0.0:8080 -p thread_pool_min=50 -p thread_pool_max=1000 -P  /var/log/varnish.pid
启动参数
-s:指定使用内存进行缓存,内存大小1G
-T:指定管理IP和端口
-a:指定访问IP和端口
-p:指定单个pool打开的最小thread和最大thread(pool数一般与CPU核数一致)
-P:pid进程文件

访问:
http://192.168.40.131:8080/hello/


查看日志
# varnishncsa
192.168.40.1 - - [12/May/2024:14:04:12 +0800] "GET http://192.168.40.131:8080/hello/ HTTP/1.1" 200 18 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
192.168.40.1 - - [12/May/2024:14:04:12 +0800] "GET http://192.168.40.131:8080/favicon.ico HTTP/1.1" 404 3650 "http://192.168.40.131:8080/hello/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"