热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Varnish3.0安装配置过程笔记

Varnish有centos下的rpm和ubuntu下的deb二进制包下载,但我选择的是源码编译安装先下载wgethttp://repo.varnish-cache.org/source/varnish-3.0.0.tar.gztar-xzvfvarnish-3.0.0.tar.gzyuminstallgccyumin

Varnish有centos下的rpm和ubuntu下的deb二进制包下载,但我选择的是源码编译安装

先下载 wget http://repo.varnish-cache.org/source/varnish-3.0.0.tar.gz

tar -xzvf varnish-3.0.0.tar.gz

 

yum install gcc

yum install gcc-c++ libstdc++-devel

yum install -y httpd-devel pcre perl pcre-devel zlib zlib-devel GeoIP GeoIP-devel

 

Varnish需要pcre支持,如果服务器没有安装pcre-devel会提示需要指定prce目录。
Centos服务器上使用yum install pcre-devel安装

 

解压varnish进行编译安装

cd varnish-3.0.0

./autogen.sh

./configure --prefix=/usr/local/varnish PKG_CONFIG_PATH=/usr/lib/pkgconfig
 

make

make install

安装成功后,安装的目录是

cd /usr/local/varnish/sbin

./varnishd -V

查看版本,看是否安装成功

测试varnish

先编辑配置文件

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

 

# This is a basic VCL configuration file for varnish.  See the vcl(7)
# man page for details on VCL syntax and semantics.
#
# Default backend definition.  Set this to point to your content
# server.
#
 backend default {
     .host = "192.168.88.156";
     .port = "80";
     ###下面三行为新加配
     .connect_timeout = 1s;
     .first_byte_timeout = 5s;
     .between_bytes_timeout = 2s;
 }
#
# Below is a commented-out copy of the default VCL logic.  If you
# redefine any of these subroutines, the built-in logic will be
# appended to your code.
 sub vcl_recv {
     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;
        }
     }
     if (req.request != "GET" &&
       req.request != "HEAD" &&
       req.request != "PUT" &&
       req.request != "POST" &&
       req.request != "TRACE" &&
       req.request != "OPTIONS" &&
       req.request != "DELETE") {
         /* Non-RFC2616 or CONNECT which is weird. */
         return (pipe);
     }
     if (req.request != "GET" && req.request != "HEAD") {
         /* We only deal with GET and HEAD by default */
         return (pass);
     }
     if (req.http.Authorization || req.http.COOKIE) {
         /* Not cacheable by default */
         return (pass);
     }
     return (lookup);
 }
#
 sub vcl_pipe {
#     # Note that only the first request to the backend will have
#     # X-Forwarded-For set.  If you use X-Forwarded-For and want to
#     # have it set for all requests, make sure to have:
#     # set bereq.http.connection = "close";
#     # here.  It is not set by default as it might break some broken web
#     # applications, like IIS with NTLM authentication.
     return (pipe);
 }
#
 sub vcl_pass {
     return (pass);
 }
#
 sub vcl_hash {
     hash_data(req.url);
     if (req.http.host) {
         hash_data(req.http.host);
     } else {
         hash_data(server.ip);
     }
     return (hash);
 }
#
 sub vcl_hit {
     return (deliver);
 }
#
 sub vcl_miss {
     return (fetch);
 }
#
 sub vcl_fetch {
     if (beresp.ttl <= 0s ||
         beresp.http.Set-COOKIE ||
         beresp.http.Vary == "*") {
                /*
                 * Mark as "Hit-For-Pass" for the next 2 minutes
                 */
                set beresp.ttl = 120 s;
                return (hit_for_pass);
     }
     return (deliver);
 }
#
 sub vcl_deliver {
     return (deliver);
 }
#
# sub vcl_error {
#     set obj.http.Content-Type = "text/html; charset=utf-8";
#     set obj.http.Retry-After = "5";
#     synthetic {"

#  #  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

#   
#     
#   
#   
#     Error "} + obj.status + " " + obj.response + {"
#     

"} + obj.response + {"


#     

Guru Meditation:


#     

XID: "} + req.xid + {"


#     

#     

Varnish cache server


#   

# "};
#     return (deliver);
# }
#
 sub vcl_init {
        return (ok);
 }
#
 sub vcl_fini {
        return (ok);
 }

 

/usr/local/varnish/sbin/varnishd -f /usr/local/varnish/etc/varnish/default.vcl -s malloc,1024m -T 127.0.0.1:200 -a 0.0.0.0:80

 

现在可以打开varnish了

http://192.168.88.1/    (开启varnish的端口号)

戴图显示,nginx 为177上运行的web服务器,出现了varnish字样,表示缓存架设成功,已正常工作了。


 

启动varnishncsa用来将Varnish访问日志写入日志文件:

/usr/local/varnish/bin/varnishncsa -n /var/vcache -w /var/logs/varnish.log &

配置开机自动启动Varnish

vi /etc/rc.local


  在末尾增加以下内容:

ulimit -SHn 51200
/usr/local/varnish/sbin/varnishd -n /var/vcache -f /usr/local/varnish/vcl.conf -a 0.0.0.0:80 -s file,/var/vcache/varnish_cache.data,1G -g www -u www -w 30000,51200,10 -T 127.0.0.1:3500 -p client_http11=on
/usr/local/varnish/bin/varnishncsa -n /var/vcache -w /var/logs/youvideo.log &

 优化Linux内核参数

vi /etc/sysctl.conf


  在末尾增加以下内容:

