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命令无法通过外界获取依赖包时,可参考本节内容进行本地源配置。
mount /root/openEuler-20.03-LTS-SP1-everything-aarch64-dvd.iso /mntvi /etc/fstab/root/openEuler-20.03-LTS-SP1-everything-aarch64-dvd.iso /mnt iso9660 loop 0 0cd /etc/yum.repos.dvi local.repo[local]
name=local.repo
baseurl=file:///mnt
enabled=1
gpgcheck=0
yum clean all
yum makecache
yum list
下载并安装依赖包
yum install -y autoconf automake jemalloc-devel libedit-devel libtool ncurses-devel pcre-devel pkgconfig python-docutils python-sphinx graphviz httpd
[root@localhost]# python3 --version
Python 3.7.9
本文将介绍源码编译安装方式
cd /home/tar -zxvf varnish-6.2.0.tgzcd /home/varnish-6.2.0/sh autogen.sh./configure --prefix=/usr/local/varnish[root@localhost 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
说明:
–prefix=PATH:指定Varnish的安装目录。
make && make install[root@localhost 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'
cd /usr/local/varnish && mkdir configcp /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
[root@localhost ~]# /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
Varnish启动参数说明见表 Varnish启动参数说明。
参数 : 说明
-a address:port : 表示Varnish对HTTP的监测地址及其端口, 此处IP默认为本机。
-T address:port : 设定Varnish的Telnet管理地址及其端口。
-s : 指定Varnish缓存存放的方式,此处采用malloc的形式,总共分配10GB内存空间。
-f : 指定Varnish的配置文件位置。
curl http://localhost:80...
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.
If you are a member of the general public:
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 "webmaster@example.com".
For information on openEuler Linux, please visit the openEuler, Inc. website. The ation for openEuler Linux is available on the openEuler, Inc. website.
...
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
说明:
- 若需要停止Varnish,则使用如下命令,业务运行中不需要执行该命令。
pkill varnish - 卸载Varnish,并查询。
卸载源码方式安装的Varnish。
rm -rf /usr/local/varnish/
相关链接:
-
openEuler官网:www.openeuler.org/
-
OS迁移专区: https://www.openeuler.org/zh/migration/download/
-
openEuler兼容性列表:https://www.openeuler.org/zh/compatibility/
-
openEuler迁移指南:https://www.openeuler.org/zh/blog/2022-08-29/migration.html