本人对varnish也是新手,这里记录一下安装步骤!

环境:centos6.6

varnish安装包下载:wget https://repo.varnish-cache.org/source/varnish-3.0.7.tar.gz

先上我的拓扑图 (基础拓扑为LVSDR环境)  LVS不在这里讲解

安装

yum -y install gcc gcc-c++ make autoconf automake
yum -y install automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig readline-devel
tar -zxf varnish-3.0.7.tar.gz
cd varnish-3.0.7
./configure --prefix=/usr/local/varnish
make;make install

拷贝文件到系统

cp redhat/varnish.initrc /etc/init.d/varnish
cp redhat/varnish.sysconfig /etc/sysconfig/varnish
cp redhat/varnish_reload_vcl /usr/local/varnish/bin

修改varnish配置文件

vim /etc/sysconfig/varnish

修改为如下内容 (里面有许多varnish的性能配置)

VARNISH_VCL_CONF=/usr/local/varnish/etc/varnish/default.vcl

VARNISH_LISTEN_PORT=80

VARNISH_SECRET_FILE=/usr/local/varnish/etc/varnish/secret

vim /etc/init.d/varnish

pidfile=/var/run/varnish.pid
exec="/usr/local/varnish/sbin/varnishd"
reload_exec="/usr/local/varnish/bin/varnish_reload_vcl"
# Done parsing, set up command
VARNISHADM="/usr/local/varnish/bin/varnishadm $secret -T $VARNISH_ADMIN_LISTEN_ADDRESS:$VARNISH_ADMIN_LISTEN_PORT"

注:也可以将/usr/local/varnish/bin添加到系统的PATH中,这样就不需要编辑varnish_reload_vcl

生成varnish管理秘钥:

/usr/bin/uuidgen > /usr/local/varnish/etc/varnish/secret
chmod 644 /usr/local/varnish/etc/varnish/secret

VCL配置(对应拓扑图)

vim /usr/local/varnish/etc/varnish/default.vcl

backend web1 {
.host = "192.168.0.38";
.port = "80";
.connect_timeout = 1s;
.first_byte_timeout = 5s;
.between_bytes_timeout = 2s;
} backend web2 {
.host = "192.168.0.162";
.port = "80";
.connect_timeout = 1s;
.first_byte_timeout = 5s;
.between_bytes_timeout = 2s;
} director syw_web random {
{ .backend = web1; .weight =2; }
{ .backend = web2; .weight =2; } } #clean cache
acl purge {
"localhost";
"127.0.0.1";
"192.168.0.162";
"192.168.0.167";
} sub vcl_recv {
if (req.http.host ~ "^192.168.0.193"){
set req.backend = syw_web;} if (req.request == "PURGE") {
if (!client.ip ~purge) {
error 405 "Not Allowed";
}
return(lookup); #find localhost cache
} if (req.request == "GET" && req.url ~ "\.(png|swf|txt|png|gif|jpg|css|js|htm|html)$") {
unset req.http.cookie;
} if (req.url ~ "^/images") {
unset req.http.cookie;
} #if (req.http.Cache-Control ~ "(no-cache|max-age=0)"){
# purge_url(req.url);
#}
# return (lookup); #获取客户端ip
# if (req.restarts == 0) {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
# }
}
检查VCL配置是否正确:
/etc/init.d/varnish configtest

/usr/local/varnish/sbin/varnishd -C -f /usr/local/varnish/etc/varnish/fdfs.vcl #启动varnish: service varnish start #查看varnish状态: /etc/init.d/varnish status # 动态加载VCL配置: /etc/init.d/varnish reload # 停止varnish: /etc/init.d/varnish stop

先就说这么多吧

更多精华请参考

http://www.it165.net/admin/html/201405/2999.html

http://www.51itstudy.com/30132.html

