Varnish 6.2.2 的介绍与安装
一、简介
Varnish 是一款高性能且开源的反向代理服务器和 HTTP 加速器,其采用全新的软件体系机构,和现在的硬件体系紧密配合,与传统的 Squid 相比,Varnish 具有性能更高、速度更快、管理更加方便等诸多优点。
二、Varnish 与 Squid 的对比
相同点
- 都是一个反向代理服务器。
- 都是开源软件。
Varnish的优势
- Varnish 的稳定性很高。两者在完成相同负荷的工作时,Squid服务器发生故障的几率要高于Varnish,因为使用Squid要经常重启。
- Varnish 访问速度更快。因为采用了“Visual Page Cache”技术,所有缓存数据都直接从内存读取,而squid是从硬盘读取,因而Varnish在访问速度方面会更快。
- Varnish 可以支持更多的并发连接。因为Varnish的TCP连接释放要比Squid快,因而在高并发连接情况下可以支持更多TCP连接。
- Varnish 可以通过管理端口,使用正则表达式批量的清除部分缓存,而Squid是做不到的。
- Squid属于是单进程使用单核CPU,但Varnish是通过fork形式打开多进程来做处理,所以可以合理的使用所有核来处理相应的请求。
Varnish的劣势
- Varnish进程一旦Hang、Crash或者重启,缓存数据都会从内存中完全释放,此时所有请求都会发送到后端服务器,在高并发情况下,会给后端服务器造成很大压力。
- 在Varnish使用中如果单个url的请求通过HA/F5等负载均衡,则每次请求落在不同的varnish服务器中,造成请求都会被穿透到后端;而且同样的请求在多台服务器上缓存,也会造成varnish的缓存的资源浪费,造成性能下降。
Varnish劣势的解决方案
- 针对劣势一:在访问量很大的情况下推荐使用varnish的内存缓存方式启动,而且后面需要跟多台squid服务器。主要为了防止前面的varnish服 务、服务器被重启的情况下,大量请求穿透varnish,这样squid可以就担当第二层CACHE,而且也弥补了varnish缓存在内存中重启都会释 、放的问题。
- 针对劣势二:可以在负载均衡上做url哈希,让单个url请求固定请求到一台varnish服务器上。
三、Varnish 6.2.2 的安装
Varnish 的官方链接:https://varnish-cache.org/
Varnish 的部署文档:https://varnish-cache.org/docs/index.html#
注意:Centos7默认yum安装版本为4.0.5,网上文档支持比较多;最新版本为6.3.0,较4.x老版本变化较大,需要参照官方文档进行学习
1、Varnish 安装前的准备
Varnish 安装环境的准备:
- 主机名:Varnish
- 操作系统:CentOS Linux release 7.6.1810 (Core)
- IP地址:192.168.1.194
[root@varnish ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@varnish ~]# mkdir -p /data/varnish/{etc,log}
[root@varnish ~]# ll /data/varnish/
total 0
drwxr-xr-x. 2 varnish varnish 6 Nov 25 05:45 etc
drwxr-xr-x. 2 varnish varnish 6 Nov 25 05:45 log
2、Varnish 安装前的介绍
Varnish 是一个开源软件,可以选择安全二进制包,或者从源码定制编译安装。
在相关操作系统上,可以使用系统自带的包管理器来安装,常见的用例:
FreeBSD:
varnish 5.x 以前的安装方式:
源码安装:cd /usr/ports/varnish && make install clean
二进制包安装: pkg_add -r varnish
varnish 5.x 以后的安装方式:
源码安装:cd /usr/ports/www/varnish4 && make install clean
二进制包安装: pkg_add -r varnish4
CentOS/RedHat:
# 编译安装时,所需安装的依赖包:
yum install autoconf automake jemalloc-devel libedit-devel libtool ncurses-devel pcre-devel pkgconfig python-docutils python-sphinx
Debian/Ubuntu:
Varnish 已经发布了 Debian 和 Ubuntu 的软件包,只需要使用一条命令就可以安装。(注意:这样安装可能不是最新的版本)
apt-get install varnish
Other Systems:
建议:最好使用源码安装
3、获取 Varnish 软件
Varnish 的官网网址:http://varnish-cache.org/
在官网有 Varnish 的最新说明文档及版本升级记录,也可以找到 Varnish 的 SourceForge 的下载链接。
目前,Varnish 的最新版本是 Varnish 6.3.1,此处,以 安全版本 Varnish 6.2.2 为例。
# 获取 Varnish 6.2.2 软件
[root@varnish ~]# mkdir /soft
[root@varnish ~]# cd /soft/
[root@varnish soft]# wget http://varnish-cache.org/_downloads/varnish-6.2.2.tgz
4、开始安装 Varnish
方法1:二进制包的rpm安装方式
方法2:源码包的编译安装方式
安装基础包:
yum install \
make \
autoconf \
automake \
jemalloc-devel \
libedit-devel \
libtool \
ncurses-devel \
pcre-devel \
pkgconfig \
python3-docutils \
python3-sphinx
# 开始解压安装 Varnish
[root@varnish soft]# tar xzvf varnish-6.2.2.tgz
[root@varnish soft]# cd varnish-6.2.2
[root@varnish varnish-6.2.2]# ./configure --prefix=/data/varnish
[root@varnish varnish-6.2.2]# make && make install [root@varnish varnish-6.2.2]# ll /data/varnish/
total 0
drwxr-xr-x. 2 root root 136 Nov 25 06:10 bin
drwxr-xr-x. 2 root root 6 Nov 25 06:20 etc
drwxr-xr-x. 3 root root 21 Nov 25 06:10 include
drwxr-xr-x. 4 root root 142 Nov 25 06:10 lib
drwxr-xr-x. 2 root root 6 Nov 25 06:20 log
drwxr-xr-x. 2 root root 22 Nov 25 06:10 sbin
drwxr-xr-x. 6 root root 58 Nov 25 06:10 share
drwxr-xr-x. 3 root root 21 Nov 25 06:10 var # 配置环境变量
[root@varnish ~]# echo 'export PATH=$PATH:/data/varnish/sbin:/data/varnish/bin' >> /etc/profile
[root@varnish ~]# source /etc/profile
[root@varnish ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/data/varnish/sbin:/data/varnish/bin # 查看 Varnish 的版本
[root@varnish varnish-6.2.2]# varnishd -V
varnishd (varnish-6.2.2 revision 3ed1506895ecaddb91f658bee11742f0b0b982b5)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2019 Varnish Software AS
# 拷贝配置文件
[root@varnish varnish-6.2.2]# cp /data/varnish/share/doc/varnish/example.vcl /data/varnish/etc/default.vcl
[root@varnish varnish-6.2.2]# cat /data/varnish/etc/default.vcl
#
# This is an example VCL file for Varnish.
#
# It does not do anything by default, delegating control to the
# builtin VCL. The builtin VCL is called when there is no explicit
# return statement.
#
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
# and https://www.varnish-cache.org/trac/wiki/VCLExamples for more examples. # Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0; # Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "8080";
} sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't need,
# rewriting the request, etc.
} sub vcl_backend_response {
# Happens after we have read the response headers from the backend.
#
# Here you clean the response headers, removing silly Set-Cookie headers
# and other mistakes your backend does.
} sub vcl_deliver {
# Happens when we have all the pieces we need, and are about to send the
# response to the client.
#
# You can do accounting or modifying the final object here.
}
Varnish 6.2.2 的介绍与安装的更多相关文章
- 从零自学Hadoop(19):HBase介绍及安装
阅读目录 序 介绍 安装 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceLink 序 上一篇, ...
- 从零自学Hadoop(14):Hive介绍及安装
阅读目录 序 介绍 安装 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceLink 序 本系列已 ...
- Python之路-python(mysql介绍和安装、pymysql、ORM sqlachemy)
本节内容 1.数据库介绍 2.mysql管理 3.mysql数据类型 4.常用mysql命令 创建数据库 外键 增删改查表 5.事务 6.索引 7.python 操作mysql 8.ORM sqlac ...
- Bash on Windows 抢鲜测试 -- 介绍及安装
前言 微软在上周的Windows BUILD大会上宣布,WIN10将引入原生Bash,并将很快在技术预览版中推出. 如此一来,windows的命令行工具就不再只有cmd和powershell了,我们可 ...
- Tyk API网关介绍及安装说明
Tyk API网关介绍及安装说明 Tyk是一个开源的轻量级API网关程序. 什么是API网关 API网关是一个各类不同API的前置服务器.API网关封装了系统内部架构,对外提供统一服务.此外还可以实现 ...
- Python介绍、安装、使用
Python介绍.安装.使用 搬运工:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Python语言介绍 说到Python语言,就不得不说一下它的创始人Guido van Rossu ...
- Redis介绍以及安装(Linux)
Redis介绍以及安装(Linux) redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统.和Memcached类似,但很大程度补偿了memcached的不足,它支持存储的 ...
- 自动化运维工具之 Ansible 介绍及安装使用
一.初识Ansible 介绍: Absible 使用 模块(Modules)来定义配置任务.模块可以用标准脚本语言(Python,Bash,Ruby,等等)编写,这是一个很好的做法,使每个模块幂等.A ...
- 【兄弟连ThinkPHP】1、介绍和安装
琢磨了好几天的ThinkPHP了,兄弟连的视频真心不错,下面是记得一些要点,只做备忘,有兴趣的朋友请去百度兄弟连. ## ThinkPHP 3 介绍及安装#讲师:赵桐正微博:http://weibo. ...
随机推荐
- org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed(转)
xml文件不能被正确解析/The processing instruction target matching "[xX][mM][lL]" is not allowed. The ...
- web自动化多次打开浏览器嫌烦?打开一次浏览器,pytest有个招
最近系统前端组件做了更新,我就把之前做的web自动化的代码做了一些修改,顺便优化了下用例,只保留少量的测试用例了,大头还是在接口自动化上.然后发现关于pytest的还有一个点应该比较常用,这里再介绍一 ...
- Selenium学习整理(Python)
1 准备软件 Selenium IDE firebug-2.0.19.xpi firepath-0.9.7-fx.xpi Firefox_46.0.1.5966_setup.exe 由于火狐浏览器高版 ...
- [BUUOJ记录] [CISCN 2019 初赛]Love Math & [NESTCTF 2019]Love Math 2
主要考察利用已有函数构造危险函数绕过,实现RCE. 进入题目给出源码: <?php error_reporting(0); //听说你很喜欢数学,不知道你是否爱它胜过爱flag if(!isse ...
- vue中饼状图的使用
图形构建子组件 <template> <div> <div id="myChart" :style="echartStyle"&g ...
- 下载安装gradle
1.登录官网:www.gradle.org,进入到下图的界面: 2.点击Install Gradle,跳转到下一个界面后: 3.下载 4.下载成功后,解压到任意位置,将路径添加到path路径下,选择我 ...
- jenkins安装和邮件配置
一.jenkins下载 Jenkins的下载地址是https://jenkins.io/download/,下载的时候可以选择各个版本的以及对应操作系统的版本,一般你下载的时候下载通用的.war文件即 ...
- md5命令
AIX 系统md5命令之csum #csum filename (默认使用md5算法) #csum -h SHA1 filename (使用sha1算法)Linux系统命令之md5sum 1. 背景 ...
- Python爬虫开发者工具介绍
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理. chrome 开发者工具 当我们爬取不同的网站时,每个网站页面的实现方式各不相同,我们需要对 ...
- java 泛型学习随笔
对于java 泛型 编译时处理,运行时擦除的特点理解 对于编译时处理 在使用泛型相关的类或方法时,如果声明时的类型和具体使用时的类型不一致则直接会编译不通过 对于运行时擦除 当在运行时对两个相同类型但 ...