介绍
简要介绍
Varnish是一款高性能且开源的反向代理服务器和HTTP加速器,与传统的缓存服务器相比,Varnish具备性能更高、速度更快、治理更加不便等诸多长处,很多大型的网站都开始尝试应用Varnish来替换Squid,这些都促成Varnish迅速倒退起来。
开发语言:C++
一句话形容:反向代理服务器和HTTP加速器
倡议的版本
倡议应用版本为“Varnish 6.2.0”。
环境要求
硬件要求
硬件要求如表1所示。
表1 硬件要求
我的项目 | 阐明 |
---|---|
服务器 | TaiShan 200服务器(型号2280) |
CPU | 鲲鹏920 5250处理器 |
磁盘分区 | 对磁盘分区无要求 |
操作系统要求
操作系统要求如表2所示。
表2 操作系统要求
我的项目 | 版本 | 版本查看命令 |
---|---|---|
openEuler | 20.03 LTS SP1 | cat /etc/openEuler-release |
Kernel | 4.19.90 | uname -r |
配置编译环境
配置Yum源
阐明:
如果组网环境处于外网受限状况下,服务器yum命令无奈通过外界获取依赖包时,可参考本节内容进行本地源配置。
- 将操作系统镜像文件openEuler-20.03-LTS-SP1-everything-aarch64-dvd.iso文件拷贝到每台服务器的“/root”目录下。
镜像文件挂载。
a. 将“/root”目录下的openEuler操作系统对应iso文件挂载到“/mnt”目录下。mount /root/openEuler-20.03-LTS-SP1-everything-aarch64-dvd.iso /mnt
阐明:
该操作单次失效,重启后生效。若须要配置开机启动主动挂载镜像(可选),可参考上面步骤。- 关上fstab文件。
vi /etc/fstab
- 编辑fstab文件,在文件开端增加如下信息:
/root/openEuler-20.03-LTS-SP1-everything-aarch64-dvd.iso /mnt iso9660 loop 0 0
- 保留并退出fstab文件。
- 关上fstab文件。
增加本地源文件。
a. 进入“/etc/yum.repos.d”目录。cd /etc/yum.repos.d
阐明:
此时,倡议将此目录下的*.repo文件移到任意其余备份目录下。
b. 创立local.repo文件。- 关上local.repo文件。
vi local.repo
编辑local.repo文件,在local.repo文件中增加如下内容:
[local]name=local.repobaseurl=file:///mntenabled=1gpgcheck=0
阐明:
其中,baseurl中file门路为镜像挂载门路,与镜像文件挂载中的目录“/mnt” 对应。- 保留并退出local.repo文件。
- 关上local.repo文件。
失效本地源。
yum clean allyum makecacheyum list
装置依赖包
下载并装置依赖包
装置所需依赖。
yum install -y autoconf automake jemalloc-devel libedit-devel libtool ncurses-devel pcre-devel pkgconfig python-docutils python-sphinx graphviz httpd
查看Python3版本
[[email protected]]# python3 --versionPython 3.7.9
装置
装置形式介绍
本文将介绍源码编译装置形式
源码编译装置
获取源码
- 在本地浏览器下载Varnish源码。
下载地址:https://varnish-cache.org/_do... - 将源码复制至服务器“/home”目录。
阐明:
若服务器能够拜访网络,则能够间接在服务器上应用wget命令下载源码。
编译和装置
- 进入“home”目录。
cd /home/
- 解压源码包。
tar -zxvf varnish-6.2.0.tgz
- 进入“varnish-6.2.0”目录。
cd /home/varnish-6.2.0/
- 执行主动编译。
sh autogen.sh
查看依赖。
./configure --prefix=/usr/local/varnish
[[email protected] varnish-6.2.0]# ./configure --prefix=/usr/local/varnishchecking for gcc... gccchecking whether the C compiler works... yeschecking for C compiler default output file name... a.outchecking for suffix of executables... checking whether we are cross compiling... nochecking for suffix of files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yes
阐明:
--prefix=PATH:指定Varnish的装置目录。编译装置Varnish。
make && make install
[[email protected] varnish-6.2.0]# make && make installmake all-recursivemake[1]: Entering directory '/home/varnish-6.2.0'Making all in includemake[2]: Entering directory '/home/varnish-6.2.0/include'make all-ammake[3]: Entering directory '/home/varnish-6.2.0/include'
配置文件
- 在Varnish装置门路中创立配置文件所需的文件夹。
cd /usr/local/varnish && mkdir config
- 复制配置文件到“config”中。
cp /usr/local/varnish/share/doc/varnish/example.vcl /usr/local/varnish/config/default.vcl
运行与验证
以本机作为Varnish后端对象为例,运行和验证Varnish。
批改后端地址端口用于反向代理测试。
若需配置缓存策略,请从官网获取最新的Varnish Book)。此处配置本机作为后端对象,端口默认80。a. 关上配置文件。
vi /usr/local/varnish/config/default.vcl
b. 配置如下内容后,保留并退出。
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 {}
- 启动后端对象的HTTP服务。
systemctl start httpd
启动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.vclDebug: Version: varnish-6.2.0 revision b14a3d38dbe918ad50d3838b11aa596f42179b54Debug: Platform: Linux,4.19.90-2012.4.0.0053.oe1.aarch64,aarch64,-jnone,-smalloc,-sdefault,-hcritbitDebug: Child (30634) Started
Varnish启动参数阐明见表 Varnish启动参数阐明。
参数 : 阐明-a address:port : 示意Varnish对HTTP的监测地址及其端口, 此处IP默认为本机。
-T address:port : 设定Varnish的Telnet治理地址及其端口。
-s : 指定Varnish缓存寄存的形式,此处采纳malloc的模式,总共调配10GB内存空间。
-f : 指定Varnish的配置文件地位。
拜访本机即可看到后端服务的测试页面。
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>. ...
阐明:
- 若须要进行Varnish,则应用如下命令,业务运行中不须要执行该命令。
pkill varnish
- 卸载Varnish,并查问。
卸载源码形式装置的Varnish。
rm -rf /usr/local/varnish/
相干链接:
- openEuler官网:www.openeuler.org/
- OS迁徙专区: https://www.openeuler.org/zh/...
- openEuler兼容性列表:https://www.openeuler.org/zh/...
- openEuler迁徙指南:https://www.openeuler.org/zh/...