Varnish安装使用(初学)的更多相关文章

  1. 高性能HTTP加速器Varnish安装与配置

    导读 Varnish是一款高性能且开源的反向代理服务器和HTTP加速器,它采用了全新的软件体系结构,和现在的硬件体系配合紧密.下面就由我给大家简单说说他的安装与配置. 安装 安装pcre 如果没有安装 ...

  2. varnish安装

    安装pcrevarnish 依赖pcre进行url正则匹配. cd pcre-8.12./configure --prefix=/usr/local/make&&make instal ...

  3. 高性能HTTP加速器Varnish安装与配置(包含常见错误)

    Varnish是一款高性能的开源HTTP加速器.挪威最大的在线报纸Verdens Gang使用3台Varnish取代了原来的12台Squid,性能竟然比曾经更好.Varnish 的作者Poul-Hen ...

  4. varnish安装和配置

    实验环境:CentOS7 Varnish是高性能开源的反向代理服务器和HTTP缓存服务器. #varnish服务器:172.16.252.142 [root@varnish localhost]#yu ...

  5. Centos7.4 小白式安装(初学)

    虚拟机安装Centos7.4系统 适用人群(初学者) 下载Centos7.4镜像 https://pan.baidu.com/s/1NtjfdHV3OWAvfDj5vrR7HQ  提取码:hzzw 虚 ...

  6. Varnish快速安装及测试

    实验环境: slave-147:   192.168.75.147 slave-148:    192.168.75.148 两台机器均已关闭selinux,关闭iptables. varnish部署 ...

  7. Varnish 6.2.2 的介绍与安装

    一.简介 Varnish 是一款高性能且开源的反向代理服务器和 HTTP 加速器,其采用全新的软件体系机构,和现在的硬件体系紧密配合,与传统的 Squid 相比,Varnish 具有性能更高.速度更快 ...

  8. 安装Varnish 及遇到的坑

      转自:http://ixdba.blog.51cto.com/2895551/682555   一.安装Varnish Varnish的安装非常简单,下面逐步介绍: 1.安装前的准备  Varni ...

  9. Varnish – 高性能http加速器

    Varnish是一款高性能且开源的反向代理服务器和http加速器.与传统的Squid相比,Varnish具有性能更高.速度更快.管理更方便 等诸多优点.作者Poul-Henning Kamp是Free ...

随机推荐

  1. loadrunner选择执行哪个Action

    深圳湖北籍软件测试群 275212937

  2. 程序员必备的代码审查(Code Review)清单【转载】

    在我们关于高效代码审查的博文中,我们建议使用一个检查清单.在代码审查中,检查清单是一个非常好的工具——它们保证了审查可以在你的团队中始终如一的进行.它们也是一种保证常见问题能够被发现并被解决的便利方式 ...

  3. Tactical Multiple Defense System 二分图

    This problem is about a war game between two countries. To protect a base, your country built a defe ...

  4. html5大纲

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. BZOJ3084 : [Algorithmic Engagements 2011]The Shortest Period

    枚举答案长度$L$,设$A$和$B$分别为第一个循环节和反串的第一个循环节. 1.坏点不在$A$,那么可以暴力匹配检验. 2.坏点不在$B$,那么把串翻转后不在$A$中,转化为1. 3.坏点在$A$和 ...

  6. 使用spring rest插入数据库时发生了 前言中不允许有内容 错误

    该错误一般是编码带来的问题,比如在请求post的时候,使用了application/x-www-form-urlencoded的content type 那么请求传过来的string则需要用urlDe ...

  7. 微软曝光眼球追踪新专利,未来或将可以使用眼球控制HoloLens

    想要在增强现实(AR)和虚拟现实(VR)中获得感官能力,计算机的配合非常重要.如何能够更好的追踪我们所感知的,计算机判断用户目光所向的能力就必须进一步提高.根据微软新曝光的专利,可能已经有一个解决方案 ...

  8. 再探CSS 中 class 命名规范

    一直以来我的CSS 的 class命名都是比较随意,有时采用驼峰式.有时采用下划线,好像没有什么统一的标准,想到什么英文单词就拿过来用,这对于自己瞎写的小项目无伤大雅,遇到冲突的问题可稍加调整改变即可 ...

  9. 20145308刘昊阳 《Java程序设计》第4周学习总结

    20145308刘昊阳 <Java程序设计>第4周学习总结 教材学习内容总结 第六章 继承与多态 6.1 何谓继承 继承:面向对象中,为避免多个类间重复定义共同行为使用 把相同代码提升为父 ...

  10. 20145308刘昊阳 《Java程序设计》第2周学习总结

    20145308刘昊阳 <Java程序设计>第2周学习总结 教材学习内容总结 第三章 基础语法 3.1 类型.变量与运算符 类型 基本类型 整数(short/int/long) short ...