net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_synCOOKIEs = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000    65000


 查看Varnish服务器连接数与命中率
/usr/local/varnish/bin/varnishstat

 

配置启动脚本: 

mkdir /cache/varnish/V -p

vi /usr/local/varnish/sbin/start.sh

 

#!/bin/sh
#file:start.sh
date -u
/usr/local/varnish/sbin/varnishd -a 0.0.0.0:80  -s file,/cache/varnish/V,1024m  -f         /usr/local/varnish/etc/varnish/default.vcl  -p thread_pool_max=1500  -p thread_pools=5  -p listen_depth=512 

chmod 777 start.sh

运行:

/usr/local/varnish/sbin/start.sh


推荐阅读
  • Ubuntu 9.04中安装谷歌Chromium浏览器及使用体验[图文]
    nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ... [详细]
  • 成功安装Sabayon Linux在thinkpad X60上的经验分享
    本文分享了作者在国庆期间在thinkpad X60上成功安装Sabayon Linux的经验。通过修改CHOST和执行emerge命令,作者顺利完成了安装过程。Sabayon Linux是一个基于Gentoo Linux的发行版,可以将电脑快速转变为一个功能强大的系统。除了作为一个live DVD使用外,Sabayon Linux还可以被安装在硬盘上,方便用户使用。 ... [详细]
  • 本文介绍了在CentOS 7.x上进行端口映射配置的方法,通过修改内核和配置防火墙实现端口映射。作者分享了自己使用华为服务器进行端口映射的经验,发现网速比直连还快且稳定。详细的配置过程包括开启系统路由模式功能、设置IP地址伪装、设置端口映射等。同时,还介绍了如何监听本地端口的tcp请求,以及删除规则和开放的端口的方法。 ... [详细]
  • 在ubuntu服务器上安装vscode,但是目前使用的方法都无法成功。第一次安装经历:安装完anaconda后有自动安装vscode的选项,输入yes后,没有出现错误,但是在终端输 ... [详细]
  • MySQL语句大全:创建、授权、查询、修改等【MySQL】的使用方法详解
    本文详细介绍了MySQL语句的使用方法,包括创建用户、授权、查询、修改等操作。通过连接MySQL数据库,可以使用命令创建用户,并指定该用户在哪个主机上可以登录。同时,还可以设置用户的登录密码。通过本文,您可以全面了解MySQL语句的使用方法。 ... [详细]
  • 分享css中提升优先级属性!important的用法总结
    web前端|css教程css!importantweb前端-css教程本文分享css中提升优先级属性!important的用法总结微信门店展示源码,vscode如何管理站点,ubu ... [详细]
  • 本文介绍了在Web应用系统中,数据库性能是导致系统性能瓶颈最主要的原因之一,尤其是在大规模系统中,数据库集群已经成为必备的配置之一。文章详细介绍了主从数据库架构的好处和实验环境的搭建方法,包括主数据库的配置文件修改和设置需要同步的数据库等内容。MySQL的主从复制功能在国内外大型网站架构体系中被广泛采用,本文总结了作者在实际的Web项目中的实践经验。 ... [详细]
  • PHP组合工具以及开发所需的工具
    本文介绍了PHP开发中常用的组合工具和开发所需的工具。对于数据分析软件,包括Excel、hihidata、SPSS、SAS、MARLAB、Eview以及各种BI与报表工具等。同时还介绍了PHP开发所需的PHP MySQL Apache集成环境,包括推荐的AppServ等版本。 ... [详细]
  • 云原生应用最佳开发实践之十二原则(12factor)
    目录简介一、基准代码二、依赖三、配置四、后端配置五、构建、发布、运行六、进程七、端口绑定八、并发九、易处理十、开发与线上环境等价十一、日志十二、进程管理当 ... [详细]
  • 如何使用PLEX播放组播、抓取信号源以及设置路由器
    本文介绍了如何使用PLEX播放组播、抓取信号源以及设置路由器。通过使用xTeve软件和M3U源,用户可以在PLEX上实现直播功能,并且可以自动匹配EPG信息和定时录制节目。同时,本文还提供了从华为itv盒子提取组播地址的方法以及如何在ASUS固件路由器上设置IPTV。在使用PLEX之前,建议先使用VLC测试是否可以正常播放UDPXY转发的iptv流。最后,本文还介绍了docker版xTeve的设置方法。 ... [详细]
  • Linux下部署Symfoy2对app/cache和app/logs目录的权限设置,symfoy2logs
    php教程|php手册xml文件php教程-php手册Linux下部署Symfoy2对appcache和applogs目录的权限设置,symfoy2logs黑色记事本源码,vsco ... [详细]
  • ORACLE空间管理实验5:块管理之ASSM下高水位的影响
    数据库|mysql教程ORACLE,空间,管理,实验,ASSM,下高,水位,影响,数据库-mysql教程易语言黑客软件源码,vscode左侧搜索,ubuntu怎么看上一页,ecs搭 ... [详细]
  • MySQL5.6.40在CentOS764下安装过程 ... [详细]
  • 1、概述首先和大家一起回顾一下Java消息服务,在我之前的博客《Java消息队列-JMS概述》中,我为大家分析了:然后在另一篇博客《Java消息队列-ActiveMq实战》中 ... [详细]
  • 前言对于从事技术的人员来说ajax是这好东西,都会使用,而且乐于使用。但对于新手,开发一个ajax实例,还有是难度的,必竟对于他们这是新东西。leo开发一个简单的ajax实例,用的是 ... [详细]
author-avatar
津pig
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有