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. ...
随机推荐
- linux的五种IO模型
概念: 同步.异步.阻塞.非阻塞的概念 同步:所谓同步,发起一个功能调用的时候,在没有得到结果之前,该调用不返回,也就是必须一件事一件事的做,等前一件做完了,才能做下一件. 提交请求->等待服务 ...
- 记录一个基于Java的利用快排切分来实现快排TopK问题的代码模板
使用快排切分实现快排和TopK问题的解题模板 import java.util.Arrays; public class TestDemo { public static void main(Stri ...
- 小程序开发-使用npm包
微信小程序引用npm包 微信小程序官方支持使用npm包,地址为 https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html 实 ...
- C012:颠倒显示两位数
代码: #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { int original; do{ printf(&q ...
- 经典SQL问题:Top 10%
学生表: create table hy_student( id number(4,0) primary key, name nvarchar2(20) not null, score number( ...
- 使用 Promise 实现任务队列发送请求,实现最大请求数目限制
核心 设置最大请求数量,当前请求数量,待执行队列 调用时,创建一个新任务,然后判断是否达到最大请求数量,若达到则将任务追加到待执行队列,否则,则直接执行该任务.并返回Promise 创建任务时,需要返 ...
- Django进入监听端口就自动打开指定页面,无需导航栏手动添加(Django六)
在我们进入监听端口时画面如下:而因为在urls.py中写过如下语句 我们在监听端口后加上/login就会跳转到login.html页面,如下图 那么如何一打开监听端口就可以走动跳转到login.htm ...
- 反射之hasattr() getattr() setattr() 函数
Python的hasattr() getattr() setattr() 函数使用方法详解 hasattr(object, name)判断object中有没有一个name字符串对应的方法或属性,返回B ...
- 掌控安全sql注入靶场pass-05
1.判断注入点 1 and 1=1 1 and 1=2 考虑存在布尔盲注 布尔盲注解释 当不能像前面那样直接在网页中显示我们要的数据时就需要用到盲注,来得到数据库之类的名字.基于布尔的盲注就是通过判断 ...
- python3 for
当range中只有一个参数时,此参数表示终点,但不包括.(从0开始) 当range中有两个参数时,分别表示起点和终点.(左闭但不包括终点) 当range中有三个参数时,分别表示起点和终点,和步长,意思 ...